From 68add5937cd418ba2150239f72116ce277e6ff5b Mon Sep 17 00:00:00 2001 From: LoadingPleaseWait Date: Fri, 15 Jan 2016 23:34:02 -0600 Subject: [PATCH] Add to README.md, Add to Javadoc comments and annotations, add unit test --- .classpath | 2 + .gitignore | 2 + README.md | 6 +- build.xml | 28 ++++++++- .../impact2585/lib2585/DoubleSolenoid.java | 3 + .../lib2585/ExecuterBasedRobot.java | 8 +++ src/org/impact2585/lib2585/MultiMotor.java | 7 +++ .../impact2585/lib2585/RobotEnvironment.java | 4 ++ .../impact2585/lib2585/RunnableExecuter.java | 1 + .../lib2585/tests/RunnableExecuterTest.java | 60 +++++++++++++++++++ 10 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 test/org/impact2585/lib2585/tests/RunnableExecuterTest.java diff --git a/.classpath b/.classpath index 5d0521a..c0245ec 100644 --- a/.classpath +++ b/.classpath @@ -1,8 +1,10 @@ + + diff --git a/.gitignore b/.gitignore index 40ea9a2..ac392ba 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ hs_err_pid* # Output Folders bin/ build/ + +junit/ diff --git a/README.md b/README.md index b01d938..8c8868e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/build.xml b/build.xml index ea408f6..4d975b6 100644 --- a/build.xml +++ b/build.xml @@ -7,11 +7,10 @@ - + - @@ -22,6 +21,11 @@ + + + + + @@ -33,8 +37,26 @@ - + + + + + + + + + + + + + + + + + + + diff --git a/src/org/impact2585/lib2585/DoubleSolenoid.java b/src/org/impact2585/lib2585/DoubleSolenoid.java index 221755f..c79a2b4 100644 --- a/src/org/impact2585/lib2585/DoubleSolenoid.java +++ b/src/org/impact2585/lib2585/DoubleSolenoid.java @@ -62,12 +62,14 @@ 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() { @@ -75,6 +77,7 @@ public boolean isDefaultState() { } /** + * Set state * @param defaultState state of pneumatics */ protected void setDefaultState(boolean defaultState) { diff --git a/src/org/impact2585/lib2585/ExecuterBasedRobot.java b/src/org/impact2585/lib2585/ExecuterBasedRobot.java index 88993e5..85fd073 100644 --- a/src/org/impact2585/lib2585/ExecuterBasedRobot.java +++ b/src/org/impact2585/lib2585/ExecuterBasedRobot.java @@ -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(); } @@ -31,6 +33,7 @@ public void autonomousPeriodic() { * (non-Javadoc) * @see edu.wpi.first.wpilibj.IterativeRobot#teleopPeriodic() */ + @Override public void teleopPeriodic() { executer.execute(); } @@ -39,6 +42,7 @@ public void teleopPeriodic() { * (non-Javadoc) * @see edu.wpi.first.wpilibj.IterativeRobot#testPeriodic() */ + @Override public void testPeriodic() { executer.execute(); } @@ -47,6 +51,7 @@ public void testPeriodic() { * (non-Javadoc) * @see edu.wpi.first.wpilibj.IterativeRobot#disabledInit() */ + @Override public void disabledInit() { } @@ -55,11 +60,13 @@ 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() { @@ -67,6 +74,7 @@ protected synchronized Executer getExecuter() { } /** + * Mutator for executer * @param executer the executer to set */ protected synchronized void setExecuter(Executer executer) { diff --git a/src/org/impact2585/lib2585/MultiMotor.java b/src/org/impact2585/lib2585/MultiMotor.java index 3305174..7d33e01 100644 --- a/src/org/impact2585/lib2585/MultiMotor.java +++ b/src/org/impact2585/lib2585/MultiMotor.java @@ -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 */ @@ -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); @@ -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(); @@ -51,6 +54,7 @@ public void disable() { * * @see edu.wpi.first.wpilibj.SpeedController#get() */ + @Override public double get() { return motors[0].get(); } @@ -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); @@ -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); @@ -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) { diff --git a/src/org/impact2585/lib2585/RobotEnvironment.java b/src/org/impact2585/lib2585/RobotEnvironment.java index 7ba8afc..0faa62a 100644 --- a/src/org/impact2585/lib2585/RobotEnvironment.java +++ b/src/org/impact2585/lib2585/RobotEnvironment.java @@ -29,6 +29,7 @@ public RobotEnvironment(RobotBase robot) { } /** + * Find out which mode the bot is in * @return if the robot is in auton mode */ public boolean isAutonomous() { @@ -36,6 +37,7 @@ public boolean isAutonomous() { } /** + * See if the robot is in teleop * @return if robot is in teleop mode */ public boolean isOperatorControl() { @@ -43,6 +45,7 @@ public boolean isOperatorControl() { } /** + * Accessor for robot * @return the robot */ protected synchronized RobotBase getRobot() { @@ -50,6 +53,7 @@ protected synchronized RobotBase getRobot() { } /** + * Mutator for robot * @param robot the robot to set */ protected synchronized void setRobot(RobotBase robot) { diff --git a/src/org/impact2585/lib2585/RunnableExecuter.java b/src/org/impact2585/lib2585/RunnableExecuter.java index f4fb3ba..b2ee0c9 100644 --- a/src/org/impact2585/lib2585/RunnableExecuter.java +++ b/src/org/impact2585/lib2585/RunnableExecuter.java @@ -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()); diff --git a/test/org/impact2585/lib2585/tests/RunnableExecuterTest.java b/test/org/impact2585/lib2585/tests/RunnableExecuterTest.java new file mode 100644 index 0000000..ef1e9aa --- /dev/null +++ b/test/org/impact2585/lib2585/tests/RunnableExecuterTest.java @@ -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 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; + } + + } +}