Skip to content
Snippets Groups Projects
Commit 173243b4 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Initial commit.

parents
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.project 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>decomposition_and_conditionals_homework</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
pom.xml 0 → 100644
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.unl.cse.soft160.decomposition_and_conditionals</groupId>
<artifactId>decomposition_and_conditionals</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>decomposition_and_conditionals</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
package edu.unl.cse.soft160.decomposition_and_conditionals;
public class GiveAndTake {
public static void main(String... arguments) {
// [write code here]
}
}
package edu.unl.cse.soft160.decomposition_and_conditionals;
public class Stream {
private static enum State {
OUTSIDE,
INSIDE,
AFTER,
}
public static void main(String... arguments) {
// [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 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", "\\"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment