diff --git a/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Game.java b/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Game.java deleted file mode 100755 index b6c5df8ebebb4f56127c643ef25e799d2aae81ff..0000000000000000000000000000000000000000 --- a/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/Game.java +++ /dev/null @@ -1,18 +0,0 @@ -package edu.unl.cse.soft160.decomposition_and_conditionals; - -public class Game { - private static enum Direction { - UP, DOWN, RIGHT, LEFT, - } - - private static enum Result { - WIN, NOT_ALLOWED, NEW_POSITION, - } - - static final int x_win = 7; - static final int y_win = 6; - - public static void main(String... arguments) { - // [write code here] - } -} diff --git a/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/ProcessInput.java b/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/ProcessInput.java new file mode 100755 index 0000000000000000000000000000000000000000..68c5444d072c1bdbde97946c94ba6fefa8a8bd69 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft160/decomposition_and_conditionals/ProcessInput.java @@ -0,0 +1,15 @@ +package edu.unl.cse.soft160.decomposition_and_conditionals; + +public class ProcessInput { + private static enum State { + EMPTY, DECIMAL, NUMERIC, + } + + private static enum Classification { + FLOAT, INTEGER, NAN, + } + + public static void main(String... arguments) { + // [write code here] + } +} diff --git a/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/GameTest.java b/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/GameTest.java deleted file mode 100644 index 96d1ea3c1ac84f9d7cbdf3d29d582a77cca0e4bc..0000000000000000000000000000000000000000 --- a/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/GameTest.java +++ /dev/null @@ -1,125 +0,0 @@ -package edu.unl.cse.soft160.decomposition_and_conditionals; - -import static org.junit.Assert.*; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.PrintStream; - -import org.junit.Test; - -public class GameTest { - - 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)); - Game.main(); - System.setIn(in); - System.setOut(out); - return collector.toString(); - } - - @Test - public void testUpNotallowed() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: NOT_ALLOWED"), - runMain("6", "7", "Up", "7")); - } - - @Test - public void testUpWin() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: WIN"), - runMain("7", "3", "Up", "3")); - } - - @Test - public void testUpNewPosition() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: NEW_POSITION"), - runMain("6", "1", "Up", "7")); - } - - @Test - public void testDownNotallowed() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: NOT_ALLOWED"), - runMain("6", "3", "Down", "7")); - } - - @Test - public void testDownWin() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: WIN"), - runMain("7", "8", "Down", "2")); - } - - @Test - public void testDownNewPosition() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: NEW_POSITION"), - runMain("6", "7", "Down", "4")); - } - - @Test - public void testLeftNotallowed() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: NOT_ALLOWED"), - runMain("6", "7", "Left", "9")); - } - - @Test - public void testLeftWin() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: WIN"), - runMain("9", "6", "Left", "2")); - } - - @Test - public void testLeftNewPosition() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: NEW_POSITION"), - runMain("6", "7", "Left", "3")); - } - - @Test - public void testRightNotallowed() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: NOT_ALLOWED"), - runMain("6", "7", "Right", "7")); - } - - @Test - public void testRightWin() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: WIN"), - runMain("6", "6", "Right", "1")); - } - - @Test - public void testRightNewPosition() { - assertEquals( - assemble("Enter the initial x position: Enter the initial y position: Enter the direction of the move: " - + "Enter the number of the steps to move: Move result: NEW_POSITION"), - runMain("2", "7", "Right", "1")); - } -} diff --git a/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/ProcessInputTest.java b/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/ProcessInputTest.java new file mode 100644 index 0000000000000000000000000000000000000000..443be183205bc414fa912917d54c0b19cc183697 --- /dev/null +++ b/src/test/java/edu/unl/cse/soft160/decomposition_and_conditionals/ProcessInputTest.java @@ -0,0 +1,365 @@ +package edu.unl.cse.soft160.decomposition_and_conditionals; + +import static org.junit.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; + +import org.junit.Test; + +public class ProcessInputTest { + + 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)); + ProcessInput.main(); + System.setIn(in); + System.setOut(out); + return collector.toString(); + } + + @Test + public void testEmptyL() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: NAN"), + runMain("empty","L")); + } + + @Test + public void testEmpty0() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("empty","0")); + } + + @Test + public void testEmpty1() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("empty","1")); + } + + @Test + public void testEmpty2() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("empty","2")); + } + + @Test + public void testEmpty3() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("empty","3")); + } + + @Test + public void testEmpty4() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("empty","4")); + } + + @Test + public void testEmpty5() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("empty","5")); + } + + @Test + public void testEmpty6() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("empty","6")); + } + + @Test + public void testEmpty7() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("empty","7")); + } + + @Test + public void testEmpty8() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("empty","8")); + } + + @Test + public void testEmpty9() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("empty","9")); + } + + @Test + public void testEmptyPeriod() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("empty",".")); + } + + @Test + public void testEmptyF() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: NAN"), + runMain("empty","f")); + } + + @Test + public void testEmptyD() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: NAN"), + runMain("empty","d")); + } + + @Test + public void testDecimalL() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: NAN"), + runMain("decimal","L")); + } + + @Test + public void testDecimal0() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","0")); + } + + @Test + public void testDecimal1() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","1")); + } + + @Test + public void testDecimal2() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","2")); + } + + @Test + public void testDecimal3() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","3")); + } + + @Test + public void testDecimal4() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","4")); + } + + @Test + public void testDecimal5() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","5")); + } + + @Test + public void testDecimal6() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","6")); + } + + @Test + public void testDecimal7() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","7")); + } + + @Test + public void testDecimal8() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","8")); + } + + @Test + public void testDecimal9() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","9")); + } + + @Test + public void testDecimalPeriod() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: NAN"), + runMain("decimal",".")); + } + + @Test + public void testDecimalF() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","f")); + } + + @Test + public void testDecimalD() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("decimal","d")); + } + + @Test + public void testNumericL() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","L")); + } + + @Test + public void testNumeric0() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","0")); + } + + @Test + public void testNumeric1() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","1")); + } + + @Test + public void testNumeric2() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","2")); + } + + @Test + public void testNumeric3() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","3")); + } + + @Test + public void testNumeric4() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","4")); + } + + @Test + public void testNumeric5() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","5")); + } + + @Test + public void testNumeric6() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","6")); + } + + @Test + public void testNumeric7() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","7")); + } + + @Test + public void testNumeric8() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","8")); + } + + @Test + public void testNumeric9() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: INTEGER"), + runMain("numeric","9")); + } + + @Test + public void testNumericPeriod() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("numeric",".")); + } + + @Test + public void testNumericF() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("numeric","f")); + } + + @Test + public void testNumericD() { + assertEquals( + assemble("Enter the current state: Enter the next character: " + + "Classification: FLOAT"), + runMain("numeric","d")); + } +}