Skip to content

Commit

Permalink
Merge branch 'master' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
edelmanjm authored Dec 7, 2018
2 parents 053bd12 + c54d235 commit 5a763ff
Show file tree
Hide file tree
Showing 12 changed files with 580 additions and 137 deletions.
5 changes: 5 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ A system to easily set tuning fields through WPILib `Preferences`.

Various classes for testing common things.
- `BurnoutTester` for testing if motors are burned out.
- `EncoderTester` for testing if motors have working encoders attached.
- `SimpleControllersTester` for easily running motors.
- `ControllersMultiTester` for automatically running multiple tests across motor groups.

#### Triggers

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ subprojects {

repositories {
mavenCentral()
maven {url "https://jitpack.io/"}
}

dependencies {
Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Nov 30 17:46:10 PST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
5 changes: 3 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies {
compile "jaci.pathfinder:Pathfinder-Java:1.8"
compile "openrio.powerup:MatchData:2018.01.07"
compile "com.google.guava:guava:27.0-jre"
// https://mvnrepository.com/artifact/org.apache.commons/commons-math3
compile 'org.apache.commons:commons-math3:3.6.1'
compile "org.apache.commons:commons-math3:3.6.1"
// Last release was in 2014, so we're just pinning it to this commit instead
compile "com.github.oxo42:stateless4j:3dd512049f"
}
42 changes: 27 additions & 15 deletions lib/src/main/java/org/team1540/rooster/testers/AbstractTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public abstract class AbstractTester<T, R> implements Tester<T, R> {
private int updateDelay;
private boolean running = true;
@NotNull
List<T> itemsToTest;
private List<T> itemsToTest;
@NotNull
private Function<T, R> test;
@NotNull
@Nullable
private List<Function<T, Boolean>> runConditions;
@NotNull
private Map<T, ResultStorage<R>> storedResults;
Expand All @@ -38,8 +38,8 @@ public abstract class AbstractTester<T, R> implements Tester<T, R> {
* @param runConditions The conditions that must be met before the test will be executed on an
* item.
*/
AbstractTester(@NotNull Function<T, R> test, @NotNull List<T> itemsToTest,
@NotNull List<Function<T, Boolean>> runConditions) {
protected AbstractTester(@NotNull Function<T, R> test, @NotNull List<T> itemsToTest,
@Nullable List<Function<T, Boolean>> runConditions) {
this(test, itemsToTest, runConditions, (int) DEFAULT_LOG_TIME / (DEFAULT_UPDATE_DELAY / 1000));
}

Expand All @@ -55,8 +55,8 @@ public abstract class AbstractTester<T, R> implements Tester<T, R> {
* checked against while running.
* @param updateDelay The delay between the test being run on the items.
*/
AbstractTester(@NotNull Function<T, R> test, @NotNull List<T> itemsToTest,
@NotNull List<Function<T, Boolean>> runConditions, float logTime, int updateDelay) {
protected AbstractTester(@NotNull Function<T, R> test, @NotNull List<T> itemsToTest,
@Nullable List<Function<T, Boolean>> runConditions, float logTime, int updateDelay) {
this(test, itemsToTest, runConditions,
(int) (logTime / ((float) updateDelay / 1000f)));
this.updateDelay = updateDelay;
Expand All @@ -71,8 +71,9 @@ public abstract class AbstractTester<T, R> implements Tester<T, R> {
* item.
* @param queueDepth The maximum number of items that the {@link EvictingQueue} can hold.
*/
AbstractTester(@NotNull Function<T, R> test, @NotNull List<T> itemsToTest,
@NotNull List<Function<T, Boolean>> runConditions, int queueDepth) {
@SuppressWarnings("WeakerAccess")
protected AbstractTester(@NotNull Function<T, R> test, @NotNull List<T> itemsToTest,
@Nullable List<Function<T, Boolean>> runConditions, int queueDepth) {
this.test = test;
this.itemsToTest = itemsToTest;
this.runConditions = runConditions;
Expand All @@ -95,11 +96,18 @@ public void setTest(@NotNull Function<T, R> test) {
}

@Override
@NotNull
@Nullable
public List<Function<T, Boolean>> getRunConditions() {
return Collections.unmodifiableList(runConditions);
return runConditions;
}

@Override
public void setRunConditions(
@Nullable List<Function<T, Boolean>> runConditions) {
this.runConditions = runConditions;
}


@Override
@NotNull
public List<T> getItemsToTest() {
Expand Down Expand Up @@ -141,14 +149,18 @@ public boolean setRunning(boolean status) {
* The code that should be called every tick. This does the actual testing. Override me as
* necessary (but don't forget to call super!)
*/
void periodic() {
protected void periodic() {
for (T t : itemsToTest) {
// Run through all the run conditions and make sure they all return true
for (Function<T, Boolean> runCondition : runConditions) {
if (!runCondition.apply(t)) {
return;
// If there are run conditions
if (runConditions != null) {
// Run through all the run conditions and make sure they all return true
for (Function<T, Boolean> runCondition : runConditions) {
if (!runCondition.apply(t)) {
return;
}
}
}

this.storedResults.get(t).addResult(this.test.apply(t), System.currentTimeMillis());
}
}
Expand Down
115 changes: 0 additions & 115 deletions lib/src/main/java/org/team1540/rooster/testers/BurnoutTester.java

This file was deleted.

13 changes: 11 additions & 2 deletions lib/src/main/java/org/team1540/rooster/testers/Tester.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,21 @@ public interface Tester<T, R> extends Runnable {
/**
* Gets the conditions that must be met before the test will be executed on an item.
*
* @return An {@link EvictingQueue} of the run conditions.
* @return An potentially {@link List} of the run conditions, or null if there are none (always
* execute.)
*/
@SuppressWarnings("UnstableApiUsage")
@NotNull // TODO how to annotate as unmodifiable?
@Nullable
List<Function<T, Boolean>> getRunConditions();

/**
* Sets the run conditions that must be met before the test will be executed on an item.
*
* @param runConditions A {@link List} of the run conditions, or null if the test should always
* run.
*/
void setRunConditions(@Nullable List<Function<T, Boolean>> runConditions);

/**
* Gets the items that the tests are being applied to.
*
Expand Down
Loading

0 comments on commit 5a763ff

Please sign in to comment.