feat: update draw offer test to include draw decline scenario
Build & Test (NowChessSystems) TeamCity build failed
Build & Test (NowChessSystems) TeamCity build failed
This commit is contained in:
@@ -194,7 +194,7 @@ class GameEngineDrawOfferTest extends AnyFunSuite with Matchers:
|
|||||||
case other =>
|
case other =>
|
||||||
fail(s"Expected InvalidMoveEvent, but got $other")
|
fail(s"Expected InvalidMoveEvent, but got $other")
|
||||||
|
|
||||||
test("Draw offer is cleared when game ends by resignation"):
|
test("Draw offer is cleared when game ends by resignation (accept)"):
|
||||||
val engine = new GameEngine()
|
val engine = new GameEngine()
|
||||||
val observer = new DrawOfferMockObserver()
|
val observer = new DrawOfferMockObserver()
|
||||||
engine.subscribe(observer)
|
engine.subscribe(observer)
|
||||||
@@ -214,6 +214,26 @@ class GameEngineDrawOfferTest extends AnyFunSuite with Matchers:
|
|||||||
case other =>
|
case other =>
|
||||||
fail(s"Expected InvalidMoveEvent, but got $other")
|
fail(s"Expected InvalidMoveEvent, but got $other")
|
||||||
|
|
||||||
|
test("Draw offer is cleared when game ends by resignation"):
|
||||||
|
val engine = new GameEngine()
|
||||||
|
val observer = new DrawOfferMockObserver()
|
||||||
|
engine.subscribe(observer)
|
||||||
|
|
||||||
|
engine.offerDraw(Color.White)
|
||||||
|
observer.events.clear()
|
||||||
|
engine.resign(Color.Black)
|
||||||
|
|
||||||
|
// Try to accept the now-cleared draw offer
|
||||||
|
observer.events.clear()
|
||||||
|
engine.declineDraw(Color.White)
|
||||||
|
|
||||||
|
observer.events should have length 1
|
||||||
|
observer.events.head match
|
||||||
|
case event: InvalidMoveEvent =>
|
||||||
|
event.reason shouldBe InvalidMoveReason.GameAlreadyOver
|
||||||
|
case other =>
|
||||||
|
fail(s"Expected InvalidMoveEvent, but got $other")
|
||||||
|
|
||||||
private class DrawOfferMockObserver extends Observer:
|
private class DrawOfferMockObserver extends Observer:
|
||||||
val events = mutable.ListBuffer[GameEvent]()
|
val events = mutable.ListBuffer[GameEvent]()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user