1
|
|
|
/** |
2
|
|
|
* Test for class Card, parameterized version of testsuite. |
3
|
|
|
*/ |
4
|
|
|
"use strict"; |
5
|
|
|
|
6
|
|
|
/* global describe it */ |
7
|
|
|
|
8
|
|
|
var assert = require("assert"); |
9
|
|
|
const Card = require("../../src/card/card"); |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Check a card with its expected card face. |
15
|
|
|
*/ |
16
|
|
|
function checkCard(id, expected) { |
17
|
|
|
let card = new Card(); |
18
|
|
|
let res = card.getCard(id); |
19
|
|
|
|
20
|
|
|
assert.equal(res, expected); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Check the card rank. |
27
|
|
|
*/ |
28
|
|
|
function checkRank(id, expected) { |
29
|
|
|
let card = new Card(); |
30
|
|
|
let res = card.getRank(id); |
31
|
|
|
|
32
|
|
|
assert.equal(res, expected); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Testsuite |
39
|
|
|
*/ |
40
|
|
|
describe("Check card ranks", function() { |
41
|
|
|
var tests = [ |
42
|
|
|
{id: 0, face: "♣A", rank: 14}, |
43
|
|
|
{id: 1, face: "♣2", rank: 2}, |
44
|
|
|
{id: 13, face: "♦A", rank: 14}, |
45
|
|
|
{id: 26, face: "♠A", rank: 14}, |
46
|
|
|
{id: 39, face: "♥A", rank: 14}, |
47
|
|
|
{id: 51, face: "♥K", rank: 13}, |
48
|
|
|
{id: 52, face: undefined, rank: undefined}, |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
tests.forEach(function(test) { |
52
|
|
|
describe("Get card with value " + test.id, function() { |
53
|
|
|
it("should be card " + test.face, function () { |
54
|
|
|
checkCard(test.id, test.face); |
55
|
|
|
}); |
56
|
|
|
it("should have rank " + test.rank, function () { |
57
|
|
|
checkRank(test.id, test.rank); |
58
|
|
|
}); |
59
|
|
|
}); |
60
|
|
|
}); |
61
|
|
|
}); |
62
|
|
|
|