diff --git a/cassovary-core/src/main/scala/com/twitter/cassovary/graph/TestGraph.scala b/cassovary-core/src/main/scala/com/twitter/cassovary/graph/TestGraph.scala index 7417ddf0..2987d83d 100644 --- a/cassovary-core/src/main/scala/com/twitter/cassovary/graph/TestGraph.scala +++ b/cassovary-core/src/main/scala/com/twitter/cassovary/graph/TestGraph.scala @@ -15,9 +15,10 @@ package com.twitter.cassovary.graph import com.twitter.cassovary.graph.StoredGraphDir._ import com.twitter.cassovary.util.{Sampling, BinomialDistribution} +import java.util.concurrent.ConcurrentLinkedQueue import scala.collection.mutable +import scala.collection.JavaConverters._ import scala.util.Random -import scala.collection.mutable.ArrayBuffer /** * A simple implementation of a DirectedGraph @@ -155,8 +156,8 @@ object TestGraphs { */ def generateRandomUndirectedGraph(numNodes: Int, probEdge: Double, graphDir: StoredGraphDir = StoredGraphDir.BothInOut) = { - val nodes = Array.fill[mutable.Buffer[Int]](numNodes){new ArrayBuffer[Int]() with mutable.SynchronizedBuffer[Int]} - def addMutualEdge(i: Int)(j: Int) {nodes(i) += j; nodes(j) += i} + val nodes = Array.fill(numNodes){new ConcurrentLinkedQueue[Int]()} + def addMutualEdge(i: Int)(j: Int) {nodes(i).add(j); nodes(j).add(i)} val rand = new Random val binomialDistribution = new BinomialDistribution(numNodes - 1, probEdge) // Sampling edges only from nodes with lower id to higher id. In order to @@ -176,7 +177,7 @@ object TestGraphs { higherNodeNeighbors map (higherNode + _ + 1) foreach addMutualEdge(higherNode) } val nodesEdges = nodes.indices map { i => - NodeIdEdgesMaxId(i, nodes(i).toArray) + NodeIdEdgesMaxId(i, nodes(i).asScala.toArray) } ArrayBasedDirectedGraph( () => nodesEdges.iterator, graphDir) } diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/algorithms/PageRankSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/algorithms/PageRankSpec.scala index 6b0303b0..9af9d4f0 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/algorithms/PageRankSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/algorithms/PageRankSpec.scala @@ -14,10 +14,10 @@ package com.twitter.cassovary.algorithms import com.twitter.cassovary.graph.TestGraphs -import org.scalatest.matchers._ -import org.scalatest.WordSpec +import org.scalatest.{Matchers, WordSpec} +import org.scalatest.matchers.{Matcher, MatchResult} -class PageRankSpec extends WordSpec with ShouldMatchers { +class PageRankSpec extends WordSpec with Matchers { val EPSILON = 1e-6 diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/algorithms/TriangleCountSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/algorithms/TriangleCountSpec.scala index a7554342..1632fbc5 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/algorithms/TriangleCountSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/algorithms/TriangleCountSpec.scala @@ -14,10 +14,9 @@ package com.twitter.cassovary.algorithms import com.twitter.cassovary.graph.TestGraphs -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} -class TriangleCountSpec extends WordSpec with ShouldMatchers { +class TriangleCountSpec extends WordSpec with Matchers { def averageOfPairs(f: => (Double, Double), repetitions: Int): (Double, Double) = { val sums = (0 until repetitions).map(_ => f).reduce((p1, p2) => (p1._1 + p2._1, p1._2 + p2._2)) @@ -47,9 +46,9 @@ class TriangleCountSpec extends WordSpec with ShouldMatchers { val graph = TestGraphs.generateRandomUndirectedGraph(numberOfNodes, 2.0 / numberOfNodes) val pars = TriangleCountParameters(200, 200) val (transitivity, triangles) = TriangleCount(graph, pars) - transitivity should be(0.0 plusOrMinus 0.05) + transitivity should be(0.0 +- 0.05) - triangles should be(0.0 plusOrMinus 20.0) + triangles should be(0.0 +- 20.0) } @@ -59,13 +58,13 @@ class TriangleCountSpec extends WordSpec with ShouldMatchers { val erGraph = TestGraphs.generateRandomUndirectedGraph(numberOfNodes, edgeProbability) val pars = TriangleCountParameters(500, 500) val (transitivity, triangles) = averageOfPairs(TriangleCount(erGraph, pars), 10) - transitivity should be(edgeProbability plusOrMinus 0.15 * edgeProbability) + transitivity should be(edgeProbability +- (0.15 * edgeProbability)) def averageTrianglesInERGraph(nodes: Int, p: Double) = { p * p * p * nodes * (nodes - 1) * (nodes - 2) / 6 } val expectedTriangles = averageTrianglesInERGraph(numberOfNodes, edgeProbability) - triangles should be(expectedTriangles plusOrMinus (0.3 * expectedTriangles)) + triangles should be (expectedTriangles +- (0.3 * expectedTriangles)) } "Return correct results for complete graph" in { @@ -73,14 +72,14 @@ class TriangleCountSpec extends WordSpec with ShouldMatchers { val graph = TestGraphs.generateCompleteGraph(nodes) val pars = TriangleCountParameters(1000, 1000) val (transitivity, triangles) = averageOfPairs(TriangleCount(graph, pars), 5) - transitivity should be(1.0 plusOrMinus 0.1) + transitivity should be(1.0 +- 0.1) def trianglesInCompleteGraph(nodes: Int): Double = { (nodes * (nodes - 1) * (nodes - 2)) / 6 } val expectedTriangles = trianglesInCompleteGraph(nodes) - triangles should be(expectedTriangles plusOrMinus (0.25 * expectedTriangles)) + triangles should be(expectedTriangles +- (0.25 * expectedTriangles)) } } } diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedGraphSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedGraphSpec.scala index 971d634a..0ec5dedd 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedGraphSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedGraphSpec.scala @@ -14,12 +14,11 @@ package com.twitter.cassovary.graph import org.junit.runner.RunWith -import org.scalatest.WordSpec +import org.scalatest.{Matchers, WordSpec} import org.scalatest.junit.JUnitRunner -import org.scalatest.matchers.ShouldMatchers @RunWith(classOf[JUnitRunner]) -class DirectedGraphSpec extends WordSpec with ShouldMatchers { +class DirectedGraphSpec extends WordSpec with Matchers { val twoNodeGraph = TestGraphs.g2_mutual val sixNodeGraph = TestGraphs.g6 diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedGraphUtilsSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedGraphUtilsSpec.scala index 4115c125..983d0e4a 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedGraphUtilsSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedGraphUtilsSpec.scala @@ -14,12 +14,11 @@ package com.twitter.cassovary.graph import org.junit.runner.RunWith -import org.scalatest.WordSpec +import org.scalatest.{Matchers, WordSpec} import org.scalatest.junit.JUnitRunner -import org.scalatest.matchers.ShouldMatchers @RunWith(classOf[JUnitRunner]) -class DirectedGraphUtilsSpec extends WordSpec with ShouldMatchers { +class DirectedGraphUtilsSpec extends WordSpec with Matchers { private def utils(graph: DirectedGraph) = { (graph, new DirectedGraphUtils(graph)) diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedPathCollectionSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedPathCollectionSpec.scala index 7ce55b22..044132ca 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedPathCollectionSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedPathCollectionSpec.scala @@ -16,12 +16,11 @@ package com.twitter.cassovary.graph import com.twitter.cassovary.util.FastUtilUtils import it.unimi.dsi.fastutil.objects.Object2IntMap import org.junit.runner.RunWith -import org.scalatest.WordSpec +import org.scalatest.{Matchers, WordSpec} import org.scalatest.junit.JUnitRunner -import org.scalatest.matchers.ShouldMatchers @RunWith(classOf[JUnitRunner]) -class DirectedPathCollectionSpec extends WordSpec with ShouldMatchers { +class DirectedPathCollectionSpec extends WordSpec with Matchers { "DirectedPathCollection" when { diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedPathSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedPathSpec.scala index c5ed22c9..671b47e9 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedPathSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/DirectedPathSpec.scala @@ -13,10 +13,9 @@ */ package com.twitter.cassovary.graph -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} -class DirectedPathSpec extends WordSpec with ShouldMatchers { +class DirectedPathSpec extends WordSpec with Matchers { "path of many nodes" should { "length, append, exists, equals" in { diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/GraphBehaviours.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/GraphBehaviours.scala index 5929961c..d1d86b85 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/GraphBehaviours.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/GraphBehaviours.scala @@ -14,10 +14,9 @@ package com.twitter.cassovary.graph import com.twitter.cassovary.graph.StoredGraphDir._ import com.twitter.cassovary.util.NodeNumberer -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} -trait GraphBehaviours extends ShouldMatchers { +trait GraphBehaviours extends Matchers { this: WordSpec => private def correctNumberOfNodesAndEdges(graph: DirectedGraph, numNodes: Int) { diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/GraphUtilsSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/GraphUtilsSpec.scala index bf095109..1de5c5a1 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/GraphUtilsSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/GraphUtilsSpec.scala @@ -19,11 +19,10 @@ import com.twitter.util.Duration import com.twitter.util.Stopwatch import it.unimi.dsi.fastutil.ints.Int2IntMap import it.unimi.dsi.fastutil.objects.Object2IntMap -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} // TODO add a fake random so that the random walk tests can be controlled -class GraphUtilsSpec extends WordSpec with ShouldMatchers { +class GraphUtilsSpec extends WordSpec with Matchers { def utils(graph: DirectedGraph) = { (graph, new GraphUtils(graph)) @@ -185,7 +184,7 @@ class GraphUtilsSpec extends WordSpec with ShouldMatchers { val walk = graphUtils.randomWalk(OutDir, Seq(startNodeId), walkParams) val duration: Duration = elapsed() val (visitsCounter, _) = walk - visitsCounter.infoAllNodes.size should be > (graph.getNodeById(startNodeId).get.outboundCount) + visitsCounter.infoAllNodes.size should be > graph.getNodeById(startNodeId).get.outboundCount if (times > ignoreFirstNum) { sumDuration += duration.inMilliseconds } diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/NodeSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/NodeSpec.scala index 5b5b1561..7f12c4df 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/NodeSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/NodeSpec.scala @@ -13,10 +13,9 @@ */ package com.twitter.cassovary.graph -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} -class NodeSpec extends WordSpec with ShouldMatchers { +class NodeSpec extends WordSpec with Matchers { def noInboundOrOutboundEdges = TestNode(1, Nil, Nil) def onlyInboundEdges = TestNode(1, List(2), Nil) diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/NodeUtilsSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/NodeUtilsSpec.scala index 4bc117eb..5fbb6855 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/NodeUtilsSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/NodeUtilsSpec.scala @@ -14,10 +14,9 @@ package com.twitter.cassovary.graph import com.twitter.cassovary.graph.GraphDir._ -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} -class NodeUtilsSpec extends WordSpec with ShouldMatchers { +class NodeUtilsSpec extends WordSpec with Matchers { def fixture = TestNode(100, List(1,2,3), List(60, 70)) diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/SynchronizedDynamicGraphSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/SynchronizedDynamicGraphSpec.scala index e65f7404..c47128cc 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/SynchronizedDynamicGraphSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/SynchronizedDynamicGraphSpec.scala @@ -14,13 +14,12 @@ package com.twitter.cassovary.graph import java.util.concurrent.Executors -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} import StoredGraphDir._ import scala.concurrent.{Await, ExecutionContext, Future} import scala.concurrent.duration.Duration -class SynchronizedDynamicGraphSpec extends WordSpec with ShouldMatchers { +class SynchronizedDynamicGraphSpec extends WordSpec with Matchers { implicit val ecctxt = ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(4)) "Add new nodes" in { diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/TestGraphSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/TestGraphSpec.scala index c3178283..b5526c65 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/TestGraphSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/TestGraphSpec.scala @@ -13,12 +13,11 @@ package com.twitter.cassovary.graph import org.junit.runner.RunWith -import org.scalatest.WordSpec +import org.scalatest.{Matchers, WordSpec} import org.scalatest.junit.JUnitRunner -import org.scalatest.matchers.ShouldMatchers @RunWith(classOf[JUnitRunner]) -class TestGraphSpec extends WordSpec with ShouldMatchers with GraphBehaviours { +class TestGraphSpec extends WordSpec with Matchers with GraphBehaviours { "three node graph g3 stored in both directions" should { val graph = TestGraphs.g3 diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/TraverserSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/TraverserSpec.scala index 5d961828..bcf303b1 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/TraverserSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/TraverserSpec.scala @@ -14,13 +14,12 @@ package com.twitter.cassovary.graph import org.mockito.Mockito._ -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} import org.scalatest.mock.MockitoSugar import scala.util.Random -class TraverserSpec extends WordSpec with MockitoSugar with ShouldMatchers { +class TraverserSpec extends WordSpec with MockitoSugar with Matchers { class TestIter extends Iterator[Int] { var i = 0 diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/bipartite/BipartiteGraphSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/bipartite/BipartiteGraphSpec.scala index 985a5ef3..7ccfb479 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/bipartite/BipartiteGraphSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/bipartite/BipartiteGraphSpec.scala @@ -14,11 +14,10 @@ package com.twitter.cassovary.graph.bipartite import com.twitter.cassovary.graph.GraphDir -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} import scala.collection.mutable -class BipartiteGraphSpec extends WordSpec with ShouldMatchers { +class BipartiteGraphSpec extends WordSpec with Matchers { def bipartiteExampleSingleSide() = { /* diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/NodeBehaviors.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/NodeBehaviors.scala index 895fe1e5..a867e14b 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/NodeBehaviors.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/NodeBehaviors.scala @@ -14,10 +14,9 @@ package com.twitter.cassovary.graph.node import NodeTestUtils._ import com.twitter.cassovary.graph.Node -import org.scalatest.matchers.ShouldMatchers -import org.scalatest.WordSpec +import org.scalatest.{Matchers, WordSpec} -trait NodeBehaviors extends WordSpec with ShouldMatchers { +trait NodeBehaviors extends WordSpec with Matchers { val nodeId = 100 val neighbors = Array(1,2,3) val inEdges = Array(4,5) diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/NodeTestUtils.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/NodeTestUtils.scala index 8ee102ec..e34eba0e 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/NodeTestUtils.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/NodeTestUtils.scala @@ -14,8 +14,7 @@ package com.twitter.cassovary.graph.node -import com.twitter.cassovary.graph.StoredGraphDir._ -import com.twitter.cassovary.graph.{Node, StoredGraphDir} +import com.twitter.cassovary.graph.Node import org.scalatest.matchers.{MatchResult, Matcher} object NodeTestUtils { diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/SharedArrayBasedDirectedNodeSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/SharedArrayBasedDirectedNodeSpec.scala index a07cb133..f7ceddd7 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/SharedArrayBasedDirectedNodeSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/SharedArrayBasedDirectedNodeSpec.scala @@ -13,7 +13,7 @@ */ package com.twitter.cassovary.graph.node -import com.twitter.cassovary.graph.{Node, StoredGraphDir} +import com.twitter.cassovary.graph.StoredGraphDir class SharedArrayBasedDirectedNodeSpec extends NodeBehaviors { val sharedArray = Array[Array[Int]](neighbors) diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/SynchronizedDynamicNodeSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/SynchronizedDynamicNodeSpec.scala index 0be36cb5..992ff900 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/SynchronizedDynamicNodeSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/node/SynchronizedDynamicNodeSpec.scala @@ -13,10 +13,9 @@ */ package com.twitter.cassovary.graph.node -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} -class SynchronizedDynamicNodeSpec extends WordSpec with ShouldMatchers { +class SynchronizedDynamicNodeSpec extends WordSpec with Matchers { def fixture(id: Int) = new SynchronizedDynamicNode(id) @@ -27,7 +26,7 @@ class SynchronizedDynamicNodeSpec extends WordSpec with ShouldMatchers { node1.addInBoundNode(2) val node3 = fixture(2) node1 shouldEqual node2 - node1 should not equal (node3) + node1 should not equal node3 } "perform add/delete functions correctly" in { diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/tourist/NodeTouristSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/tourist/NodeTouristSpec.scala index 95719ade..4ccdbb2e 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/graph/tourist/NodeTouristSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/graph/tourist/NodeTouristSpec.scala @@ -17,10 +17,9 @@ import com.twitter.cassovary.graph.{DirectedPath, TestNode} import com.twitter.cassovary.util.FastUtilUtils import it.unimi.dsi.fastutil.ints.Int2IntMap import it.unimi.dsi.fastutil.objects.Object2IntMap -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} -class NodeTouristSpec extends WordSpec with ShouldMatchers { +class NodeTouristSpec extends WordSpec with Matchers { def testNode(id: Int) = TestNode(id, Nil, Nil) diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/util/BinomialDistributionSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/util/BinomialDistributionSpec.scala index 2bad2232..6ccb4220 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/util/BinomialDistributionSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/util/BinomialDistributionSpec.scala @@ -15,12 +15,11 @@ package com.twitter.cassovary.util import org.junit.runner.RunWith import org.scalatest.junit.JUnitRunner -import org.scalatest.matchers.ShouldMatchers -import org.scalatest.{PrivateMethodTester, WordSpec} +import org.scalatest.{Matchers, PrivateMethodTester, WordSpec} import scala.util.Random @RunWith(classOf[JUnitRunner]) -class BinomialDistributionSpec extends WordSpec with ShouldMatchers with PrivateMethodTester { +class BinomialDistributionSpec extends WordSpec with Matchers with PrivateMethodTester { val twoPoint = new BinomialDistribution(1, 0.3) val twoTrials = new BinomialDistribution(2, 0.8) @@ -45,12 +44,12 @@ class BinomialDistributionSpec extends WordSpec with ShouldMatchers with Private "binomial distribution with 2 trials" should { val expected = Array(0.2 * 0.2, 2 * 0.2 * 0.8, 0.8 * 0.8) "have correct pdf" in { - (twoTrials invokePrivate pdf()).zip(expected).foreach{case (x, y) => x should be (y plusOrMinus 0.001)} + (twoTrials invokePrivate pdf()).zip(expected).foreach{case (x, y) => x should be (y +- 0.001)} } "have correct cdf" in { val expected = Array(0.2 * 0.2, 0.2 * 0.2 + 2 * 0.2 * 0.8) - (twoTrials invokePrivate cdf()).zip(expected).foreach{case (x, y) => x should be (y plusOrMinus 0.001)} + (twoTrials invokePrivate cdf()).zip(expected).foreach{case (x, y) => x should be (y +- 0.001)} } } @@ -80,7 +79,7 @@ class BinomialDistributionSpec extends WordSpec with ShouldMatchers with Private } "have pdf that sums up to 1" in { - (distribution10 invokePrivate pdf()).sum should be (1.0 plusOrMinus 0.005) + (distribution10 invokePrivate pdf()).sum should be (1.0 +- 0.005) } "have increasing cdf" in { @@ -100,7 +99,7 @@ class BinomialDistributionSpec extends WordSpec with ShouldMatchers with Private val error = (distribution10 invokePrivate pdf())(i) - histogram.getOrElse(i, 0.0) mse += error * error } - mse should be (0.0 plusOrMinus 0.01) // checked experimentally to be true with high probability + mse should be (0.0 +- 0.01) // checked experimentally to be true with high probability } } } diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/util/MapNodeNumbererSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/util/MapNodeNumbererSpec.scala index d308b24c..90838f9f 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/util/MapNodeNumbererSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/util/MapNodeNumbererSpec.scala @@ -16,11 +16,10 @@ package com.twitter.cassovary.util import org.junit.runner.RunWith import org.scalatest.junit.JUnitRunner -import org.scalatest.WordSpec -import org.scalatest.matchers.{ShouldMatchers} +import org.scalatest.{Matchers, WordSpec} @RunWith(classOf[JUnitRunner]) -class MapNodeNumbererSpec extends WordSpec with ShouldMatchers { +class MapNodeNumbererSpec extends WordSpec with Matchers { val directory = "cassovary-core/src/test/resources/nodeNumberers/" "Map node numberer" should { @@ -36,19 +35,17 @@ class MapNodeNumbererSpec extends WordSpec with ShouldMatchers { numberer.internalToExternal(29) should be ("spoon") numberer.internalToExternal(12) should be ("bike") - evaluating (numberer.externalToInternal("apple")) should produce [NoSuchElementException] + an [NoSuchElementException] should be thrownBy numberer.externalToInternal("apple") - evaluating (numberer.internalToExternal(3)) should produce [NoSuchElementException] + an [NoSuchElementException] should be thrownBy numberer.internalToExternal(3) } "find duplicated names" in { - evaluating (MapNodeNumberer.forStringsFromFile(directory + "numbering-duplicatedId.txt")) should - produce [Exception] + an [Exception] should be thrownBy MapNodeNumberer.forStringsFromFile(directory + "numbering-duplicatedId.txt") } "find duplicated ids" in { - evaluating (MapNodeNumberer.forStringsFromFile(directory + "numbering-duplicatedName.txt")) should - produce [Exception] + an [Exception] should be thrownBy MapNodeNumberer.forStringsFromFile(directory + "numbering-duplicatedName.txt") } } } diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/util/SamplingSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/util/SamplingSpec.scala index c5df6530..2f99a3fa 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/util/SamplingSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/util/SamplingSpec.scala @@ -15,12 +15,11 @@ package com.twitter.cassovary.util import org.junit.runner.RunWith import org.scalatest.junit.JUnitRunner -import org.scalatest.matchers.ShouldMatchers -import org.scalatest.WordSpec +import org.scalatest.{Matchers, WordSpec} import scala.util.Random @RunWith(classOf[JUnitRunner]) -class SamplingSpec extends WordSpec with ShouldMatchers { +class SamplingSpec extends WordSpec with Matchers { val array = (1 to 100).toArray val range = 1 to 100 diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/util/SequentialNodeNumbererSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/util/SequentialNodeNumbererSpec.scala index f891f7c6..5e2f8916 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/util/SequentialNodeNumbererSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/util/SequentialNodeNumbererSpec.scala @@ -14,13 +14,12 @@ package com.twitter.cassovary.util import org.junit.runner.RunWith -import org.scalatest.WordSpec +import org.scalatest.{Matchers, WordSpec} import org.scalatest.junit.JUnitRunner -import org.scalatest.matchers.{ShouldMatchers} @RunWith(classOf[JUnitRunner]) -class SequentialNodeNumbererSpec extends WordSpec with ShouldMatchers { +class SequentialNodeNumbererSpec extends WordSpec with Matchers { "SequentialNodeNumberer" when { "numbering Longs" should { "use consecutive numbers" in { @@ -39,7 +38,7 @@ class SequentialNodeNumbererSpec extends WordSpec with ShouldMatchers { } "raise exception when using internal id not defined so far" in { val numberer = new SequentialNodeNumberer[Long] - evaluating (numberer.internalToExternal(4)) should produce [IndexOutOfBoundsException] + an [IndexOutOfBoundsException] should be thrownBy numberer.internalToExternal(4) } } "numbering Strings" should { @@ -59,7 +58,7 @@ class SequentialNodeNumbererSpec extends WordSpec with ShouldMatchers { } "raise exception when using internal id not defined so far" in { val numberer = new SequentialNodeNumberer[String] - evaluating (numberer.internalToExternal(4)) should produce [IndexOutOfBoundsException] + an [IndexOutOfBoundsException] should be thrownBy numberer.internalToExternal(4) } } } diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/util/SharedArraySeqSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/util/SharedArraySeqSpec.scala index 93df5e04..8dff6023 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/util/SharedArraySeqSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/util/SharedArraySeqSpec.scala @@ -13,10 +13,9 @@ */ package com.twitter.cassovary.util -import org.scalatest.matchers.ShouldMatchers -import org.scalatest.WordSpec +import org.scalatest.{Matchers, WordSpec} -class SharedArraySeqSpec extends WordSpec with ShouldMatchers { +class SharedArraySeqSpec extends WordSpec with Matchers { val arr1 = Array(1,2,3) val arr2 = Array(4,5) @@ -27,15 +26,15 @@ class SharedArraySeqSpec extends WordSpec with ShouldMatchers { "construct seqs correctly" in { val seq1 = new SharedArraySeq(0, sharedArray, 0, 3) seq1.toList shouldEqual arr1.toList - (new SharedArraySeq(0, sharedArray, 1, 2)).toList shouldEqual List(2, 3) + new SharedArraySeq(0, sharedArray, 1, 2).toList shouldEqual List(2, 3) seq1(0) shouldEqual 1 seq1(1) shouldEqual 2 seq1(2) shouldEqual 3 - evaluating { seq1(3) } should produce [IndexOutOfBoundsException] + an [IndexOutOfBoundsException] should be thrownBy { seq1(3) } } "implement foreach correctly" in { - ((new SharedArraySeq(0, sharedArray, 0, 3)) map { _ + 1 }) shouldEqual List(2, 3, 4) + (new SharedArraySeq(0, sharedArray, 0, 3) map { _ + 1 }) shouldEqual List(2, 3, 4) } } @@ -55,15 +54,15 @@ class SharedArraySeqSpec extends WordSpec with ShouldMatchers { seq1(0) shouldEqual 1 seq1(1) shouldEqual 2 seq1(2) shouldEqual 3 - evaluating { seq1(3) } should produce [IndexOutOfBoundsException] + an [IndexOutOfBoundsException] should be thrownBy { seq1(3) } seq2(0) shouldEqual 4 seq2(1) shouldEqual 5 - evaluating { seq2(2) } should produce [IndexOutOfBoundsException] + an [IndexOutOfBoundsException] should be thrownBy { seq2(2) } } "implement foreach correctly" in { - ((new SharedArraySeq(111, sharedArray, 0, 2)) map { _ + 1 }) shouldEqual List(5, 6) + (new SharedArraySeq(111, sharedArray, 0, 2) map { _ + 1 }) shouldEqual List(5, 6) } } } diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/util/SmallBoundedPriorityQueueSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/util/SmallBoundedPriorityQueueSpec.scala index c83f1b71..c56e77bc 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/util/SmallBoundedPriorityQueueSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/util/SmallBoundedPriorityQueueSpec.scala @@ -13,12 +13,10 @@ */ package com.twitter.cassovary.util -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers - +import org.scalatest.{Matchers, WordSpec} import scala.reflect.ClassTag -class SmallBoundedPriorityQueueSpec extends WordSpec with ShouldMatchers { +class SmallBoundedPriorityQueueSpec extends WordSpec with Matchers { def emptyQueue[A](maxSize: Int)(implicit m: ClassTag[A], ord: Ordering[A]) = { new SmallBoundedPriorityQueue[A](maxSize) } diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/AdjacencyListGraphReaderSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/AdjacencyListGraphReaderSpec.scala index 4651c5ef..afc128eb 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/AdjacencyListGraphReaderSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/AdjacencyListGraphReaderSpec.scala @@ -16,10 +16,9 @@ package com.twitter.cassovary.util.io import com.twitter.cassovary.graph.GraphBehaviours import com.twitter.cassovary.util.SequentialNodeNumberer import java.util.concurrent.Executors -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} -class AdjacencyListGraphReaderSpec extends WordSpec with ShouldMatchers with GraphBehaviours { +class AdjacencyListGraphReaderSpec extends WordSpec with Matchers with GraphBehaviours { val directory = "cassovary-core/src/test/resources/graphs/" val toy6nodeMap = Map( 10 -> List(11, 12, 13), 11 -> List(12, 14), 12 -> List(14), diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/GraphWriterSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/GraphWriterSpec.scala index 229d2650..fb70b823 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/GraphWriterSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/GraphWriterSpec.scala @@ -15,10 +15,9 @@ package com.twitter.cassovary.util.io import com.twitter.cassovary.graph.TestGraphs import java.io.StringWriter -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} -class GraphWriterSpec extends WordSpec with ShouldMatchers { +class GraphWriterSpec extends WordSpec with Matchers { "Graph writer" should { "write graph to single file" in { val graph = TestGraphs.g6 diff --git a/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/ListOfEdgesGraphReaderSpec.scala b/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/ListOfEdgesGraphReaderSpec.scala index 32e7ba4b..209bcb2b 100644 --- a/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/ListOfEdgesGraphReaderSpec.scala +++ b/cassovary-core/src/test/scala/com/twitter/cassovary/util/io/ListOfEdgesGraphReaderSpec.scala @@ -16,10 +16,9 @@ package com.twitter.cassovary.util.io import com.twitter.cassovary.graph.GraphBehaviours import com.twitter.cassovary.util.SequentialNodeNumberer import java.util.concurrent.Executors -import org.scalatest.WordSpec -import org.scalatest.matchers.ShouldMatchers +import org.scalatest.{Matchers, WordSpec} -class ListOfEdgesGraphReaderSpec extends WordSpec with GraphBehaviours with ShouldMatchers { +class ListOfEdgesGraphReaderSpec extends WordSpec with GraphBehaviours with Matchers { val intGraphMap = Map(1 -> List(2, 3), 2 -> List(3), 3 -> List(4), 4 -> List(1))