Skip to content
Snippets Groups Projects
Commit 14c7031d authored by Suzette J Person's avatar Suzette J Person
Browse files

updated with new classes for 2018

parent 173243b4
No related branches found
No related tags found
No related merge requests found
package edu.unl.cse.soft160.decomposition_and_conditionals; package edu.unl.cse.soft160.decomposition_and_conditionals;
public class Stream { public class Parity {
private static enum State { private static enum ParityType {
OUTSIDE, EVEN, ODD, UNKNOWN,
INSIDE,
AFTER,
} }
public static void main(String... arguments) { public static void main(String... arguments) {
......
package edu.unl.cse.soft160.decomposition_and_conditionals; 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) { public static void main(String... arguments) {
// [write code here] // [write code here]
} }
......
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"));
}
}
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"));
}
}
...@@ -9,13 +9,13 @@ import java.io.ByteArrayInputStream; ...@@ -9,13 +9,13 @@ import java.io.ByteArrayInputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
public class StreamTest extends TestCase { public class RobotTest extends TestCase {
public StreamTest(String testName) { public RobotTest(String testName) {
super(testName); super(testName);
} }
public static Test suite() { public static Test suite() {
return new TestSuite(StreamTest.class); return new TestSuite(RobotTest.class);
} }
protected static String assemble(String... lines) { protected static String assemble(String... lines) {
...@@ -28,62 +28,82 @@ public class StreamTest extends TestCase { ...@@ -28,62 +28,82 @@ public class StreamTest extends TestCase {
System.setIn(new ByteArrayInputStream(assemble(inputs).getBytes())); System.setIn(new ByteArrayInputStream(assemble(inputs).getBytes()));
ByteArrayOutputStream collector = new ByteArrayOutputStream(); ByteArrayOutputStream collector = new ByteArrayOutputStream();
System.setOut(new PrintStream(collector)); System.setOut(new PrintStream(collector));
Stream.main(); Robot.main();
System.setIn(in); System.setIn(in);
System.setOut(out); System.setOut(out);
return collector.toString(); return collector.toString();
} }
public void testLetterOutside() { public void testEastLeft() {
assertEquals( assertEquals(
assemble("Enter the current state of the stream: Enter the next character: New state: OUTSIDE"), assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: NORTH"),
runMain("OUTSIDE", "x")); runMain("East", "l"));
} }
public void testQuoteOutside() { public void testEastRight() {
assertEquals( assertEquals(
assemble("Enter the current state of the stream: Enter the next character: New state: INSIDE"), assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: SOUTH"),
runMain("OUTSIDE", "\"")); runMain("East", "r"));
} }
public void testBackslashOutside() { public void testEastBack() {
assertEquals( assertEquals(
assemble("Enter the current state of the stream: Enter the next character: New state: OUTSIDE"), assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: WEST"),
runMain("OUTSIDE", "\\")); runMain("East", "b"));
} }
public void testLetterInside() { public void testWestLeft() {
assertEquals( assertEquals(
assemble("Enter the current state of the stream: Enter the next character: New state: INSIDE"), assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: SOUTH"),
runMain("INSIDE", "y")); runMain("West", "l"));
} }
public void testQuoteInside() { public void testWestRight() {
assertEquals( assertEquals(
assemble("Enter the current state of the stream: Enter the next character: New state: OUTSIDE"), assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: NORTH"),
runMain("INSIDE", "\"")); runMain("West", "r"));
} }
public void testBackslashInside() { public void testWestBack() {
assertEquals(assemble("Enter the current state of the stream: Enter the next character: New state: AFTER"), assertEquals(
runMain("INSIDE", "\\")); 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 testLetterAfterBackslash() { public void testNorthRight() {
assertEquals( assertEquals(
assemble("Enter the current state of the stream: Enter the next character: New state: INSIDE"), assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: EAST"),
runMain("AFTER", "z")); runMain("North", "r"));
} }
public void testQuoteAfterBackslash() { public void testNorthBack() {
assertEquals( assertEquals(
assemble("Enter the current state of the stream: Enter the next character: New state: INSIDE"), assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: SOUTH"),
runMain("AFTER", "\"")); runMain("North", "b"));
} }
public void testBackslashAfterBackslash() { public void testSpouthLeft() {
assertEquals( assertEquals(
assemble("Enter the current state of the stream: Enter the next character: New state: INSIDE"), assemble("Enter the direction of the robot prior to moving: Enter the rotation: New direction: EAST"),
runMain("AFTER", "\\")); 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"));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment