Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package frc.robot;

import frc.robot.subsystems.ExampleSubsystem;

/**
* The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean
Expand Down
77 changes: 45 additions & 32 deletions src/main/java/frc/robot/subsystems/ExampleSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,51 @@
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants.exampleSubsystem_Constants;

public class ExampleSubsystem extends SubsystemBase{
/** Creates a new ExampleSubsystem. */
private Encoder m_encoder;

public ExampleSubsystem() {
m_encoder = new Encoder(exampleSubsystem_Constants.encoderA,
exampleSubsystem_Constants.encoderB);

}
public ExampleSubsystem(Encoder encoder) {
m_encoder = encoder;
}

@Override
public void periodic() {
// This method will be called once per scheduler run
}

@Override
public void simulationPeriodic() {
// This method will be called once per scheduler run during simulation
}

public String helloWorld(String string){
System.out.println(string);
return string;
}

public double getDistance_Inch() {
System.out.println("Encoder Distance = " + m_encoder.getDistance());
return m_encoder.getDistance();
}
public class ExampleSubsystem extends SubsystemBase implements AutoCloseable {
/** Creates a new ExampleSubsystem. */
private Encoder m_encoder;
public EncoderSim mEncoderSim;

public ExampleSubsystem() {this(false);}

public ExampleSubsystem(boolean simulation) {
m_encoder = new Encoder(exampleSubsystem_Constants.encoderA,
exampleSubsystem_Constants.encoderB);
if (simulation) {
mEncoderSim = new EncoderSim(m_encoder);
} else {

}
}

@Override
public void close() throws Exception {
m_encoder.close();
}

// public ExampleSubsystem(Encoder encoder) {
// m_encoder = encoder;
// }

@Override
public void periodic() {
// This method will be called once per scheduler run
}

@Override
public void simulationPeriodic() {
// This method will be called once per scheduler run during simulation
}

public String helloWorld(String string) {
System.out.println(string);
return string;
}

public double getDistance_Inch() {
System.out.println("Encoder Distance = " + m_encoder.getDistance());
return m_encoder.getDistance();
}


}
14 changes: 6 additions & 8 deletions src/test/java/frc/commands/ExampleCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.simulation.EncoderSim;
import frc.robot.Constants.exampleSubsystem_Constants;
import frc.robot.commands.ExampleCommand;
import frc.robot.subsystems.ExampleSubsystem;

Expand All @@ -20,18 +19,17 @@ public class ExampleCommandTest {

@Before // this method will run before each test
public void setup() {
assert HAL.initialize(500, 0); // initialize the HAL, crash if failed
encoder = new Encoder(exampleSubsystem_Constants.encoderA,
exampleSubsystem_Constants.encoderB);
encoderSim = new EncoderSim(encoder);
subsystem = new ExampleSubsystem(encoder); // create our ExampleSubsystem.
assert HAL.initialize(500, 0); // initialize the HAL, crash if failed

subsystem = new ExampleSubsystem(true); // create our ExampleSubsystem.
encoderSim = subsystem.mEncoderSim;

}

@After // this method will run after each test
public void shutdown() throws Exception {
// exampleSubsystem.close(); // destroy our exampleSubsystem object
encoder.close();
subsystem.close(); // destroy our exampleSubsystem object
}

@Test // Is Initilized
Expand Down
70 changes: 39 additions & 31 deletions src/test/java/frc/subsystems/ExampleSubsystemTest.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
package frc.subsystems;

import static org.junit.Assert.*;

import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.simulation.EncoderSim;
import frc.robot.Constants.exampleSubsystem_Constants;
import frc.robot.subsystems.ExampleSubsystem;
import org.junit.*;

public class ExampleSubsystemTest {
ExampleSubsystem exampleSubsystem;
Encoder encoder;
EncoderSim encoderSim;

@Before // this method will run before each test
public void setup() {
assert HAL.initialize(500, 0); // initialize the HAL, crash if failed
encoder = new Encoder(exampleSubsystem_Constants.encoderA,
exampleSubsystem_Constants.encoderB);
encoderSim = new EncoderSim(encoder);
exampleSubsystem = new ExampleSubsystem(encoder); // create our ExampleSubsystem.
}

@After // this method will run after each test
public void shutdown() throws Exception {
// exampleSubsystem.close(); // destroy our exampleSubsystem object
encoder.close();
}

@Test // marks this method as a test
public void hello_World() {
System.out.print("Hello ");
assertEquals("World", exampleSubsystem.helloWorld("World"));
}

@Test // Checks that Capsensitive fails if not Equal
public void NOT_Hello_World() {
System.out.print("Hello ");
assertNotEquals("World", exampleSubsystem.helloWorld("world"));
}
private double delta = 1e-5;

ExampleSubsystem exampleSubsystem;
Encoder encoder;
EncoderSim encoderSim;

@Before // this method will run before each test
public void setup() {
assert HAL.initialize(500, 0); // initialize the HAL, crash if failed

exampleSubsystem = new ExampleSubsystem(true); // create our ExampleSubsystem.

encoderSim = exampleSubsystem.mEncoderSim;
}

@After // this method will run after each test
public void shutdown() throws Exception {
// exampleSubsystem.close(); // destroy our exampleSubsystem object
exampleSubsystem.close();
}

@Test // marks this method as a test
public void hello_World() {
System.out.print("Hello ");
assertEquals("World", exampleSubsystem.helloWorld("World"));
}

@Test // Checks that Capsensitive fails if not Equal
public void NOT_Hello_World() {
System.out.print("Hello ");
assertNotEquals("World", exampleSubsystem.helloWorld("world"));
}

@Test
public void encoderTest() {
encoderSim.setDistance(5);
assertEquals(5.0, exampleSubsystem.getDistance_Inch(), delta);
}
}