UNPKG

2.24 kBJavaScriptView Raw
1'use strict';
2var divisibleWithRemainder = require('../src/divisibleWithRemainder'),
3 assert = require('chai').assert;
4
5describe('divisibleWithRemainder', function() {
6 it('checks whether the divisor is a finite number', function() {
7 assert.throws(function() {
8 divisibleWithRemainder('0', 0);
9 }, TypeError, /is not a finite number/);
10 });
11
12 it('checks whether the divisor is not 0', function() {
13 assert.throws(function() {
14 divisibleWithRemainder(0, 0);
15 }, Error, /cannot be 0/);
16 });
17
18 it('checks whether the remainder is a finite number', function() {
19 assert.throws(function() {
20 divisibleWithRemainder(10, '1');
21 }, TypeError, /is not a finite number/);
22 });
23
24 it('throws an error when only 1 argument provided', function() {
25 assert.throws(function() {
26 divisibleWithRemainder(10);
27 }, Error, /missing remainder/i);
28 });
29
30 it('checks whether the remainder is smaller than the divisor', function() {
31 assert.throws(function() {
32 divisibleWithRemainder(10, 15);
33 }, Error, /Remainder cannot be greater than divisor/);
34
35 });
36
37 it('returns a function if only 2 arguments provided', function() {
38 assert.ok(divisibleWithRemainder(10, 5));
39 });
40
41 it('checks whether number is divisible by the given divisor with the given remainder', function() {
42 assert.ok(divisibleWithRemainder(10, 5, 5));
43 assert.ok(divisibleWithRemainder(10, 5)(5));
44 assert.ok(divisibleWithRemainder(2, 0, 2));
45 assert.ok(divisibleWithRemainder(2, 0)(2));
46
47 assert.ok(divisibleWithRemainder(10, 5, 4) === false);
48 assert.ok(divisibleWithRemainder(10, 5)(4) === false);
49 assert.ok(divisibleWithRemainder(2, 0, 1) === false);
50 assert.ok(divisibleWithRemainder(2, 0)(1) === false);
51 });
52
53 it('returns always false if a tested value is not a number', function() {
54 assert.ok(divisibleWithRemainder(10, 5, '5') === false);
55 assert.ok(divisibleWithRemainder(10, 5)('5') === false);
56 assert.ok(divisibleWithRemainder(10, 5, {}) === false);
57 assert.ok(divisibleWithRemainder(10, 5)({}) === false);
58 });
59});
\No newline at end of file