Skip to content

Instantly share code, notes, and snippets.

@jponge
Created September 24, 2009 07:08
Show Gist options
  • Save jponge/192564 to your computer and use it in GitHub Desktop.
Save jponge/192564 to your computer and use it in GitHub Desktop.
package fr.inria.gforge.amazones.protocols.model
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.Spec
import org.scalatest.matchers.ShouldMatchers
@RunWith(classOf[JUnitRunner])
class DirectedGraphSpec extends Spec with ShouldMatchers {
describe("A simple directed graph") {
val dg = new DirectedGraph(
Set("s0", "s1", "s2"),
Set(
EdgeNode("s0", "a", "s1"),
EdgeNode("s1", "c", "s1"),
EdgeNode("s1", "b", "s2")
)
)
it("should be well constructed") {
dg.vertices should have size (3)
dg.edges should have size (3)
dg.edgeValues should (have size (3) and contain("a") and contain("b") and contain("c"))
dg.outgoing("s0") should (have size (1) and contain(EdgeNode("s0", "a", "s1")))
dg.neighbors("s0") should (have size (1) and contain("s1"))
dg.predecessors("s0") should be('empty)
dg.outgoing("s1") should (have size (2) and contain(EdgeNode("s1", "c", "s1")))
dg.neighbors("s2") should be('empty)
dg.incoming("s1") should (have size (2) and contain(EdgeNode("s0", "a", "s1")))
dg.predecessors("s1") should (have size (2) and contain("s0") and contain("s1"))
}
it("should be comparable to another graph") {
val otherSame = new DirectedGraph(
Set("s0", "s1", "s2"),
Set(
EdgeNode("s0", "a", "s1"),
EdgeNode("s1", "c", "s1"),
EdgeNode("s1", "b", "s2")
)
)
val otherDifferent = new DirectedGraph(
Set("s0", "s1"),
Set(
EdgeNode("s0", "a", "s1"),
EdgeNode("s1", "b", "s1"),
)
)
dg should equal (otherSame)
dg should not equal (otherDifferent)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment