Ver a proveniência

Add tests using Mocha+Chai

tags/v0.1.3
bertieb há 3 anos
ascendente
cometimento
14f32e812f
1 ficheiros alterados com 97 adições e 0 eliminações
  1. +97
    -0
      test/test-dice.spec.ts

+ 97
- 0
test/test-dice.spec.ts Ver ficheiro

@@ -0,0 +1,97 @@
import { Asphodice } from "../dice";
import { expect } from 'chai';
import 'mocha';

let asphodice = new Asphodice;

const testCandidates = [
{ dice: [ 6, 6, 6 ], aboveCutOff: true, belowCutOff: false,
reroll: false, cancelled: [6,6,6] },
{ dice: [ 2, 2, 2 ], aboveCutOff: false, belowCutOff: true,
reroll: false, cacncelled: [2,2,2] },
{ dice: [ 1 ], aboveCutOff: false, belowCutOff: true,
reroll: true, cacncelled: [1] },
];



describe("allAboveCutOff() says are all above cutoff correctly", function() {
const tests = [
{ dice: [ 6, 6, 6 ], expected: true },
{ dice: [ 2, 2, 2 ], expected: false },
{ dice: [ 1 ], expected: false },
{ dice: [ 10 ], expected: true },
{ dice: [ 6, 10, 6, 9 ], expected: true}
];

tests.forEach(({dice, expected}) => {
it(`correctly determines ${dice} are above cutoff`, function () {
const result = asphodice.allAboveCutOff(dice);
expect(result).to.equal(expected);
});
});
testCandidates.forEach( ({dice, aboveCutOff}) => {
it(`allAboveCutOff() says ${dice} → ${aboveCutOff}`, function() {
const result = asphodice.allAboveCutOff(dice);
expect(result).to.equal(aboveCutOff);
});

});
});

describe("Are all below cutoff?", function() {
const tests = [
{ dice: [ 6, 6, 6 ], expected: false },
{ dice: [ 2, 2, 2 ], expected: true },
{ dice: [ 1 ], expected: true },
{ dice: [ 10 ], expected: false },
{ dice: [ 6, 10, 6, 9 ], expected: false },
{ dice: [ 6, 1, 6, 9 ], expected: false }
];

tests.forEach(({dice, expected}) => {
it(`correctly determines ${dice} are above cutoff`, function () {
const result = asphodice.allBelowCutOff(dice);
expect(result).to.equal(expected);
});
});
});

// TODO: single dice behaviour
describe("Does it need a re-roll?", function() {
const tests = [
{ dice: [ 6, 6, 6 ], expected: false },
{ dice: [ 2, 2, 2 ], expected: false },
{ dice: [ 6, 10, 6, 9 ], expected: false },
{ dice: [ 6, 1, 6, 9 ], expected: true },
{ dice: [ 10, 1, 2], expected: false },
{ dice: [ 10, 10, 1, 1, 1, 6], expected: true },
{ dice: [ 10, 10, 1, 1, 1, 2], expected: false },
];

tests.forEach(({dice, expected}) => {
it(`correctly determines ${dice} needs a re-roll`, function () {
const result = asphodice.rerollNeeded(dice);
expect(result).to.equal(expected);
});
});
});

describe("cancelRerollDice() filters correctly", function() {
const tests = [
{ dice: [ 6, 6, 6 ], out: [6,6,6] },
{ dice: [ 2, 2, 2 ], out: [2,2,2] },
{ dice: [ 6, 10, 6, 9 ], out: [6, 10, 6, 9] },
{ dice: [ 6, 1, 6, 9 ], out: [ 6, 1, 6, 9 ] },
{ dice: [ 10, 1, 2], out: [2] },
{ dice: [ 10, 10, 1, 1, 1, 6], out: [1,6] },
{ dice: [ 10, 10, 1, 1, 1, 2], out: [1,2] },
];

tests.forEach(({dice, out}) => {
it(`correctly filters ${dice} to ${out}`, function () {
const result = asphodice.cancelRerollDice(dice);
expect(result.sort()).to.deep.equal(out.sort());
});
});
});

Carregando…
Cancelar
Guardar