mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add C++ Counter Test
Added a PCM java test and a Counter C++ test Add RelayTest for C++, fixed spelling error in Relay.cpp Change-Id: I436ac34449d00e8dcd1b988758cc24e80534a2c7
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2014. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.concurrent.Delayed;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
|
||||
/**
|
||||
* @author Kacper Puczydlowski
|
||||
*
|
||||
*/
|
||||
|
||||
public class PCMTest extends AbstractComsSetup {
|
||||
private static final Logger logger = Logger.getLogger(PCMTest.class.getName());
|
||||
/* The PCM switches the compressor up to 2 seconds after the pressure switch
|
||||
changes. */
|
||||
protected static final double kCompressorDelayTime = 2.0;
|
||||
|
||||
/* Solenoids should change much more quickly */
|
||||
protected static final double kSolenoidDelayTime = 0.1;
|
||||
|
||||
/* The voltage divider on the test bench should bring the compressor output
|
||||
to around these values. */
|
||||
protected static final double kCompressorOnVoltage = 5.00;
|
||||
protected static final double kCompressorOffVoltage = 1.68;
|
||||
|
||||
private static Compressor compressor;
|
||||
|
||||
private static DigitalOutput fakePressureSwitch;
|
||||
private static AnalogInput fakeCompressor;
|
||||
|
||||
private static Solenoid solenoid1, solenoid2;
|
||||
private static DigitalInput fakeSolenoid1, fakeSolenoid2;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
compressor = new Compressor();
|
||||
|
||||
fakePressureSwitch = new DigitalOutput(11);
|
||||
fakeCompressor = new AnalogInput(1);
|
||||
|
||||
solenoid1 = new Solenoid(1);
|
||||
solenoid2 = new Solenoid(2);
|
||||
|
||||
fakeSolenoid1 = new DigitalInput(12);
|
||||
fakeSolenoid2 = new DigitalInput(13);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
compressor.free();
|
||||
|
||||
fakePressureSwitch.free();
|
||||
fakeCompressor.free();
|
||||
|
||||
solenoid1.free();
|
||||
solenoid2.free();
|
||||
|
||||
fakeSolenoid1.free();
|
||||
fakeSolenoid2.free();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void reset() throws Exception {
|
||||
compressor.stop();
|
||||
fakePressureSwitch.set(false);
|
||||
solenoid1.set(false);
|
||||
solenoid2.set(false);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the compressor turns on and off when the pressure switch is toggled
|
||||
*/
|
||||
@Test
|
||||
public void testPressureSwitch() throws Exception {
|
||||
double range = 0.1;
|
||||
reset();
|
||||
compressor.setClosedLoopControl(true);
|
||||
|
||||
// Turn on the compressor
|
||||
fakePressureSwitch.set(true);
|
||||
Timer.delay(kCompressorDelayTime);
|
||||
assertEquals("Compressor did not turn on when the pressure switch turned on.",
|
||||
kCompressorOnVoltage, fakeCompressor.getVoltage(), range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the correct solenoids turn on and off when they should
|
||||
*/
|
||||
@Test
|
||||
public void testSolenoid() throws Exception {
|
||||
reset();
|
||||
|
||||
solenoid1.set(false);
|
||||
solenoid2.set(false);
|
||||
|
||||
Timer.delay(kSolenoidDelayTime);
|
||||
|
||||
assertTrue("Solenoid did not turn off.",solenoid1.get());
|
||||
assertTrue("Solenoid did not turn off.",solenoid2.get());
|
||||
|
||||
// Turn Solenoid #1 on, and turn Solenoid #2 off
|
||||
solenoid1.set(true);
|
||||
solenoid2.set(false);
|
||||
Timer.delay(kSolenoidDelayTime);
|
||||
assertFalse("Solenoid #1 did not turn on",fakeSolenoid1.get());
|
||||
assertTrue("Solenoid #2 did not turn off",fakeSolenoid2.get());
|
||||
|
||||
// Turn Solenoid #1 off, and turn Solenoid #2 on
|
||||
solenoid1.set(false);
|
||||
solenoid2.set(true);
|
||||
Timer.delay(kSolenoidDelayTime);
|
||||
assertTrue("Solenoid #1 did not turn off",fakeSolenoid1.get());
|
||||
assertFalse("Solenoid #2 did not turn on",fakeSolenoid2.get());
|
||||
|
||||
// Turn both Solenoids on
|
||||
solenoid1.set(true);
|
||||
solenoid2.set(true);
|
||||
Timer.delay(kSolenoidDelayTime);
|
||||
assertFalse("Solenoid #1 did not turn on",fakeSolenoid1.get());
|
||||
assertFalse("Solenoid #2 did not turn on",fakeSolenoid2.get());
|
||||
}
|
||||
|
||||
protected Logger getClassLogger(){
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
EncoderTest.class,
|
||||
MotorEncoderTest.class,
|
||||
PIDTest.class,
|
||||
PCMTest.class,
|
||||
PrefrencesTest.class,
|
||||
RelayCrossConnectTest.class,
|
||||
SampleTest.class,
|
||||
|
||||
@@ -21,6 +21,7 @@ import edu.wpi.first.wpilibj.CounterTest;
|
||||
import edu.wpi.first.wpilibj.DIOCrossConnectTest;
|
||||
import edu.wpi.first.wpilibj.EncoderTest;
|
||||
import edu.wpi.first.wpilibj.MotorEncoderTest;
|
||||
import edu.wpi.first.wpilibj.PCMTest;
|
||||
import edu.wpi.first.wpilibj.PIDTest;
|
||||
import edu.wpi.first.wpilibj.PrefrencesTest;
|
||||
import edu.wpi.first.wpilibj.RelayCrossConnectTest;
|
||||
@@ -46,7 +47,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SmartDashboardTestSuite;
|
||||
* suite classes annotation.
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({
|
||||
@SuiteClasses({
|
||||
WpiLibJTestSuite.class,
|
||||
CommandTestSuite.class,
|
||||
SmartDashboardTestSuite.class
|
||||
@@ -67,7 +68,7 @@ public class TestSuite {
|
||||
Logger.getAnonymousLogger().severe("Could not load default logging.properties file");
|
||||
Logger.getAnonymousLogger().severe(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
System.out.println("Starting Tests");
|
||||
}
|
||||
private static final Logger WPILIBJ_ROOT_LOGGER = Logger.getLogger("edu.wpi.first.wpilibj");
|
||||
|
||||
Reference in New Issue
Block a user