Skip to content

Commit

Permalink
Merge pull request #13 from LoadingPleaseWait/master
Browse files Browse the repository at this point in the history
Add to README.md, Add to Javadoc comments and annotations, add unit test
  • Loading branch information
AmanuelBayu committed Jan 17, 2016
2 parents 10b9e08 + 68add59 commit 265f2dc
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="var" path="wpilib" sourcepath="wpilib.sources"/>
<classpathentry kind="var" path="networktables" sourcepath="networktables.sources"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ hs_err_pid*
# Output Folders
bin/
build/

junit/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Lib2585
Lib2585 [![Build Status](https://travis-ci.org/Impact2585/Lib2585.svg?branch=master)](https://travis-ci.org/Impact2585/Lib2585)
=======

This FRC library was made from the [code for aerbot](https://github.com/2585Robophiles/aerbot-champs), team 2585's robot for 2014, which has been [unit tested](https://github.com/2585Robophiles/aerbot-junit).
This FRC library is made to supplement WPILibJ and has [documentation available](https://impact2585.github.io/Lib2585).

Downloads can be found on the [releases](https://github.com/2585Robophiles/Lib2585/releases) page.
Downloads can be found on the [releases](https://github.com/2585Robophiles/Lib2585/releases) page. Releases are signed by one of our core developers: @LoadingPleaseWait (Michael Murphey PGP Key ID: A1CFA14B) or @KIllin-A13 (Amanuel Bayu PGP Key ID: B8AD8D5E).

Lib2585 is dual licensed under the [GPL v3](http://www.gnu.org/licenses) and BSD License for WPILib.
Lib2585 is free software: you can redistribute it and/or modify it under the terms of those two licenses.
28 changes: 25 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.8"/>
<property name="source" value="1.8"/>
<path id="FRC2015.classpath">
<path id="Lib2585.classpath">
<pathelement location="bin"/>
<pathelement location="${wpilib}"/>
<pathelement location="${networktables}"/>
<pathelement location="lib/Lib2585.jar"/>
<pathelement location="lib/junit-4.12.jar"/>
<pathelement location="lib/hamcrest-core-1.3.jar"/>
</path>
Expand All @@ -22,6 +21,11 @@
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy includeemptydirs="false" todir="bin">
<fileset dir="test">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
Expand All @@ -33,8 +37,26 @@
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="FRC2015.classpath"/>
<src path="test"/>
<classpath refid="Lib2585.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target name="RunnableExecuterTest">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" haltonfailure="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="org.impact2585.lib2585.tests.RunnableExecuterTest" todir="${junit.output.dir}"/>
<classpath refid="Lib2585.classpath"/>
</junit>
</target>
<target depends="build-project, RunnableExecuterTest" name="test"/>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
</project>
3 changes: 3 additions & 0 deletions src/org/impact2585/lib2585/DoubleSolenoid.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,22 @@ public void setRelayValues(Relay.Value relayOne, Relay.Value relayTwo) {
* (non-Javadoc)
* @see edu.wpi.first.wpilibj.SensorBase#free()
*/
@Override
public void free() {
this.relayOne.free();
this.relayTwo.free();
}

/**
* State of the pneumatic
* @return returns the state of pneumatics (default or not default)
*/
public boolean isDefaultState() {
return defaultState;
}

/**
* Set state
* @param defaultState state of pneumatics
*/
protected void setDefaultState(boolean defaultState) {
Expand Down
8 changes: 8 additions & 0 deletions src/org/impact2585/lib2585/ExecuterBasedRobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public abstract class ExecuterBasedRobot extends IterativeRobot implements Seria
* (non-Javadoc)
* @see edu.wpi.first.wpilibj.IterativeRobot#robotInit()
*/
@Override
public abstract void robotInit();

/*
* (non-Javadoc)
* @see edu.wpi.first.wpilibj.IterativeRobot#autonomousPeriodic()
*/
@Override
public void autonomousPeriodic() {
executer.execute();
}
Expand All @@ -31,6 +33,7 @@ public void autonomousPeriodic() {
* (non-Javadoc)
* @see edu.wpi.first.wpilibj.IterativeRobot#teleopPeriodic()
*/
@Override
public void teleopPeriodic() {
executer.execute();
}
Expand All @@ -39,6 +42,7 @@ public void teleopPeriodic() {
* (non-Javadoc)
* @see edu.wpi.first.wpilibj.IterativeRobot#testPeriodic()
*/
@Override
public void testPeriodic() {
executer.execute();
}
Expand All @@ -47,6 +51,7 @@ public void testPeriodic() {
* (non-Javadoc)
* @see edu.wpi.first.wpilibj.IterativeRobot#disabledInit()
*/
@Override
public void disabledInit() {

}
Expand All @@ -55,18 +60,21 @@ public void disabledInit() {
* (non-Javadoc)
* @see edu.wpi.first.wpilibj.IterativeRobot#disabledPeriodic()
*/
@Override
public void disabledPeriodic() {

}

/**
* Accessor for executer
* @return the executer
*/
protected synchronized Executer getExecuter() {
return executer;
}

/**
* Mutator for executer
* @param executer the executer to set
*/
protected synchronized void setExecuter(Executer executer) {
Expand Down
7 changes: 7 additions & 0 deletions src/org/impact2585/lib2585/MultiMotor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MultiMotor extends SensorBase implements SpeedController, Serializa
private transient SpeedController[] motors;

/**
* Constructor that consumes an array
* @param motors SpeedController array
* @throws IllegalArgumentException if array is empty
*/
Expand All @@ -29,6 +30,7 @@ public MultiMotor(SpeedController[] motors) throws IllegalArgumentException {
*
* @see edu.wpi.first.wpilibj.PIDOutput#pidWrite(double)
*/
@Override
public void pidWrite(double output) {
for (int i = 0; i < motors.length; i++) {
motors[i].pidWrite(output);
Expand All @@ -40,6 +42,7 @@ public void pidWrite(double output) {
*
* @see edu.wpi.first.wpilibj.SpeedController#disable()
*/
@Override
public void disable() {
for (int i = 0; i < motors.length; i++) {
motors[i].disable();
Expand All @@ -51,6 +54,7 @@ public void disable() {
*
* @see edu.wpi.first.wpilibj.SpeedController#get()
*/
@Override
public double get() {
return motors[0].get();
}
Expand All @@ -60,6 +64,7 @@ public double get() {
*
* @see edu.wpi.first.wpilibj.SpeedController#set(double)
*/
@Override
public void set(double speed) {
for (int i = 0; i < motors.length; i++)
motors[i].set(speed);
Expand All @@ -70,6 +75,7 @@ public void set(double speed) {
*
* @see edu.wpi.first.wpilibj.SpeedController#set(double, byte)
*/
@Override
public void set(double speed, byte syncGroup) {
for (int i = 0; i < motors.length; i++)
motors[i].set(speed, syncGroup);
Expand Down Expand Up @@ -98,6 +104,7 @@ public void setInverted(boolean isInverted) {
*
* @see edu.wpi.first.wpilibj.SensorBase#free()
*/
@Override
public void free() {
for (int i = 0; i < motors.length; i++) {
if (motors[i] instanceof SensorBase) {
Expand Down
4 changes: 4 additions & 0 deletions src/org/impact2585/lib2585/RobotEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,31 @@ public RobotEnvironment(RobotBase robot) {
}

/**
* Find out which mode the bot is in
* @return if the robot is in auton mode
*/
public boolean isAutonomous() {
return getRobot().isAutonomous();
}

/**
* See if the robot is in teleop
* @return if robot is in teleop mode
*/
public boolean isOperatorControl() {
return getRobot().isOperatorControl();
}

/**
* Accessor for robot
* @return the robot
*/
protected synchronized RobotBase getRobot() {
return robot;
}

/**
* Mutator for robot
* @param robot the robot to set
*/
protected synchronized void setRobot(RobotBase robot) {
Expand Down
1 change: 1 addition & 0 deletions src/org/impact2585/lib2585/RunnableExecuter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract class RunnableExecuter implements Executer, Serializable {
/* (non-Javadoc)
* @see org.impact2585.lib2585.Executer#execute()
*/
@Override
public void execute() {
//run all the runnables
runnables.parallelStream().forEach(runnable -> runnable.run());
Expand Down
60 changes: 60 additions & 0 deletions test/org/impact2585/lib2585/tests/RunnableExecuterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.impact2585.lib2585.tests;

import java.util.LinkedList;

import org.impact2585.lib2585.RunnableExecuter;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
* Test the RunnableExecuter Class
*/
public class RunnableExecuterTest {

private RunnableExecuter executer;

/**
* Set up before test
*/
@Before
public void setUp() {
executer = new RunnableExecuter() {

private static final long serialVersionUID = 1L;

};
}

/**
* Actually do the unit test
*/
@Test
public void test() {
LinkedList<TestRunnable> testRunnables = new LinkedList<>();
for (int i = 0; i < 3; i++)
testRunnables.add(new TestRunnable());
for (Runnable item : testRunnables)
executer.getRunnables().add(item);
executer.execute();
for (TestRunnable runnable : testRunnables)
Assert.assertTrue(runnable.ran);
}

/**
* Class that implements Runnable for testing
*/
private class TestRunnable implements Runnable{

private boolean ran;

/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
ran = true;
}

}
}

0 comments on commit 265f2dc

Please sign in to comment.