dice-utils.spec.ts 851 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { isConsecutives, sumOfSelectedValue, toDiceMap } from './dice-utils';

describe('Sum of selected value in array', () => {
  it('should give the sum of a selected value in an array', () => {
    expect(sumOfSelectedValue([1, 1, 2, 20, 5, 4, 1], 1)).toBe(3);
    expect(sumOfSelectedValue([1, 1, 2, 20, 5, 4, 1], 9)).toBe(0)
  });
});

describe('Convert dice array to map', () => {
  it('should return a map with the dice face as key and his number of occurences as value', () => {
    expect(toDiceMap([1, 1, 1, 2, 2, 3])).toStrictEqual({'1': 3, '2': 2, '3':1});
  });
});

describe('Check if array contains only consecutives values', () => {
  it('should return true', () => {
    expect(isConsecutives([2, 1, 5, 4, 3])).toBe(true);
  });
  it('should return false', () => {
    expect(isConsecutives([2, 1, 5, 3, 7, 8])).toBe(false);
  })
});