test/nim/nim.js   A
last analyzed

Complexity

Total Complexity 16
Complexity/F 1

Size

Lines of Code 124
Function Count 16

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 16
c 1
b 0
f 0
nc 1
mnd 0
bc 16
fnc 16
dl 0
loc 124
rs 10
bpm 1
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B nim.js ➔ describe(ꞌThis is test of nim-gameꞌ) 0 116 1
1
/**
2
 * Test the nim-game
3
 */
4
"use strict";
5
6
/* global describe it */
7
8
var assert = require("assert");
9
const Nim = require("../../src/nim/nim");
10
11
12
describe("This is test of nim-game", function() {
13
    describe("Test the constructor", function() {
14
        it("Num of piles should be 3", function() {
15
            let nim = new Nim();
16
            let piles = nim.piles;
17
18
            assert.equal(piles, 3);
19
        });
20
21
        it("The matches are 1,3,5 in piles", function() {
22
            let nim = new Nim();
23
            let matches = nim.matches;
24
25
            assert.equal(matches[0], 1);
26
            assert.equal(matches[1], 3);
27
            assert.equal(matches[2], 5);
28
            //assert.equal(matches[3], 7);
29
            //assert.equal(matches[4], 9);
30
        });
31
32
        it("Name of player one is Pelle", function() {
33
            let options = {nameOfPlayerOne: "Pelle"};
34
            let nim = new Nim(options);
35
            let name = nim.playerOne;
36
37
            assert.equal(name, "Pelle");
38
        });
39
40
        it("Player two is null", function() {
41
            let nim = new Nim();
42
            let name = nim.playerTwo;
43
44
            assert.equal(name, null);
45
        });
46
47
        it("Player in turn is Super Mario", function() {
48
            let options = {nameOfPlayerOne: "Super Mario"};
49
            let nim = new Nim(options);
50
            let inTurn = nim.playerInTurn;
51
52
            assert.equal(inTurn, "Super Mario");
53
        });
54
55
        it("Winner is null", function() {
56
            let nim = new Nim();
57
            let victory = nim.winner;
58
59
            assert.equal(victory, null);
60
        });
61
    });
62
63
    describe("Test the addPlayerTwo-function", function() {
64
        it("Player two name is Bamse", function() {
65
            let nim = new Nim();
66
67
            nim.addPlayerTwo("Bamse");
68
            let name = nim.playerTwo;
69
70
            assert.equal(name, "Bamse");
71
        });
72
    });
73
74
    describe("Test the changePlayer-function", function() {
75
        it("Changes player in turn", function() {
76
            let options = {nameOfPlayerOne: "Super Mario"};
77
            let nim = new Nim(options);
78
79
            nim.addPlayerTwo("Luigi");
80
            let inTurn = nim.playerInTurn;
81
82
            assert.equal(inTurn, "Super Mario");
83
            nim.changePlayer();
84
            inTurn = nim.playerInTurn;
85
            assert.equal(inTurn, "Luigi");
86
            nim.changePlayer();
87
            inTurn = nim.playerInTurn;
88
            assert.equal(inTurn, "Super Mario");
89
        });
90
    });
91
92
    describe("Test the removeMatches-function", function() {
93
        it("removes matches", function() {
94
            let nim = new Nim();
95
96
            let res = nim.removeMatches(3, 4);
97
            let matches = nim.matches[2];
98
99
            assert.equal(matches, 1);
100
            assert.equal(res, true);
101
102
            res = nim.removeMatches(2, 4);
103
            assert.equal(res, false);
104
105
            res = nim.removeMatches(6, 4);
106
            assert.equal(res, false);
107
        });
108
    });
109
110
    describe("Test the checkForWinner-function", function() {
111
        it("removes matches, check winner", function() {
112
            let nim = new Nim();
113
114
            nim.removeMatches(1, 1);
115
            let res = nim.checkForWinner();
116
117
            assert.equal(res, false);
118
            nim.removeMatches(2, 3);
119
            nim.removeMatches(3, 5);
120
121
            //nim.removeMatches(4, 7);
122
            //nim.removeMatches(5, 9);
123
            res = nim.checkForWinner();
124
            assert.equal(res, true);
125
        });
126
    });
127
});
128