test/cardDeck/cardDeck.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 1.13

Size

Lines of Code 75
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 2
dl 0
loc 75
rs 10
wmc 9
mnd 1
bc 9
fnc 8
bpm 1.125
cpm 1.125
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A cardDeck.js ➔ compareInteger 0 3 1
A cardDeck.js ➔ describe(ꞌCheck CardDeckꞌ) 0 54 1
1
/**
2
* Test for class CardDeck.
3
 */
4
"use strict";
5
6
/* global describe it */
7
8
const assert = require("assert");
9
const CardDeck = require("../../src/cardDeck/cardDeck");
10
11
12
13
/**
14
 * Compare two integers.
15
 */
16
function compareInteger(a, b) {
17
    return a - b;
18
}
19
20
21
22
/**
23
 * Testsuite
24
 */
25
describe("Check CardDeck", function() {
26
    describe("use default card deck", function() {
27
        it("should be 104 cards", function() {
28
            let deck = new CardDeck();
29
            let numberOfCards = deck.getNumberOfCards();
30
31
            assert.equal(numberOfCards, 104);
32
        });
33
34
        it("id should be between 0 and 103", function() {
35
            let deck = new CardDeck();
36
            let cards = deck.showAllCardsById();
37
38
            assert.equal(cards.length, 104);
39
            assert.equal(cards[0], 0);
40
            assert.equal(cards[51], 51);
41
            assert.equal(cards[52], 0);
42
            assert.equal(cards[103], 51);
43
        });
44
45
        it("shuffle it", function() {
46
            let deck = new CardDeck();
47
            let numberOfCards;
48
49
            deck.shuffle();
50
            numberOfCards = deck.getNumberOfCards();
51
52
            assert.equal(numberOfCards, 104);
53
        });
54
55
        it("get all cards, one by one", function() {
56
            let deck = new CardDeck();
57
            let allCards = deck.showAllCardsById();
58
            let cardId;
59
            let shuffledCards = [];
60
            let equal;
61
62
            deck.shuffle();
63
            while ((cardId = deck.getCard()) !== undefined) {
64
                shuffledCards.push(cardId);
65
            }
66
67
            allCards.sort(compareInteger);
68
            shuffledCards.sort(compareInteger);
69
70
            equal = shuffledCards.length == allCards.length &&
71
                shuffledCards.every((element, index) => {
72
                    return element === allCards[index];
73
                });
74
75
            assert.equal(equal, true);
76
        });
77
    });
78
});
79