diff --git a/src/main/java/edu/unl/cse/soft160/conditionals/Scramble.java b/src/main/java/edu/unl/cse/soft160/conditionals/Scramble.java new file mode 100644 index 0000000000000000000000000000000000000000..f0c448959c34db30f412e9e1250fe21d8c4c73bc --- /dev/null +++ b/src/main/java/edu/unl/cse/soft160/conditionals/Scramble.java @@ -0,0 +1,9 @@ +package edu.unl.cse.soft160.conditionals; + +import java.util.Scanner; + +public class Scramble { + public static void main(String... arguments) { + // [write code here] + } +} diff --git a/src/test/java/edu/unl/cse/soft160/conditionals/SatelliteTest.java b/src/test/java/edu/unl/cse/soft160/conditionals/SatelliteTest.java index 08071a6a8ea50009a4c8bd725f7933af01128efb..85db4db193403801216cf7628cc6dfbbda3ed62c 100644 --- a/src/test/java/edu/unl/cse/soft160/conditionals/SatelliteTest.java +++ b/src/test/java/edu/unl/cse/soft160/conditionals/SatelliteTest.java @@ -34,49 +34,49 @@ public class SatelliteTest extends TestCase { return collector.toString(); } - public void testCaseZero() { + public void testAcquireWithNoRotation() { assertEquals(assemble("Is the satellite in tracking mode rather than acquire mode (yes/no)? " + "Does the IRU report rotation (yes/no)? " + "Does the STT report rotation (yes/no)? " - + "Continue tracking"), runMain("no", "no", "no")); + + "Continue"), runMain("no", "no", "no")); } - public void testCaseOne() { + public void testAcquireWithSTTRotation() { assertEquals(assemble("Is the satellite in tracking mode rather than acquire mode (yes/no)? " + "Does the IRU report rotation (yes/no)? " + "Does the STT report rotation (yes/no)? " - + "Continue tracking"), runMain("no", "no", "yes")); + + "Continue"), runMain("no", "no", "yes")); } - public void testCaseTwo() { + public void testAcquireWithIRURotation() { assertEquals(assemble("Is the satellite in tracking mode rather than acquire mode (yes/no)? " + "Does the IRU report rotation (yes/no)? " + "Does the STT report rotation (yes/no)? " - + "Continue tracking"), runMain("no", "yes", "no")); + + "Continue"), runMain("no", "yes", "no")); } - public void testCaseThree() { + public void testAcquireWithRotation() { assertEquals(assemble("Is the satellite in tracking mode rather than acquire mode (yes/no)? " + "Does the IRU report rotation (yes/no)? " + "Does the STT report rotation (yes/no)? " - + "Continue tracking"), runMain("no", "yes", "yes")); + + "Continue"), runMain("no", "yes", "yes")); } - public void testCaseFour() { + public void testTrackWithNoRotation() { assertEquals(assemble("Is the satellite in tracking mode rather than acquire mode (yes/no)? " + "Does the IRU report rotation (yes/no)? " + "Does the STT report rotation (yes/no)? " - + "Continue tracking"), runMain("yes", "no", "no")); + + "Continue"), runMain("yes", "no", "no")); } - public void testCaseFive() { + public void testTrackWithSTTRotation() { assertEquals(assemble("Is the satellite in tracking mode rather than acquire mode (yes/no)? " + "Does the IRU report rotation (yes/no)? " + "Does the STT report rotation (yes/no)? " + "Counteract rotation"), runMain("yes", "no", "yes")); } - public void testCaseSix() { + public void testTrackWithIRURotation() { assertEquals(assemble("Is the satellite in tracking mode rather than acquire mode (yes/no)? " + "Does the IRU report rotation (yes/no)? " + "Does the STT report rotation (yes/no)? " + "Counteract rotation"), runMain("yes", "yes", "no")); } - public void testCaseSeven() { + public void testTrackWithRotation() { assertEquals(assemble("Is the satellite in tracking mode rather than acquire mode (yes/no)? " + "Does the IRU report rotation (yes/no)? " + "Does the STT report rotation (yes/no)? " + "Counteract rotation"), runMain("yes", "yes", "yes")); diff --git a/src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java b/src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..55a899263de14e5f88b31d3b7f93ce91de367920 --- /dev/null +++ b/src/test/java/edu/unl/cse/soft160/conditionals/ScrambleTest.java @@ -0,0 +1,102 @@ +package edu.unl.cse.soft160.conditionals; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import java.io.InputStream; +import java.io.ByteArrayInputStream; +import java.io.PrintStream; +import java.io.ByteArrayOutputStream; + +public class ScrambleTest extends TestCase { + public ScrambleTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(ScrambleTest.class); + } + + protected static String assemble(String... lines) { + return String.join("\n", lines) + "\n"; + } + + protected static String runMain(String... inputs) { + InputStream in = System.in; + PrintStream out = System.out; + System.setIn(new ByteArrayInputStream(assemble(inputs).getBytes())); + ByteArrayOutputStream collector = new ByteArrayOutputStream(); + System.setOut(new PrintStream(collector)); + Scramble.main(); + System.setIn(in); + System.setOut(out); + return collector.toString(); + } + + public void testOrder0() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is 2."), + runMain("0", "1", "2")); + } + + public void testOrder1() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is 2."), + runMain("0", "2", "1")); + } + + public void testOrder2() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is 2."), + runMain("2", "0", "1")); + } + + public void testOrder3() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is 2."), + runMain("2", "1", "0")); + } + + public void testOrder4() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is 2."), + runMain("1", "2", "0")); + } + + public void testOrder5() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is 2."), + runMain("1", "0", "2")); + } + + public void testOrder6WithATie() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is 1."), + runMain("0", "1", "1")); + } + + public void testOrder7WithATie() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is 1."), + runMain("1", "0", "1")); + } + + public void testOrder8WithATie() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is 1."), + runMain("1", "1", "0")); + } + + public void testAllTied() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is 0."), + runMain("0", "0", "0")); + } + + public void testNegatives() { + assertEquals( + assemble("Enter first value: " + "Enter second value: " + "Enter third value: " + "The maximum is -1."), + runMain("-1", "-2", "-3")); + } +} diff --git a/src/test/java/edu/unl/cse/soft160/conditionals/TrainTest.java b/src/test/java/edu/unl/cse/soft160/conditionals/TrainTest.java index bcb228f0d2a9af8954d0d9e4a26e96f714b64b73..e43416b4124dc9eb1d2717425d73792d2d08b023 100644 --- a/src/test/java/edu/unl/cse/soft160/conditionals/TrainTest.java +++ b/src/test/java/edu/unl/cse/soft160/conditionals/TrainTest.java @@ -34,97 +34,121 @@ public class TrainTest extends TestCase { return collector.toString(); } - public void testCaseZero() { + public void testStoppedTrainWithNoRestrictions() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Safe"), runMain("0.0", "no", "no")); } - public void testCaseOne() { + public void testStoppedTrainWithClosedTrackProtection() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Safe"), runMain("0.0", "no", "yes")); } - public void testCaseTwo() { + public void testStoppedTrainWithSpeedReduction() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Safe"), runMain("0.0", "yes", "no")); } - public void testCaseThree() { + public void testStoppedTrainWithBothRestrictions() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Safe"), runMain("0.0", "yes", "yes")); } - public void testCaseFour() { + public void testSlowTrainWithNoRestrictions() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Safe"), runMain("18.0", "no", "no")); } - public void testCaseFive() { + public void testSlowTrainWithClosedTrackProtection() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Unsafe"), runMain("18.0", "no", "yes")); } - public void testCaseSix() { + public void testSlowTrainWithSpeedReduction() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Safe"), runMain("18.0", "yes", "no")); } - public void testCaseSeven() { + public void testSlowTrainWithBothRestrictions() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Unsafe"), runMain("18.0", "yes", "yes")); } - public void testCaseEight() { + public void testAlmostSlowTrainWithNoRestrictions() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Safe"), runMain("18.1", "no", "no")); } - public void testCaseNine() { + public void testAlmostSlowTrainWithClosedTrackProtection() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Unsafe"), runMain("18.1", "no", "yes")); } - public void testCaseTen() { + public void testAlmostSlowTrainWithSpeedReduction() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Unsafe"), runMain("18.1", "yes", "no")); } - public void testCaseEleven() { + public void testAlmostSlowTrainWithBothRestrictions() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Unsafe"), runMain("18.1", "yes", "yes")); } - public void testCaseTwelve() { + public void testAlmostFastTrainWithNoRestrictions() { + assertEquals(assemble("What is the train's speed (in km/h)? " + + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + + "Safe"), runMain("56.0", "no", "no")); + } + + public void testAlmostFastTrainWithClosedTrackProtection() { + assertEquals(assemble("What is the train's speed (in km/h)? " + + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + + "Unsafe"), runMain("56.0", "no", "yes")); + } + + public void testAlmostFastTrainWithSpeedReduction() { + assertEquals(assemble("What is the train's speed (in km/h)? " + + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + + "Unsafe"), runMain("56.0", "yes", "no")); + } + + public void testAlmostFastTrainWithBothRestrictions() { + assertEquals(assemble("What is the train's speed (in km/h)? " + + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + + "Unsafe"), runMain("56.0", "yes", "yes")); + } + + public void testFastTrainWithNoRestrictions() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Unsafe"), runMain("56.1", "no", "no")); } - public void testCaseThirteen() { + public void testFastTrainWithClosedTrackProtection() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Unsafe"), runMain("56.1", "no", "yes")); } - public void testCaseFourteen() { + public void testFastTrainWithSpeedReduction() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Unsafe"), runMain("56.1", "yes", "no")); } - public void testCaseFifteen() { + public void testFastTrainWithBothRestrictions() { assertEquals(assemble("What is the train's speed (in km/h)? " + "Is there a temporary speed reduction (yes/no)? " + "Is closed-track protection active (yes/no)? " + "Unsafe"), runMain("56.1", "yes", "yes"));