private DependencyGraph createDepsWithEqualInstability() { DependencyGraph deps = new DependencyGraph(null, new HashSet(Arrays.asList(FOO, BAR, BAY, XOO, XYZ))); deps.addDependency(FOO, BAR); deps.addDependency(FOO, BAY); deps.addDependency(XOO, FOO); deps.addDependency(XOO, BAR); deps.addDependency(XOO, BAR); deps.addDependency(XYZ, XOO); return deps; }
@Test public void testSortOrder() { DependencyGraph deps = new DependencyGraph(null, new HashSet(Arrays.asList(FOO, BAR, BAY, XOO))); deps.addDependency(FOO, BAR); deps.addDependency(FOO, BAY); deps.addDependency(XOO, FOO); deps.addDependency(XOO, BAR); List<Dependable> items = new ArrayList(Arrays.asList(FOO, BAR, BAY, XOO)); Collections.sort(items, new InstabilityComparator(deps)); assertEquals(XOO, items.get(0)); // ce = 2, ca = 1 assertEquals(FOO, items.get(1)); // ce = 2 ca = 0 assertEquals(BAR, items.get(2)); // ce = 0 ca = 2 assertEquals(BAY, items.get(3)); // ce = 0 ca = 1 }