2
* This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
8
class BoardTest extends haxe.unit.TestCaseX
10
static var testBoard = [
16
//second value is the "Score"
17
static var foundWords = [
18
["fantastico", 1], //full permutation, with double letter
19
["a", 0], //x2 must be found twice, single letter
21
["ants", 0], //prefix also exists "ant"
22
["sat", 0], //x3 multiple path lookup
23
["coin", 1] //double letter
26
static var unfoundWords = [
27
["fantastic", 0], //invalid double letter split
28
["fin", 0], //incorrect permutation
29
["cost", 0], //incorrect permutation on double
30
["cat", 0], //incorrect split as prefix
31
["sats", 0], //double use of a single letter
34
private function getAnagram()
36
var m = mathx.Matrix.fromArrayMat( testBoard );
37
var enc = new words.Encoder_EN();
38
var hash = HashUtil.merge(
39
HashUtil.fromArray( foundWords ),
40
HashUtil.fromArray( unfoundWords )
42
var dict = words.Dictionary.withHash( hash, enc );
44
return words.Anagram.withMatrix( m, dict );
47
public function testSearch()
49
var ana = getAnagram();
51
while( ana.step( 1000 ) )
52
{ } //it has to end sometime...
54
for( fw in foundWords )
55
assertEquals( fw[1], ana.found.get( fw[0] ) );
57
//we can't verify the multiple counts now since Anagram stores in a Hash
59
for( uw in unfoundWords )
60
assertFalse( ana.found.exists( uw[0] ) );
63
public function testBoardClass()
65
var board = words.WordBoard.withMatrix(
66
mathx.Matrix.fromArrayMat( testBoard )
69
for( fw in foundWords )
70
assertTrue( board.contains( fw[0] ) );
71
for( uw in unfoundWords )
72
assertFalse( board.contains( uw[0] ) );
76
public function testSearchPerf()
78
var start = haxe.Timer.stamp();
81
var ana = getAnagram();
82
while( ana.step( 1000 ) )
83
{ } //it has to end sometime...
85
var end = haxe.Timer.stamp();
87
trace( "Lookup: " + (end-start) );
92
public function testEncoderEN()
94
var enc = new words.Encoder_EN();
95
for( fw in foundWords )
96
assertEquals( fw[0], enc.decode( enc.encode( fw[0] ) ) );