Skip to content
Snippets Groups Projects
Commit e5093cc3 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Updated to JUnit 4; incidentally reformatted code

parent 9e89f30b
No related branches found
No related tags found
No related merge requests found
...@@ -7,3 +7,23 @@ release.properties ...@@ -7,3 +7,23 @@ release.properties
dependency-reduced-pom.xml dependency-reduced-pom.xml
buildNumber.properties buildNumber.properties
.mvn/timing.properties .mvn/timing.properties
# Mac file finder metadata
.DS_Store
# MS Office temporary file
~*
# Emacs backup file
*~
# JetBrains (IntelliJ IDEA, PyCharm, etc) files
.idea/
out/
*.iml
*.iws
*.ipr
# Eclipse files
bin/
.settings/
.classpath
.project
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>3.8.1</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
......
package edu.unl.cse.csce361.sort_three_pairs; package edu.unl.cse.csce361.sort_three_pairs;
import junit.framework.Test; import org.junit.After;
import junit.framework.TestCase; import org.junit.Before;
import junit.framework.TestSuite; import org.junit.Test;
import static org.junit.Assert.*;
import java.io.InputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.security.Permission; import java.security.Permission;
import java.io.ByteArrayOutputStream;
public class SortThreePairsTest extends TestCase { public class SortThreePairsTest {
public SortThreePairsTest(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(SortThreePairsTest.class);
}
protected static String assemble(String... lines) { protected static String assemble(String... lines) {
return String.join("\n", lines) + "\n"; return String.join("\n", lines) + "\n";
...@@ -61,16 +56,14 @@ public class SortThreePairsTest extends TestCase { ...@@ -61,16 +56,14 @@ public class SortThreePairsTest extends TestCase {
} }
} }
@Override @Before
protected void setUp() throws Exception { public void setUp() {
super.setUp();
System.setSecurityManager(new TestingSecurityManager()); System.setSecurityManager(new TestingSecurityManager());
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() {
System.setSecurityManager(null); System.setSecurityManager(null);
super.tearDown();
} }
protected static String runMainForError(int expectedStatus, String... arguments) { protected static String runMainForError(int expectedStatus, String... arguments) {
...@@ -93,66 +86,79 @@ public class SortThreePairsTest extends TestCase { ...@@ -93,66 +86,79 @@ public class SortThreePairsTest extends TestCase {
return collector.toString(); return collector.toString();
} }
@Test
public void testZeros() { public void testZeros() {
assertEquals(assemble("(0.0, 0.0)", "(0.0, 0.0)", "(0.0, 0.0)"), assertEquals(assemble("(0.0, 0.0)", "(0.0, 0.0)", "(0.0, 0.0)"),
runMain("0", "0", "0", "0", "0", "0")); runMain("0", "0", "0", "0", "0", "0"));
} }
@Test
public void testAlreadySorted() { public void testAlreadySorted() {
assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"), assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"),
runMain("0", "0", "1", "1", "2", "2")); runMain("0", "0", "1", "1", "2", "2"));
} }
@Test
public void testReversed() { public void testReversed() {
assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"), assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"),
runMain("2", "2", "1", "1", "0", "0")); runMain("2", "2", "1", "1", "0", "0"));
} }
@Test
public void testJumbled() { public void testJumbled() {
assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"), assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"),
runMain("1", "1", "2", "2", "0", "0")); runMain("1", "1", "2", "2", "0", "0"));
} }
@Test
public void testTieBreaking() { public void testTieBreaking() {
assertEquals(assemble("(0.0, 1.0)", "(1.0, 2.0)", "(1.0, 3.0)"), assertEquals(assemble("(0.0, 1.0)", "(1.0, 2.0)", "(1.0, 3.0)"),
runMain("1", "3", "0", "1", "1", "2")); runMain("1", "3", "0", "1", "1", "2"));
} }
@Test
public void testMultipleTieBreaking() { public void testMultipleTieBreaking() {
assertEquals(assemble("(0.0, 0.0)", "(0.0, 1.0)", "(0.0, 3.0)"), assertEquals(assemble("(0.0, 0.0)", "(0.0, 1.0)", "(0.0, 3.0)"),
runMain("0", "1", "0", "0", "0", "3")); runMain("0", "1", "0", "0", "0", "3"));
} }
@Test
public void testDuplicates() { public void testDuplicates() {
assertEquals(assemble("(1.0, 1.0)", "(1.0, 1.0)", "(1.0, 2.0)"), assertEquals(assemble("(1.0, 1.0)", "(1.0, 1.0)", "(1.0, 2.0)"),
runMain("1", "1", "1", "2", "1", "1")); runMain("1", "1", "1", "2", "1", "1"));
} }
@Test
public void testPermutation1() { public void testPermutation1() {
assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"), assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"),
runMain("0", "0", "2", "2", "1", "1")); runMain("0", "0", "2", "2", "1", "1"));
} }
@Test
public void testPermutation2() { public void testPermutation2() {
assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"), assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"),
runMain("2", "2", "0", "0", "1", "1")); runMain("2", "2", "0", "0", "1", "1"));
} }
@Test
public void testPermutation3() { public void testPermutation3() {
assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"), assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"),
runMain("2", "2", "1", "1", "0", "0")); runMain("2", "2", "1", "1", "0", "0"));
} }
@Test
public void testPermutation16() { public void testPermutation16() {
assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"), assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"),
runMain("1", "1", "2", "2", "0", "0")); runMain("1", "1", "2", "2", "0", "0"));
} }
@Test
public void testPermutation20() { public void testPermutation20() {
assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"), assertEquals(assemble("(0.0, 0.0)", "(1.0, 1.0)", "(2.0, 2.0)"),
runMain("1", "1", "0", "0", "2", "2")); runMain("1", "1", "0", "0", "2", "2"));
} }
@Test
public void testTooFewArguments() { public void testTooFewArguments() {
assertEquals( assertEquals(
assemble("Sorts three points by their x coordinates, breaking ties using y coordinates.", assemble("Sorts three points by their x coordinates, breaking ties using y coordinates.",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment