1
exercism fetch ecmascript isbn-verifier

isbn-verifier.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
78
79
80
81
import ISBN from './isbn-verifier.js';

describe('ISBN Verifier Test Suite', () => {
  test('valid isbn number', () => {
    const isbn = new ISBN('3-598-21508-8');

    expect(isbn.isValid()).toEqual(true);
  });

  test('invalid isbn check digit', () => {
    const isbn = new ISBN('3-598-21508-9');

    expect(isbn.isValid()).toEqual(false);
  });

  xtest('valid isbn number with a check digit of 10', () => {
    const isbn = new ISBN('3-598-21507-X');

    expect(isbn.isValid()).toEqual(true);
  });

  xtest('check digit is a character other than X', () => {
    const isbn = new ISBN('3-598-21507-A');

    expect(isbn.isValid()).toEqual(false);
  });

  xtest('invalid character in isbn', () => {
    const isbn = new ISBN('3-598-2K507-0');

    expect(isbn.isValid()).toEqual(false);
  });

  xtest('X is only valid as a check digit', () => {
    const isbn = new ISBN('3-598-2X507-0');

    expect(isbn.isValid()).toEqual(false);
  });

  xtest('valid isbn without separating dashes', () => {
    const isbn = new ISBN('3598215088');

    expect(isbn.isValid()).toEqual(true);
  });

  xtest('isbn without separating dashes and X as check digit', () => {
    const isbn = new ISBN('359821507X');

    expect(isbn.isValid()).toEqual(true);
  });

  xtest('isbn without check digit and dashes', () => {
    const isbn = new ISBN('359821507');

    expect(isbn.isValid()).toEqual(false);
  });

  xtest('too long isbn and no dashes', () => {
    const isbn = new ISBN('3598215078X');

    expect(isbn.isValid()).toEqual(false);
  });

  xtest('isbn without check digit', () => {
    const isbn = new ISBN('3-598-21507');

    expect(isbn.isValid()).toEqual(false);
  });

  xtest('too long isbn', () => {
    const isbn = new ISBN('3-598-21507-XA');

    expect(isbn.isValid()).toEqual(false);
  });

  xtest('check digit of X should not be used for 0', () => {
    const isbn = new ISBN('3-598-21515-X');

    expect(isbn.isValid()).toEqual(false);
  });
});