-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.html
85 lines (70 loc) · 2.87 KB
/
tests.html
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
<html>
<head>
<title>Mastermind Tests</title>
<style>
p { margin: 0; }
</style>
</head>
<body>
<div>
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
<img /><img /><img /><img /><img /><img /><img /><img /><img /><img />
</div>
<script src="mm.js"></script>
<script>
// tests! :o
var body = document.body;
var echo = function (message) {
var element = document.createElement('p');
element.innerText = message;
document.body.appendChild(element);
};
var should = function(a, b) {
var equal = true;
a.forEach(function(v, i) {
equal = v === b[i] && equal;
});
equal = (a.length === b.length);
if (equal) {
echo(true);
} else {
echo(a, 'is not ===', b);
}
};
var game = new Mastermind();
var ref = ['b', 'a', 'f', 'a'];
should( game.reportResults(['a', 'd', 'e', 'a'], ref), [2, 1] );
should( game.reportResults(['b', 'b', 'a', 'b'], ref), [2, 1] );
should( game.reportResults(['c', 'b', 'f', 'a'], ref), [2, 2, 1] );
should( game.reportResults(['a', 'b', 'a', 'e'], ref), [1, 1, 1] );
should( game.reportResults(['c', 'a', 'a', 'e'], ref), [2, 1] );
should( game.reportResults(['f', 'f', 'e', 'e'], ref), [1] );
should( game.reportResults(['f', 'f', 'e', 'e'], ['e', 'a', 'b', 'c']), [1] );
should( game.reportResults(['f', 'f', 'e', 'e'], ['a', 'b', 'c', 'e']), [2] );
should( game.reportResults(['a', 'e', 'a', 'e'], ref), [1, 1] );
ref = [1, 0, 5, 0];
should( game.reportResults([0, 3, 4, 0], ref), [2, 1] );
should( game.reportResults([1, 1, 0, 1], ref), [2, 1] );
should( game.reportResults([2, 1, 5, 0], ref), [2, 2, 1] );
should( game.reportResults([0, 1, 0, 4], ref), [1, 1, 1] );
should( game.reportResults([2, 0, 0, 4], ref), [2, 1] );
should( game.reportResults([5, 5, 4, 4], ref), [1] );
should( game.reportResults([5, 5, 4, 4], [4, 0, 1, 2]), [1] );
should( game.reportResults([5, 5, 4, 4], [0, 1, 2, 4]), [2] );
should( game.reportResults([0, 4, 0, 4], ref), [1, 1] );
</script>
</body>
</html>