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

added starter code and test cases for Part I

parent 71ceb987
No related branches found
No related tags found
No related merge requests found
package edu.unl.cse.soft160.decomposition_and_conditionals;
public class Game {
private static enum Direction {
UP, DOWN, RIGHT, LEFT,
public class ProcessInput {
private static enum State {
EMPTY, DECIMAL, NUMERIC,
}
private static enum Result {
WIN, NOT_ALLOWED, NEW_POSITION,
private static enum Classification {
FLOAT, INTEGER, NAN,
}
static final int x_win = 7;
static final int y_win = 6;
public static void main(String... arguments) {
// [write code here]
}
......
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"));
}
}
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"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment