/** Check if the getSubBuilders properly predicts the output. */ public static void testSubBuilders() throws Exception { Workspace ws = Workspace.getWorkspace(new File("test/ws")); Project project = ws.getProject("p4-sub"); Collection<? extends Builder> bs = project.getSubBuilders(); assertNotNull(bs); assertEquals(3, bs.size()); Set<String> names = new HashSet<String>(); for (Builder b : bs) { names.add(b.getBsn()); } assertTrue(names.contains("p4-sub.a")); assertTrue(names.contains("p4-sub.b")); assertTrue(names.contains("p4-sub.c")); File[] files = project.build(); assertTrue(project.check()); System.err.println(Processor.join(project.getErrors(), "\n")); System.err.println(Processor.join(project.getWarnings(), "\n")); assertEquals(0, project.getErrors().size()); assertEquals(0, project.getWarnings().size()); assertNotNull(files); assertEquals(3, files.length); for (File file : files) { Jar jar = new Jar(file); Manifest m = jar.getManifest(); assertTrue(names.contains(m.getMainAttributes().getValue("Bundle-SymbolicName"))); } }
public void testMethodKey() throws Exception { MethodKey factory = (MethodKey) KeyFactory.create(MethodKey.class); Set methodSet = new HashSet(); methodSet.add(factory.newInstance(Number.class, new Class[] {int.class})); assertTrue(methodSet.contains(factory.newInstance(Number.class, new Class[] {int.class}))); assertTrue(!methodSet.contains(factory.newInstance(Number.class, new Class[] {Integer.class}))); }
/** Tests Subgraph. */ public void testSubgraph() { UndirectedGraph<String, DefaultEdge> g = init(false); UndirectedSubgraph<String, DefaultEdge> sub = new UndirectedSubgraph<String, DefaultEdge>(g, null, null); assertEquals(g.vertexSet(), sub.vertexSet()); assertEquals(g.edgeSet(), sub.edgeSet()); Set<String> vset = new HashSet<String>(g.vertexSet()); g.removeVertex(v1); assertEquals(vset, sub.vertexSet()); // losing track g = init(false); vset = new HashSet<String>(); vset.add(v1); sub = new UndirectedSubgraph<String, DefaultEdge>(g, vset, null); assertEquals(vset, sub.vertexSet()); assertEquals(0, sub.degreeOf(v1)); assertEquals(Collections.EMPTY_SET, sub.edgeSet()); vset.add(v2); vset.add(v3); sub = new UndirectedSubgraph<String, DefaultEdge>( g, vset, new HashSet<DefaultEdge>(g.getAllEdges(v1, v2))); assertEquals(vset, sub.vertexSet()); assertEquals(1, sub.edgeSet().size()); }
/** descendingkeySet.toArray returns contains all keys */ public void testDescendingDescendingKeySetToArray() { ConcurrentNavigableMap map = dmap5(); Set s = map.descendingKeySet(); Object[] ar = s.toArray(); assertEquals(5, ar.length); assertTrue(s.containsAll(Arrays.asList(ar))); ar[0] = m10; assertFalse(s.containsAll(Arrays.asList(ar))); }
/** keySet returns a Set containing all the keys */ public void testDescendingKeySet() { ConcurrentNavigableMap map = dmap5(); Set s = map.keySet(); assertEquals(5, s.size()); assertTrue(s.contains(m1)); assertTrue(s.contains(m2)); assertTrue(s.contains(m3)); assertTrue(s.contains(m4)); assertTrue(s.contains(m5)); }
/** keySet returns a Set containing all the keys */ public void testKeySet() { ConcurrentNavigableMap map = map5(); Set s = map.keySet(); assertEquals(5, s.size()); assertTrue(s.contains(one)); assertTrue(s.contains(two)); assertTrue(s.contains(three)); assertTrue(s.contains(four)); assertTrue(s.contains(five)); }
/** keySet is ordered */ public void testDescendingKeySetOrder() { ConcurrentNavigableMap map = dmap5(); Set s = map.keySet(); Iterator i = s.iterator(); Integer last = (Integer) i.next(); assertEquals(last, m1); while (i.hasNext()) { Integer k = (Integer) i.next(); assertTrue(last.compareTo(k) > 0); last = k; } }
/** . */ public void testStronglyConnected3() { DirectedGraph<String, DefaultEdge> g = new DefaultDirectedGraph<String, DefaultEdge>(DefaultEdge.class); g.addVertex(V1); g.addVertex(V2); g.addVertex(V3); g.addVertex(V4); g.addEdge(V1, V2); g.addEdge(V2, V3); g.addEdge(V3, V1); // strongly connected g.addEdge(V1, V4); g.addEdge(V2, V4); g.addEdge(V3, V4); // weakly connected StrongConnectivityInspector<String, DefaultEdge> inspector = new StrongConnectivityInspector<String, DefaultEdge>(g); // convert from List to Set because we need to ignore order // during comparison Set<Set<String>> actualSets = new HashSet<Set<String>>(inspector.stronglyConnectedSets()); // construct the expected answer Set<Set<String>> expectedSets = new HashSet<Set<String>>(); Set<String> set = new HashSet<String>(); set.add(V1); set.add(V2); set.add(V3); expectedSets.add(set); set = new HashSet<String>(); set.add(V4); expectedSets.add(set); assertEquals(expectedSets, actualSets); actualSets.clear(); List<DirectedSubgraph<String, DefaultEdge>> subgraphs = inspector.stronglyConnectedSubgraphs(); for (DirectedSubgraph<String, DefaultEdge> sg : subgraphs) { actualSets.add(sg.vertexSet()); StrongConnectivityInspector<String, DefaultEdge> ci = new StrongConnectivityInspector<String, DefaultEdge>(sg); assertTrue(ci.isStronglyConnected()); } assertEquals(expectedSets, actualSets); }
/** . */ public void testSubgraphListener() { UndirectedGraph<String, DefaultEdge> g = init(true); UndirectedSubgraph<String, DefaultEdge> sub = new UndirectedSubgraph<String, DefaultEdge>(g, null, null); assertEquals(g.vertexSet(), sub.vertexSet()); assertEquals(g.edgeSet(), sub.edgeSet()); Set<String> vset = new HashSet<String>(g.vertexSet()); g.removeVertex(v1); vset.remove(v1); assertEquals(vset, sub.vertexSet()); // not losing track assertEquals(g.edgeSet(), sub.edgeSet()); }
/** entrySet contains all pairs */ public void testDescendingEntrySet() { ConcurrentNavigableMap map = dmap5(); Set s = map.entrySet(); assertEquals(5, s.size()); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); assertTrue( (e.getKey().equals(m1) && e.getValue().equals("A")) || (e.getKey().equals(m2) && e.getValue().equals("B")) || (e.getKey().equals(m3) && e.getValue().equals("C")) || (e.getKey().equals(m4) && e.getValue().equals("D")) || (e.getKey().equals(m5) && e.getValue().equals("E"))); } }
/** entrySet contains all pairs */ public void testEntrySet() { ConcurrentNavigableMap map = map5(); Set s = map.entrySet(); assertEquals(5, s.size()); Iterator it = s.iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); assertTrue( (e.getKey().equals(one) && e.getValue().equals("A")) || (e.getKey().equals(two) && e.getValue().equals("B")) || (e.getKey().equals(three) && e.getValue().equals("C")) || (e.getKey().equals(four) && e.getValue().equals("D")) || (e.getKey().equals(five) && e.getValue().equals("E"))); } }