Skip to content

Instantly share code, notes, and snippets.

@jdavis
Last active December 28, 2015 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdavis/7539406 to your computer and use it in GitHub Desktop.
Save jdavis/7539406 to your computer and use it in GitHub Desktop.

CS311 Homework 6 Tests

Downloading

To use these tests, just use Git and clone them into the directory you have your project.

You can do this using:

git clone https://gist.github.com/7539406.git tests

Running the Tests

If you compile things from the command line and have ant installed: http://ant.apache.org/, you only have to modify a few lines to make it work.

  1. First, modify the property below with the name src.dir. It should point to the directory that your package lives in.

  2. Open up TestRunner.java file and edit the return line of the method newInstance. The class that is instantiated should point to your implementation of IGraph.

  3. Now you should just be able to run ant test on the command line.

Additional Things

This ant build.xml file contains a few targets:

  1. ant init
  2. ant build
  3. ant build-test
  4. ant test
  5. ant clean

More than likely you'll only have to run clean and test.

Contributing

Feel free to Fork this Gist and make changes. Let me know when/if you do and I'll add them to the existing tests.

<project name="311Homework6" default="build" basedir=".">
<!--
Edit this value.
Replace "../src/" with the directory of your Java package.
It should be the same directory that edu/iastate/cs311/f13/hw6 lives.
-->
<property name="src.dir" value="../src/"/>
<!-- -->
<!-- -->
<!--
No additional changes should be required below this.
-->
<!-- -->
<!-- -->
<property name="test.dir" value="."/>
<property name="dest.dir" value="./dest"/>
<presetdef name="javac">
<javac includeantruntime="false"/>
</presetdef>
<path id="classpath.base">
</path>
<path id="classpath.test">
<pathelement location="junit.jar"/>
<pathelement location="hamcrest-core.jar"/>
<pathelement location="${test.dir}"/>
<pathelement location="${dest.dir}"/>
<path refid="classpath.base"/>
</path>
<target name="init">
<mkdir dir="${dest.dir}"/>
</target>
<target name="clean">
<delete dir="${dest.dir}"/>
</target>
<target name="build" depends="init">
<javac srcdir="${src.dir}" destdir="${dest.dir}"/>
</target>
<target name="build-test" depends="init">
<javac srcdir="${test.dir}" destdir="${dest.dir}">
<include name="TestRunner.java" />
<classpath refid="classpath.test"/>
</javac>
</target>
<target name="test" depends="build,build-test">
<junit dir="${dest.dir}" printsummary="yes" haltonfailure="no">
<classpath refid="classpath.test"/>
<formatter type="plain" usefile="false"/>
<test name="TestRunner"/>
</junit>
</target>
</project>
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
import org.junit.Test;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import edu.iastate.cs311.f13.hw6.IGraph;
/**
* Test IGraph implementation class.
*/
public class TestGraph {
/**
* Test that creating a new instance of the IGraph implementation doens't
* give us an exception.
*
* If it does, check the TestRunner.java file to make sure your IGraph
* implementation class is being imported and set correctly.
*/
@Test
public void testCreateEmptyGraph() {
TestRunner.newGraph();
}
@Test
public void testEmptyGraph() {
IGraph g = TestRunner.newGraph();
Collection<String> expected = Arrays.asList();
Collection<String> actual = g.getVertices();
assertThat("Check the graph has no vertices", actual, equalTo(expected));
}
@Test
public void testAddOneVertex() {
IGraph g = TestRunner.newGraph();
String v = "A";
g.addVertex(v);
Collection<String> expected = Arrays.asList(v);
Collection<String> actual = g.getVertices();
assertThat("Check the added vertex was added", actual, equalTo(expected));
}
@Test
public void testAddMultipleVertices() {
IGraph g = TestRunner.newGraph();
ArrayList<String> vertices = new ArrayList<String>();
for (char c = 'A'; c < 'A' + 10; c += 1) {
String s = "" + c;
vertices.add(s);
g.addVertex(s);
}
Collection<String> expected = (Collection<String>) vertices;
Collection<String> actual = g.getVertices();
assertThat("Check for added vertices", actual, equalTo(expected));
}
@Test
public void testEmptyEdgesForSingleVertex() {
IGraph g = TestRunner.newGraph();
String v = "A";
g.addVertex(v);
Collection<String> expected = Arrays.asList();
Collection<String> actual = g.getOutgoingEdges(v);
assertThat("Check a single vertex has no outgoing edges", actual, equalTo(expected));
}
}
import org.junit.Test;
/**
* Test max flow algorithms.
*/
public class TestMaxFlow {
@Test
public final void emptyTest() {
}
}
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import edu.iastate.cs311.f13.hw6.*;
@RunWith(Suite.class)
@Suite.SuiteClasses({
TestGraph.class,
TestMaxFlow.class,
TestTopologicalSort.class,
})
/**
* Almost empty class for the suites.
*/
public final class TestRunner {
/**
* Create a new instance of the above class automatically.
* @return An instance that adheres to the IGraph interface
*
* Replace `Graph` class with the name of your implementation of the IGraph
* interface.
*
*/
public static IGraph newGraph() {
return new Graph();
}
}
import org.junit.Test;
/**
* Test topological algorithms.
*/
public class TestTopologicalSort {
@Test
public final void simpleTopologicalSort() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment