Skip to content

Commit 2e8a646

Browse files
author
Daniel Barclay
committed
ManualTicTacToe: Added test of private vectorIndex.
1 parent c303e23 commit 2e8a646

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/test/scala/com/us/dsb/explore/algs/ttt/manual/BoardTest.scala

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.us.dsb.explore.algs.ttt.manual
22

33
import cats.syntax.option._
4-
4+
import org.scalatest.{PrivateMethodTester, color}
55
import org.scalatest.funspec.AnyFunSpec
66
import org.scalatest.matchers.should.Matchers._
77

@@ -229,16 +229,32 @@ class BoardTest extends AnyFunSpec {
229229
}
230230

231231
ignore("possibly check all lines (algorithmically)") {
232-
233232
}
234233

235234
}
236235

237-
describe("Board.vectorIndex:") {
238-
it("how and how hard/disruptive to test private method?") {
239-
cancel()
236+
describe("Board.vectorIndex (private method we want to test directly):") {
237+
import PrivateMethodTester._
238+
val vectorIndex = PrivateMethod[Int](Symbol("vectorIndex"))
239+
240+
it("should compute 0 for first row, first column") {
241+
val index = Board.initial invokePrivate vectorIndex(Index(1), columnIndices.head)
242+
index shouldEqual 0
243+
}
244+
245+
it("should compute array length - 1 for last row, last column") {
246+
val index = Board.initial invokePrivate vectorIndex(rowIndices.last, Index(3))
247+
index shouldEqual Order * Order - 1
240248
}
241-
}
242249

250+
describe("should compute indices in row-major order (chosen but ~isolated)") {
251+
it("1, 2 => 1") {
252+
Board.initial invokePrivate vectorIndex(Index(1), Index(2)) shouldEqual 1
253+
}
254+
it("2, 1 => 3 (Order/row length/# columns)") {
255+
Board.initial invokePrivate vectorIndex(Index(2), Index(1)) shouldEqual Order
256+
}
257+
}
258+
}
243259

244260
}

0 commit comments

Comments
 (0)