Cleanup (test migrated; typos; formatting)

This commit is contained in:
Roman Shevchenko
2016-09-23 14:23:14 +03:00
parent c7c96475ec
commit e31bbb06fb
6 changed files with 51 additions and 59 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,26 +15,23 @@
*/
package com.intellij.util.graph;
import com.intellij.util.containers.ContainerUtil;
import java.util.*;
/**
* @author dsl
* @author dsl
*/
public class CachingSemiGraph<Node> implements GraphGenerator.SemiGraph<Node> {
private final Set<Node> myNodes;
private final Map<Node, Set<Node>> myIn;
public CachingSemiGraph(GraphGenerator.SemiGraph<Node> original) {
myNodes = ContainerUtil.newLinkedHashSet(original.getNodes());
myIn = new LinkedHashMap<Node, Set<Node>>();
myNodes = new LinkedHashSet<Node>();
for (final Node node1 : original.getNodes()) {
myNodes.add(node1);
}
for (final Node node : myNodes) {
final Set<Node> value = new LinkedHashSet<Node>();
for (Iterator<Node> itin = original.getIn(node); itin.hasNext();) {
value.add(itin.next());
}
for (Node node : myNodes) {
Set<Node> value = new LinkedHashSet<Node>();
ContainerUtil.addAll(value, original.getIn(node));
myIn.put(node, value);
}
}
@@ -52,4 +49,4 @@ public class CachingSemiGraph<Node> implements GraphGenerator.SemiGraph<Node> {
public Iterator<Node> getIn(Node n) {
return myIn.get(n).iterator();
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ import java.util.Collection;
import java.util.Iterator;
/**
* @author dsl
* @author dsl
*/
public interface Graph<Node> {
Collection<Node> getNodes();
@@ -27,4 +27,4 @@ public interface Graph<Node> {
Iterator<Node> getIn(Node n);
Iterator<Node> getOut(Node n);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,16 +18,16 @@ package com.intellij.util.graph;
import java.util.*;
/**
* @author dsl
* @author dsl
*/
public class GraphGenerator<Node> implements Graph <Node>{
private final SemiGraph<Node> myGraph;
public class GraphGenerator<Node> implements Graph<Node> {
public interface SemiGraph<Node> {
Collection<Node> getNodes();
Iterator<Node> getIn(Node n);
}
private final SemiGraph<Node> myGraph;
private final Map<Node, Set<Node>> myOuts;
public GraphGenerator(SemiGraph<Node> graph) {
@@ -73,5 +73,4 @@ public class GraphGenerator<Node> implements Graph <Node>{
public Iterator<Node> getOut(Node n) {
return myOuts.get(n).iterator();
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,24 +16,23 @@
package com.intellij.util.graph;
import com.intellij.util.containers.EmptyIterator;
import junit.framework.TestCase;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.*;
import static org.junit.Assert.assertFalse;
/**
* @author dsl
* @author dsl
*/
public class GraphGeneratorTest extends TestCase {
public class GraphGeneratorTest {
@Test
public void testEmptyGraph() {
final TestNode node = new TestNode("A");
final GraphGenerator<TestNode> graphGenerator = new GraphGenerator<>(new GraphGenerator.SemiGraph<TestNode>() {
TestNode node = new TestNode("A");
GraphGenerator<TestNode> graphGenerator = new GraphGenerator<>(new GraphGenerator.SemiGraph<TestNode>() {
@Override
public Collection<TestNode> getNodes() {
return Arrays.asList(new TestNode[]{node});
return Collections.singletonList(node);
}
@Override
@@ -45,16 +44,15 @@ public class GraphGeneratorTest extends TestCase {
assertFalse(graphGenerator.getOut(node).hasNext());
}
@Test
public void testLoop() {
final TestNode nodeA = new TestNode("A");
final TestNode nodeB = new TestNode("B");
final TestNode[] nodes = new TestNode[]{nodeA, nodeB};
final TestNode[] inA = new TestNode[]{nodeB};
final TestNode[] inB = new TestNode[] {nodeA};
final TestNode[] outA = inA;
final TestNode[] outB = inB;
TestNode nodeA = new TestNode("A");
TestNode nodeB = new TestNode("B");
TestNode[] nodes = {nodeA, nodeB};
TestNode[] inA = {nodeB};
TestNode[] inB = {nodeA};
final GraphGenerator<TestNode> graph = new GraphGenerator<>(new GraphGenerator.SemiGraph<TestNode>() {
GraphGenerator<TestNode> graph = new GraphGenerator<>(new GraphGenerator.SemiGraph<TestNode>() {
@Override
public Collection<TestNode> getNodes() {
return Arrays.asList(nodes);
@@ -67,9 +65,7 @@ public class GraphGeneratorTest extends TestCase {
throw new NoSuchElementException();
}
});
GraphTestUtil.assertIteratorsEqual(Arrays.asList(outA).iterator(), graph.getOut(nodeA));
GraphTestUtil.assertIteratorsEqual(Arrays.asList(outB).iterator(), graph.getOut(nodeB));
GraphTestUtil.assertIteratorsEqual(Arrays.asList(inA).iterator(), graph.getOut(nodeA));
GraphTestUtil.assertIteratorsEqual(Arrays.asList(inB).iterator(), graph.getOut(nodeB));
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,24 +15,24 @@
*/
package com.intellij.util.graph;
import junit.framework.Assert;
import java.util.Arrays;
import java.util.Iterator;
import static org.junit.Assert.*;
/**
* @author dsl
* @author dsl
*/
public class GraphTestUtil {
static <E> void assertIteratorsEqual(Iterator<E> expected, Iterator<E> found) {
for (; expected.hasNext(); ) {
Assert.assertTrue(found.hasNext());
Assert.assertEquals(expected.next(), found.next());
while (expected.hasNext()) {
assertTrue(found.hasNext());
assertEquals(expected.next(), found.next());
}
Assert.assertFalse(found.hasNext());
assertFalse(found.hasNext());
}
public static Iterator<TestNode> iteratorOfArray(TestNode[] array) {
return Arrays.asList(array).iterator();
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
package com.intellij.util.graph;
/**
* @author dsl
* @author dsl
*/
class TestNode {
private final String myMark;
@@ -32,4 +32,4 @@ class TestNode {
public String toString() {
return myMark;
}
}
}