1
exercism fetch javascript 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
var ISBN = require('./isbn-verifier');

describe('ISBN', function () {
  it('valid isbn number', function () {
    var isbn = new ISBN('3-598-21508-8');
    expect(isbn.isValid()).toBe(true);
  });

  it('invalid isbn check digit', function () {
    var isbn = new ISBN('3-598-21508-9');
    expect(isbn.isValid()).toBe(false);
  });

  it('valid isbn number with a check digit of 10', function () {
    var isbn = new ISBN('3-598-21507-X');
    expect(isbn.isValid()).toBe(true);
  });

  it('check digit is a character other than X', function () {
    var isbn = new ISBN('3-598-21507-A');
    expect(isbn.isValid()).toBe(false);
  });

  it('invalid character in isbn', function () {
    var isbn = new ISBN('3-598-2K507-0');
    expect(isbn.isValid()).toBe(false);
  });

  it('X is only valid as a check digit', function () {
    var isbn = new ISBN('3-598-2X507-0');
    expect(isbn.isValid()).toBe(false);
  });

  it('valid isbn without separating dashes', function () {
    var isbn = new ISBN('3598215088');
    expect(isbn.isValid()).toBe(true);
  });

  it('isbn without separating dashes and X as check digit', function () {
    var isbn = new ISBN('359821507X');
    expect(isbn.isValid()).toBe(true);
  });

  it('isbn without check digit and dashes', function () {
    var isbn = new ISBN('359821507');
    expect(isbn.isValid()).toBe(false);
  });

  it('too long isbn and no dashes', function () {
    var isbn = new ISBN('3598215078X');
    expect(isbn.isValid()).toBe(false);
  });

  it('isbn without check digit', function () {
    var isbn = new ISBN('3-598-21507');
    expect(isbn.isValid()).toBe(false);
  });

  it('too long isbn', function () {
    var isbn = new ISBN('3-598-21507-XA');
    expect(isbn.isValid()).toBe(false);
  });

  it('check digit of X should not be used for 0', function () {
    var isbn = new ISBN('3-598-21515-X');
    expect(isbn.isValid()).toBe(false);
  });
});