1
|
|
|
/** |
2
|
|
|
* Test for class memorycard. |
3
|
|
|
*/ |
4
|
|
|
"use strict"; |
5
|
|
|
|
6
|
|
|
/* global describe it */ |
7
|
|
|
|
8
|
|
|
var assert = require("assert"); |
9
|
|
|
const Memorycard = require("../../lib/Memory/memorycard"); |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Check a card with its expected card face. |
14
|
|
|
*/ |
15
|
|
|
function checkMemorycardvalue(id, expected) { |
16
|
|
|
let memorycard = new Memorycard(); |
17
|
|
|
let res = memorycard.getCardValue(id); |
18
|
|
|
|
19
|
|
|
assert.equal(res, expected); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Check if two cards is a pair |
24
|
|
|
*/ |
25
|
|
|
function isPair(cardone, cardtwo, expected) { |
26
|
|
|
let memorycard = new Memorycard(); |
27
|
|
|
let res = memorycard.isPair(cardone, cardtwo); |
28
|
|
|
|
29
|
|
|
assert.equal(res, expected); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// function checkCardId(value, expected) { |
33
|
|
|
// let memorycard = new Memorycard(); |
34
|
|
|
// let res = memorycard.getCardId(value); |
35
|
|
|
// |
36
|
|
|
// assert.equal(res[0], expected[0]); |
37
|
|
|
// assert.equal(res[1], expected[1]); |
38
|
|
|
// } |
39
|
|
|
|
40
|
|
|
function checkResetedPosition() { |
41
|
|
|
let memorycard = new Memorycard(); |
42
|
|
|
let res = memorycard.cardvalues; |
43
|
|
|
|
44
|
|
|
memorycard.placeCards(false); |
45
|
|
|
assert.deepEqual(res, [ |
46
|
|
|
"alpaca.png", "alpaca.png", |
47
|
|
|
"giraff.png", "giraff.png", |
48
|
|
|
"monkeys.png", "monkeys.png", |
49
|
|
|
"panda.png", "panda.png", |
50
|
|
|
"puppy.png", "puppy.png", |
51
|
|
|
"ram.png", "ram.png", |
52
|
|
|
"wolf.png", "wolf.png", |
53
|
|
|
"squirrel.png", "squirrel.png", |
54
|
|
|
"fox.png", "fox.png", |
55
|
|
|
"bear.png", "bear.png"]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function checkShuffledPosition() { |
59
|
|
|
let memorycard = new Memorycard(); |
60
|
|
|
let res = memorycard.cardpositions; |
61
|
|
|
|
62
|
|
|
memorycard.placeCards(); |
63
|
|
|
assert.notDeepEqual(res, [ |
64
|
|
|
"alpaca.png", "alpaca.png", |
65
|
|
|
"giraff.png", "giraff.png", |
66
|
|
|
"monkeys.png", "monkeys.png", |
67
|
|
|
"panda.png", "panda.png", |
68
|
|
|
"puppy.png", "puppy.png", |
69
|
|
|
"ram.png", "ram.png", |
70
|
|
|
"wolf.png", "wolf.png", |
71
|
|
|
"squirrel.png", "squirrel.png", |
72
|
|
|
"fox.png", "fox.png", |
73
|
|
|
"bear.png", "bear.png"]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Testsuite |
78
|
|
|
*/ |
79
|
|
|
describe("Check memorycard", function() { |
80
|
|
|
var values = [ |
81
|
|
|
{position: "00", value: "alpaca.png"}, |
82
|
|
|
{position: "01", value: "monkeys.png"}, |
83
|
|
|
{position: "11", value: "monkeys.png"}, |
84
|
|
|
{position: "12", value: "puppy.png"}, |
85
|
|
|
{position: "22", value: "ram.png"}, |
86
|
|
|
{position: "32", value: "ram.png"}, |
87
|
|
|
]; |
88
|
|
|
var pairs = [ |
89
|
|
|
{cardone: "00", cardtwo: "10", expected: true}, |
90
|
|
|
{cardone: "01", cardtwo: "22", expected: false}, |
91
|
|
|
{cardone: "02", cardtwo: "12", expected: true}, |
92
|
|
|
{cardone: "30", cardtwo: "31", expected: false}, |
93
|
|
|
]; |
94
|
|
|
// var cardids = [ |
95
|
|
|
// {value: 0, expected: [-1, -1]}, |
96
|
|
|
// {value: 300, expected: [-1, -1]}, |
97
|
|
|
// {value: 1, expected: [0, 1]}, |
98
|
|
|
// {value: 2, expected: [2, 3]}, |
99
|
|
|
// {value: 3, expected: [4, 5]} |
100
|
|
|
// ]; |
101
|
|
|
|
102
|
|
|
values.forEach(function(test) { |
103
|
|
|
describe("Get memorycard value with position " + test.position, function() { |
104
|
|
|
it("should be value " + test.value, function () { |
105
|
|
|
checkMemorycardvalue(test.position, test.value); |
106
|
|
|
}); |
107
|
|
|
}); |
108
|
|
|
}); |
109
|
|
|
|
110
|
|
|
pairs.forEach(function(pair) { |
111
|
|
|
describe("Memorycard with position " + pair.cardone + " and " + pair.cardtwo, function() { |
112
|
|
|
it("should be a pair = " + pair.expected, function() { |
113
|
|
|
isPair(pair.cardone, pair.cardtwo, pair.expected); |
114
|
|
|
}); |
115
|
|
|
}); |
116
|
|
|
}); |
117
|
|
|
|
118
|
|
|
// cardids.forEach(function(cardid) { |
119
|
|
|
// describe("Memorycard with value " + cardid.value, function() { |
120
|
|
|
// it("should be have id pair = " + cardid.expected, function() { |
121
|
|
|
// checkCardId(cardid.value, cardid.expected); |
122
|
|
|
// }); |
123
|
|
|
// }); |
124
|
|
|
// }); |
125
|
|
|
|
126
|
|
|
describe("Unshuffled cardpositions", function() { |
127
|
|
|
it("should be default setting", function() { |
128
|
|
|
checkResetedPosition(); |
129
|
|
|
}); |
130
|
|
|
}); |
131
|
|
|
|
132
|
|
|
describe("Shuffled cardpositions", function() { |
133
|
|
|
it("should not be default setting", function() { |
134
|
|
|
checkShuffledPosition(); |
135
|
|
|
}); |
136
|
|
|
}); |
137
|
|
|
}); |
138
|
|
|
|