import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import java.util.Map; import java.util.HashMap; import java.util.Set; import java.util.HashSet; import java.util.Arrays; import java.util.Collections; public class SimpleTest { private static Turnpike turnpike; @BeforeClass public static void init() { turnpike = new RecursiveTurnpike(); } @Test public void testTwoPoints() { Set points = new HashSet<>(Arrays.asList(0, 3)); Map distances = turnpike.pointsToDistances( Collections.unmodifiableSet(points)); Assert.assertNotNull(distances); Assert.assertEquals(1, distances.size()); Assert.assertEquals(1L, distances.get(3).longValue()); Set npoints = turnpike.distancesToPoints( Collections.unmodifiableMap(distances)); Assert.assertEquals(points, npoints); } @Test public void testEmpty() { Set points = Collections.singleton(0); Map distances = turnpike.pointsToDistances(points); Assert.assertNotNull(distances); Assert.assertTrue(distances.isEmpty()); Set npoints = turnpike.distancesToPoints(distances); Assert.assertEquals(points, npoints); } @Test public void testThreePoints() { Set points = new HashSet<>(Arrays.asList(0, 2, 4)); Map distances = turnpike.pointsToDistances(points); Assert.assertNotNull(distances); Assert.assertEquals(2, distances.size()); Assert.assertEquals(2L, distances.get(2).longValue()); Assert.assertEquals(1L, distances.get(4).longValue()); Set npoints = turnpike.distancesToPoints(distances); Assert.assertEquals(points, npoints); } @Test public void testFourPoints() { Set points = new HashSet<>(Arrays.asList(0, 3, 6, 8)); //Set points = new HashSet<>(Arrays.asList(0, 2, 5, 8)); Map distances = turnpike.pointsToDistances(points); Assert.assertNotNull(distances); Assert.assertEquals(5, distances.size()); Assert.assertEquals(1L, distances.get(2).longValue()); Assert.assertEquals(2L, distances.get(3).longValue()); Assert.assertEquals(1L, distances.get(5).longValue()); Assert.assertEquals(1L, distances.get(6).longValue()); Assert.assertEquals(1L, distances.get(8).longValue()); Map distancesCopy = new HashMap<>(distances); Set npoints = turnpike.distancesToPoints(distancesCopy); Map ndistances = turnpike.pointsToDistances(npoints); Assert.assertEquals(distances, ndistances); } @Test public void testNoSolution() { Map distances = new HashMap<>(); distances.put(5, 2L); distances.put(10, 2L); Assert.assertNull(turnpike.distancesToPoints(distances)); } }