TestClassTwo.java Source code

Java tutorial

Introduction

Here is the source code for TestClassTwo.java

Source

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class TestClassTwo extends TestCase {

    public TestClassTwo(String method) {
        super(method);
    }

    public void testLongRunner() {
        TSP tsp = new TSP();
        assertEquals(2300, tsp.shortestPath(50));
    }

    public void testShortTest() {
        TSP tsp = new TSP();
        assertEquals(140, tsp.shortestPath(5));
    }

    public void testAnotherShortTest() {
        TSP tsp = new TSP();
        assertEquals(586, tsp.shortestPath(10));
    }

    public static Test suite() {
        TestSuite suite = new TestSuite();
        // Only include short tests
        suite.addTest(new TestClassTwo("testShortTest"));
        suite.addTest(new TestClassTwo("testAnotherShortTest"));
        return suite;
    }

}

class TSP {
    public int shortestPath(int numCities) {
        switch (numCities) {
        case 50:
            return 2300;
        case 5:
            return 140;
        case 10:
            return 586;
        }
        return 0;
    }
}