1
exercism fetch ecmascript say

say.spec.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import Say from './say';

describe('say', () => {
  const say = new Say();
  test('zero', () => {
    expect(say.inEnglish(0)).toBe('zero');
  });

  xtest('one', () => {
    expect(say.inEnglish(1)).toBe('one');
  });

  xtest('fourteen', () => {
    expect(say.inEnglish(14)).toBe('fourteen');
  });

  xtest('twenty', () => {
    expect(say.inEnglish(20)).toBe('twenty');
  });

  xtest('twenty-two', () => {
    expect(say.inEnglish(22)).toBe('twenty-two');
  });

  xtest('one hundred', () => {
    expect(say.inEnglish(100)).toBe('one hundred');
  });

  xtest('one hundred twenty-three', () => {
    expect(say.inEnglish(123)).toBe('one hundred twenty-three');
  });

  xtest('one thousand', () => {
    expect(say.inEnglish(1000)).toBe('one thousand');
  });

  xtest('one thousand two hundred thirty-four', () => {
    expect(say.inEnglish(1234)).toBe('one thousand two hundred thirty-four');
  });

  xtest('one million', () => {
    expect(say.inEnglish(1000000)).toBe('one million');
  });

  xtest('one million two', () => {
    expect(say.inEnglish(1000002)).toBe('one million two');
  });

  xtest('one million two thousand three hundred forty-five', () => {
    expect(say.inEnglish(1002345))
      .toBe('one million two thousand three hundred forty-five');
  });

  xtest('one billion', () => {
    expect(say.inEnglish(1000000000)).toBe('one billion');
  });

  xtest('a really big number', () => {
    let expected = 'nine hundred eighty-seven billion ';
    expected += 'six hundred fifty-four million ';
    expected += 'three hundred twenty-one thousand ';
    expected += 'one hundred twenty-three';
    expect(say.inEnglish(987654321123)).toBe(expected);
  });

  xtest('raises an error below zero', () => {
    expect(() => {
      say.inEnglish(-1);
    }).toThrow(new Error('Number must be between 0 and 999,999,999,999.'));
  });

  xtest('raises an error above 999,999,999,999', () => {
    expect(() => {
      say.inEnglish(1000000000000);
    }).toThrow(new Error('Number must be between 0 and 999,999,999,999.'));
  });
});