Skip to content

Commit

Permalink
add tests for published SimpleChangeEvent after world resize
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaspayette committed Jul 30, 2013
1 parent d7ae29e commit cea8012
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/org/nlogo/agent/AbstractTestWorld.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package org.nlogo.agent

import org.scalatest.Assertions
import org.nlogo.api.SimpleChangeEvent
import org.nlogo.api.SimpleChangeEventPublisher
import org.nlogo.api.WorldDimensions

// Exists to be separately extended in 2D and 3D versions. - ST 10/18/10
Expand Down Expand Up @@ -82,4 +84,22 @@ abstract class AbstractTestWorld extends Assertions {
expect(3)(world.topology.shortestPathY(2, -2))
expect(5)(world.topology.shortestPathX(2, -2))
}

def testChangePublishedAfterWorldResize(d1: WorldDimensions, d2: WorldDimensions) {
class Sub(pub: SimpleChangeEventPublisher) extends SimpleChangeEventPublisher#Sub {
pub.subscribe(this)
var events = Seq[SimpleChangeEvent]()
override def notify(pub: SimpleChangeEventPublisher#Pub, event: SimpleChangeEvent) {
events +:= event
}
}
val world = makeWorld(d1)
val turtleSub = new Sub(world.turtles.asInstanceOf[TreeAgentSet].simpleChangeEventPublisher)
val linkSub = new Sub(world.links.asInstanceOf[TreeAgentSet].simpleChangeEventPublisher)
expect(0)(turtleSub.events.size)
expect(0)(linkSub.events.size)
world.createPatches(d2)
expect(1)(turtleSub.events.size)
expect(1)(linkSub.events.size)
}
}
3 changes: 3 additions & 0 deletions src/test/org/nlogo/agent/World3DTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ class World3DTests extends AbstractTestWorld with FunSuite
test("ShortestPath_3D") {
testShortestPath(worldRectangle)
}
test("ChangePublishedAfterWorldResize_3D") {
testChangePublishedAfterWorldResize(worldSquare, worldRectangle)
}
}
3 changes: 3 additions & 0 deletions src/test/org/nlogo/agent/WorldTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ class WorldTests extends AbstractTestWorld with FunSuite {
expect(3.0)(world.topology.shortestPathY(2, -2))
expect(-2.0)(world.topology.shortestPathX(2, -2))
}
test("ChangePublishedAfterWorldResize_2D") {
testChangePublishedAfterWorldResize(worldSquare, worldRectangle)
}
}

0 comments on commit cea8012

Please sign in to comment.