-
Notifications
You must be signed in to change notification settings - Fork 2
/
MatcherTest.java
121 lines (101 loc) · 3.85 KB
/
MatcherTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package edu.kit.informatik.matchthree.tests;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import edu.kit.informatik.matchthree.MatchThreeBoard;
import edu.kit.informatik.matchthree.MaximumDeltaMatcher;
import edu.kit.informatik.matchthree.framework.Delta;
import edu.kit.informatik.matchthree.framework.Position;
import edu.kit.informatik.matchthree.framework.RandomStrategy;
import edu.kit.informatik.matchthree.framework.Token;
import edu.kit.informatik.matchthree.framework.interfaces.Board;
import edu.kit.informatik.matchthree.framework.interfaces.Matcher;
public class MatcherTest {
private Board board;
private Set<Delta> deltas;
private Matcher mat;
@Before
public void init() {
Set<Token> tokens = new HashSet<Token>();
tokens
.addAll(Arrays.asList(new Token[] { new Token("a"), new Token("b") }));
board = new MatchThreeBoard(tokens, "ab;ab;aa");
deltas = new HashSet<Delta>();
deltas.add(new Delta(0, 1));
mat = new MaximumDeltaMatcher(deltas);
}
@Test
public void match() {
final Position initial = new Position(0, 2);
Set<Set<Position>> match = mat.match(board, initial);
Set<Position> expectedPre = new HashSet<Position>();
expectedPre.add(new Position(0, 0));
expectedPre.add(new Position(0, 1));
expectedPre.add(new Position(0, 2));
Set<Set<Position>> expected = new HashSet<Set<Position>>();
expected.add(expectedPre);
assertEquals(expected, match);
}
@Test
public void matchAll() {
final Set<Position> initial = new HashSet<Position>();
initial.add(new Position(0, 2));
initial.add(new Position(1, 0));
Set<Set<Position>> match = mat.matchAll(board, initial);
Set<Position> expectedPre = new HashSet<Position>();
expectedPre.add(new Position(0, 0));
expectedPre.add(new Position(0, 1));
expectedPre.add(new Position(0, 2));
// TODO test so richtig fuer matchAll??
// beschreibung seltsam ?!
Set<Position> expectedPre2 = new HashSet<Position>();
expectedPre2.add(new Position(1, 0));
expectedPre2.add(new Position(1, 1));
Set<Set<Position>> expected = new HashSet<Set<Position>>();
expected.add(expectedPre);
expected.add(expectedPre2);
assertEquals(expected, match);
}
@Ignore("Runtime_Test")
@Test(timeout = 15000)
/*
* timeout = 15000ms using cpu:
* Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz : 2000,00MHz
*/
public void matchAllMegaStresstest() {
// tests only runtime, not result!
for (int N = 10; N < 201; N += 10) {
Set<Token> tokens = new HashSet<Token>();
tokens.addAll(Arrays
.asList(new Token[] { new Token("a"), new Token("b") }));
board = new MatchThreeBoard(tokens, N, N);
board.setFillingStrategy(new RandomStrategy());
board.fillWithTokens();
for (int i = -100; i < 100; i++) {
if (i != 0) {
deltas.add(new Delta(i, i));
deltas.add(new Delta(2*i, 2*i));
}
}
deltas.add(new Delta(1,0));
final long befInit = System.currentTimeMillis();
mat = new MaximumDeltaMatcher(deltas);
System.out.println("Time to generate: " + (System.currentTimeMillis() - befInit));
final long before = System.currentTimeMillis();
mat.matchAll(board,
toSet(new Position(N / 2, N / 2), new Position(N / 4, N / 4)));
System.out.println((System.currentTimeMillis() - before) + "ms for " + N
+ "x" + N);
}
}
// TODO sehr viele tests, auch invalide sachen
private static <T> Set<T> toSet(T... elems) {
Set<T> ret = new HashSet<T>();
ret.addAll(Arrays.asList(elems));
return ret;
}
}