Skip to content

Commit

Permalink
cleanup - moved tests to sudoku-core
Browse files Browse the repository at this point in the history
  • Loading branch information
rladstaetter committed Jan 6, 2016
1 parent b07a82c commit e37ddd3
Show file tree
Hide file tree
Showing 36 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object TemplateLibrary extends CanLog {
private val (templateWidth, templateHeight) = (25.0, 50.0)
val templateSize = new Size(templateWidth, templateHeight)
var getResourceAsStream: String => InputStream = getClass.getResourceAsStream
var templateResource: String = "/net/ladstatt/apps/sudokufx/templates.csv"
var templateResource: String = "templates.csv"

lazy val asSeq: Seq[Mat] = logWithTimer("Initialize templates", {
val digits: Seq[Array[Int]] =
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import scala.util.{Failure, Try}
*/
class HistoryTest {

//OpenCV.loadNativeLib("../lib/libopencv_java310.so")

@Test
def invalidSCell() = {
Try {
SCell(-10, 0, null)
fail()
} match {
case Failure(e: AssertionError) =>
case _ => fail("should throw an AssertionError")
Expand All @@ -26,6 +25,7 @@ class HistoryTest {
def invalidSCell2() = {
Try {
SCell(0, -1, null)
fail()
} match {
case Failure(e: AssertionError) =>
case _ => fail("should throw an AssertionError")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import scala.concurrent.duration.Duration
object OpenCVTestContext extends CanLog {


lazy val frame69: Mat = Imgcodecs.imread("src/test/resources/frame69.png")
lazy val solution69 =
lazy val frameSudoku_1: Mat = Imgcodecs.imread("src/test/resources/net/ladstatt/sudoku/sudoku_1.png")
lazy val solutionSudoku_1 =
"""617948532
|524361879
|389725641
Expand All @@ -26,9 +26,9 @@ object OpenCVTestContext extends CanLog {
|275683194
|461592387
|893174265""".stripMargin.replaceAll("\n", "").toCharArray
lazy val sudoku69 = SCandidate(nr = 0, frame = frame69)
lazy val sudoku_1 = SCandidate(nr = 0, frame = frameSudoku_1)

lazy val (sudoku69Result, _, _) = Await.result(sudoku69.calc(Map(), Map(), 1, 17, 5000L), Duration.Inf)
lazy val (sudoku_1Result, _, _) = Await.result(sudoku_1.calc(Map(), Map(), 1, 17, 5000L), Duration.Inf)

lazy val emptyFrame = new Mat(1280, 768, CvType.CV_8UC3)
lazy val emptySudoku = SCandidate(nr = 0, frame = emptyFrame)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package net.ladstatt.sudoku
import org.junit.Assert._
import org.junit.Test

import scala.io.Source
import scala.util.{Failure, Success, Try}

class SolverTest {
Expand Down Expand Up @@ -33,7 +32,7 @@ class SolverTest {
def testSolving(): Unit = {
Try {
val solvedSudokus: Array[Option[SudokuDigitSolution]] =
for (sudokuAsString <- easySudokus.split("========"))
for (sudokuAsString <- SudokuTestContext.easySudokus.split("========"))
yield solveReadableSudoku(sudokuAsString)

for (fs <- solvedSudokus.flatten) {
Expand Down Expand Up @@ -68,9 +67,5 @@ class SolverTest {
}
}

// see http://norvig.com/easy50.txt
// and also make sure to visit http://norvig.com/sudoku.html
val easySudokus =
Source.fromInputStream(getClass.getResourceAsStream("/easysudokus.txt")).getLines().mkString("\n")

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.ladstatt.sudoku


import net.ladstatt.core.CanLog
import net.ladstatt.opencv.OpenCV
import org.junit.runner.RunWith
Expand All @@ -17,7 +16,7 @@ final class SudokuStateTest extends FunSuite with GeneratorDrivenPropertyChecks
// val frameGen : Gen[Mat] =
val stateGen: Gen[SCandidate] =
for {nr <- Gen.choose(0, 10000)
f <- Gen.const(OpenCVTestContext.frame69)
f <- Gen.const(OpenCVTestContext.frameSudoku_1)
cap <- Gen.choose(8, 15)
minHits <- Gen.choose(20, 30)} yield SCandidate(nr = nr, frame = f )
// SudokuState(cap = cap, minHits = minHits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SudokuTest {
OpenCV.loadNativeLib("../lib/libopencv_java310.so")

val refCellNumbers: Seq[(Int, Double)] = {
val lines: Iterator[String] = Source.fromFile(new File("src/test/resources/cellNumbers69.csv")).getLines
val lines: Iterator[String] = Source.fromFile(new File("src/test/resources/net/ladstatt/sudoku/sudoku_1_ref.csv")).getLines
(for (l <- lines) yield {
val a = l.split(',')
(a(0).toInt, a(1).toDouble)
Expand All @@ -31,7 +31,7 @@ class SudokuTest {
@Test def testDetect(): Unit = {
import scala.concurrent.ExecutionContext.Implicits.global
assertEquals(81.toLong, refCellNumbers.size.toLong)
val cells = Await.result(Future.sequence(OpenCVTestContext.sudoku69.cellDetector.futureSCells), Duration.Inf)
val cells = Await.result(Future.sequence(OpenCVTestContext.sudoku_1.cellDetector.futureSCells), Duration.Inf)
var i = 0
for (c <- cells) {
assertEquals(refCellNumbers(i)._1.toLong, c.value.toLong)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.ladstatt.sudoku

import scala.io.Source

/**
* Created by lad on 06.01.16.
*/
object SudokuTestContext {

// see http://norvig.com/easy50.txt
// and also make sure to visit http://norvig.com/sudoku.html
val easySudokus =
Source.fromInputStream(getClass.getResourceAsStream("easysudokus.txt")).getLines().mkString("\n")

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SudokuFXApplication extends Application with JfxUtils {
Try {
stage.setTitle("SudokuFX")

val fxmlLoader = mkFxmlLoader("/net/ladstatt/apps/sudokufx.fxml")
val fxmlLoader = mkFxmlLoader("/net/ladstatt/sudoku/sudokufx.fxml")
val parent = fxmlLoader.load[VBox]()
val controller = fxmlLoader.getController[SudokuFXController]
val scene = new Scene(parent)
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit e37ddd3

Please sign in to comment.