diff --git a/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Stream.java b/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Parity.java similarity index 62% rename from src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Stream.java rename to src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Parity.java index 0d35b1671df753319d9c040f9e61c6106dd741e3..87938ba04662f82e1eb04f731924f526dd4e4069 100644 --- a/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Stream.java +++ b/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Parity.java @@ -1,12 +1,10 @@ package edu.unl.cse.soft160.decomposition_and_conditionals; -public class Stream { - private static enum State { - OUTSIDE, - INSIDE, - AFTER, +public class Parity { + private static enum ParityType { + EVEN, ODD, UNKNOWN, } - + public static void main(String... arguments) { // [write code here] } diff --git a/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/GiveAndTake.java b/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Robot.java similarity index 61% rename from src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/GiveAndTake.java rename to src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Robot.java index 94b6d84d9455e5de94125b3e3153b10e3aea4b73..68fd710489df9a9deab62be5c8c53fd73334d906 100644 --- a/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/GiveAndTake.java +++ b/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Robot.java @@ -1,6 +1,10 @@ package edu.unl.cse.soft160.decomposition_and_conditionals; -public class GiveAndTake { +public class Robot { + private static enum Direction { + NORTH, SOUTH, EAST, WEST, + } + public static void main(String... arguments) { // [write code here] } diff --git a/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/GiveAndTakeTest.java b/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/GiveAndTakeTest.java deleted file mode 100644 index f98e15edd6e76c4c2a11287e2d048e0b7dffd898..0000000000000000000000000000000000000000 --- a/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/GiveAndTakeTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package edu.unl.cse.soft160.decomposition_and_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 GiveAndTakeTest extends TestCase { - public GiveAndTakeTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(GiveAndTakeTest.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)); - GiveAndTake.main(); - System.setIn(in); - System.setOut(out); - return collector.toString(); - } - - public void testOrder0() { - assertEquals(assemble("Enter first card: Enter second card: Enter third card: For the deck [1, 2, 4], choose TAKE."), runMain("1", "2", "4")); - } - - public void testOrder1() { - assertEquals(assemble("Enter first card: Enter second card: Enter third card: For the deck [1, 4, 2], choose GIVE."), runMain("1", "4", "2")); - } - - public void testOrder2() { - assertEquals(assemble("Enter first card: Enter second card: Enter third card: For the deck [2, 1, 4], choose GIVE."), runMain("2", "1", "4")); - } - - public void testOrder3() { - assertEquals(assemble("Enter first card: Enter second card: Enter third card: For the deck [2, 4, 1], choose GIVE."), runMain("2", "4", "1")); - } - - public void testOrder4() { - assertEquals(assemble("Enter first card: Enter second card: Enter third card: For the deck [4, 1, 2], choose TAKE."), runMain("4", "1", "2")); - } - - public void testOrder5() { - assertEquals(assemble("Enter first card: Enter second card: Enter third card: For the deck [4, 2, 1], choose TAKE."), runMain("4", "2", "1")); - } -} diff --git a/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/ParityTest.java b/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/ParityTest.java new file mode 100644 index 0000000000000000000000000000000000000000..59cf0f76accdd8b4716919884776df7bdb6a5ee0 --- /dev/null +++ b/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/ParityTest.java @@ -0,0 +1,85 @@ +package edu.unl.cse.soft160.decomposition_and_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 ParityTest extends TestCase { + public ParityTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(ParityTest.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)); + Parity.main(); + System.setIn(in); + System.setOut(out); + return collector.toString(); + } + + public void testEvenEven() { + assertEquals(assemble( + "Enter parity of multiplier: Enter parity of multiplicand: The parity of the product of an EVEN number and an EVEN number is EVEN."), + runMain("EVEN", "EVEN")); + } + + public void testEvenOdd() { + assertEquals(assemble( + "Enter parity of multiplier: Enter parity of multiplicand: The parity of the product of an EVEN number and an ODD number is EVEN."), + runMain("EVEN", "ODD")); + } + + public void testOddEven() { + assertEquals(assemble( + "Enter parity of multiplier: Enter parity of multiplicand: The parity of the product of an ODD number and an EVEN number is EVEN."), + runMain("ODD", "EVEN")); + } + + public void testOddUnknown() { + assertEquals(assemble( + "Enter parity of multiplier: Enter parity of multiplicand: The parity of the product of an ODD number and an UNKNOWN number is UNKNOWN."), + runMain("ODD", "UNKNOWN")); + } + + public void testUnknownOdd() { + assertEquals(assemble( + "Enter parity of multiplier: Enter parity of multiplicand: The parity of the product of an UNKNOWN number and an ODD number is UNKNOWN."), + runMain("UNKNOWN", "ODD")); + } + + public void testUnknownUnknown() { + assertEquals(assemble( + "Enter parity of multiplier: Enter parity of multiplicand: The parity of the product of an UNKNOWN number and an UNKNOWN number is UNKNOWN."), + runMain("UNKNOWN", "UNKNOWN")); + } + + public void testEvenUnknown() { + assertEquals(assemble( + "Enter parity of multiplier: Enter parity of multiplicand: The parity of the product of an EVEN number and an UNKNOWN number is EVEN."), + runMain("EVEN", "UNKNOWN")); + } + + public void testUnknownEven() { + assertEquals(assemble( + "Enter parity of multiplier: Enter parity of multiplicand: The parity of the product of an EVEN number and an UNKNOWN number is EVEN."), + runMain("EVEN", "UNKNOWN")); + } + +} diff --git a/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/RobotTest.java b/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/RobotTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6e36c4ff3814fc3b350af95d01c2e5cde5b3ff40 --- /dev/null +++ b/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/RobotTest.java @@ -0,0 +1,109 @@ +package edu.unl.cse.soft160.decomposition_and_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 RobotTest extends TestCase { + public RobotTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(RobotTest.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)); + Robot.main(); + System.setIn(in); + System.setOut(out); + return collector.toString(); + } + + public void testEastLeft() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: NORTH"), + runMain("East", "l")); + } + + public void testEastRight() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: SOUTH"), + runMain("East", "r")); + } + + public void testEastBack() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: WEST"), + runMain("East", "b")); + } + + public void testWestLeft() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: SOUTH"), + runMain("West", "l")); + } + + public void testWestRight() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: NORTH"), + runMain("West", "r")); + } + + public void testWestBack() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: EAST"), + runMain("West", "b")); + } + + public void testNorthLeft() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: WEST"), + runMain("North", "l")); + } + + public void testNorthRight() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: EAST"), + runMain("North", "r")); + } + + public void testNorthBack() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: SOUTH"), + runMain("North", "b")); + } + + public void testSpouthLeft() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: EAST"), + runMain("South", "l")); + } + + public void testSouthRight() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: WEST"), + runMain("South", "r")); + } + + public void testSouthBack() { + assertEquals( + assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: NORTH"), + runMain("South", "b")); + } + +} diff --git a/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/StreamTest.java b/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/StreamTest.java deleted file mode 100644 index a6ea1a0983a0dca420f94c6f6dfc1bf31a88a045..0000000000000000000000000000000000000000 --- a/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/StreamTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package edu.unl.cse.soft160.decomposition_and_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 StreamTest extends TestCase { - public StreamTest(String testName) { - super(testName); - } - - public static Test suite() { - return new TestSuite(StreamTest.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)); - Stream.main(); - System.setIn(in); - System.setOut(out); - return collector.toString(); - } - - public void testLetterOutside() { - assertEquals( - assemble("Enter the current state of the stream: Enter the next character: New state: OUTSIDE"), - runMain("OUTSIDE", "x")); - } - - public void testQuoteOutside() { - assertEquals( - assemble("Enter the current state of the stream: Enter the next character: New state: INSIDE"), - runMain("OUTSIDE", "\"")); - } - - public void testBackslashOutside() { - assertEquals( - assemble("Enter the current state of the stream: Enter the next character: New state: OUTSIDE"), - runMain("OUTSIDE", "\\")); - } - - public void testLetterInside() { - assertEquals( - assemble("Enter the current state of the stream: Enter the next character: New state: INSIDE"), - runMain("INSIDE", "y")); - } - - public void testQuoteInside() { - assertEquals( - assemble("Enter the current state of the stream: Enter the next character: New state: OUTSIDE"), - runMain("INSIDE", "\"")); - } - - public void testBackslashInside() { - assertEquals(assemble("Enter the current state of the stream: Enter the next character: New state: AFTER"), - runMain("INSIDE", "\\")); - } - - public void testLetterAfterBackslash() { - assertEquals( - assemble("Enter the current state of the stream: Enter the next character: New state: INSIDE"), - runMain("AFTER", "z")); - } - - public void testQuoteAfterBackslash() { - assertEquals( - assemble("Enter the current state of the stream: Enter the next character: New state: INSIDE"), - runMain("AFTER", "\"")); - } - - public void testBackslashAfterBackslash() { - assertEquals( - assemble("Enter the current state of the stream: Enter the next character: New state: INSIDE"), - runMain("AFTER", "\\")); - } -}