|
1 |
| -const expect = require('expect') |
2 |
| -const fs = require('fs') |
3 |
| -const jsdom = require('mocha-jsdom') |
4 |
| -const path = require('path') |
| 1 | +var a, b |
5 | 2 |
|
| 3 | +beforeEach(function() { |
| 4 | + a = Math.floor(Math.random() * 1000) |
| 5 | + b = Math.floor(Math.random() * 1000) |
| 6 | +}) |
6 | 7 |
|
7 |
| -describe('index', () => { |
8 |
| - jsdom({ |
9 |
| - src: fs.readFileSync(path.resolve(__dirname, '..', 'index.js'), 'utf-8') |
10 |
| - }) |
| 8 | +it('add(a, b) adds two numbers and returns the result', function() { |
| 9 | + expect(add(a, b)).toEqual(a + b) |
| 10 | +}) |
11 | 11 |
|
12 |
| - var a, b |
| 12 | +it('subtract(a, b) subtracts b from a and returns the result', function() { |
| 13 | + expect(subtract(a, b)).toEqual(a - b) |
| 14 | +}) |
13 | 15 |
|
14 |
| - beforeEach(() => { |
15 |
| - a = Math.floor(Math.random() * 1000) |
16 |
| - b = Math.floor(Math.random() * 1000) |
17 |
| - }) |
| 16 | +it('multiply(a, b) multiplies two numbers and returns the result', function() { |
| 17 | + expect(multiply(a, b)).toEqual(a * b) |
| 18 | +}) |
18 | 19 |
|
19 |
| - it('add(a, b) adds two numbers and returns the result', () => { |
20 |
| - expect(add(a, b)).toEqual(a + b) |
21 |
| - }) |
| 20 | +it('divide(a, b) divides a by b and returns the result', function() { |
| 21 | + expect(divide(a, b)).toEqual(a / b) |
| 22 | +}) |
22 | 23 |
|
23 |
| - it('subtract(a, b) subtracts b from a and returns the result', () => { |
24 |
| - expect(subtract(a, b)).toEqual(a - b) |
25 |
| - }) |
| 24 | +it('inc(n) increments n and returns the result', function() { |
| 25 | + expect(inc(a)).toEqual(a + 1) |
| 26 | +}) |
26 | 27 |
|
27 |
| - it('multiply(a, b) multiplies two numbers and returns the result', () => { |
28 |
| - expect(multiply(a, b)).toEqual(a * b) |
29 |
| - }) |
| 28 | +it('dec(n) decrements n and returns the result', function() { |
| 29 | + expect(dec(a)).toEqual(a - 1) |
| 30 | +}) |
30 | 31 |
|
31 |
| - it('divide(a, b) divides a by b and returns the result', () => { |
32 |
| - expect(divide(a, b)).toEqual(a / b) |
| 32 | +describe('makeInt(n)', function() { |
| 33 | + it('parses n as an integer and returns the parsed integer', function() { |
| 34 | + expect(makeInt(a.toString())).toEqual(a) |
33 | 35 | })
|
34 | 36 |
|
35 |
| - it('inc(n) increments n and returns the result', () => { |
36 |
| - expect(inc(a)).toEqual(a + 1) |
| 37 | + it('assumes base 10', function() { |
| 38 | + expect(makeInt('0x2328')).toEqual(0) |
37 | 39 | })
|
38 | 40 |
|
39 |
| - it('dec(n) decrements n and returns the result', () => { |
40 |
| - expect(dec(a)).toEqual(a - 1) |
| 41 | + it('returns NaN as appropriate', function() { |
| 42 | + expect(isNaN(makeInt('sldkjflksjf'))).toEqual(true) |
41 | 43 | })
|
| 44 | +}) |
42 | 45 |
|
43 |
| - describe('makeInt(n)', () => { |
44 |
| - it('parses n as an integer and returns the parsed integer', () => { |
45 |
| - expect(makeInt(a.toString())).toEqual(a) |
46 |
| - }) |
47 |
| - |
48 |
| - it('assumes base 10', () => { |
49 |
| - expect(makeInt('0x2328')).toEqual(0) |
50 |
| - }) |
51 |
| - |
52 |
| - it('returns NaN as appropriate', () => { |
53 |
| - expect(isNaN(makeInt('sldkjflksjf'))).toEqual(true) |
54 |
| - }) |
| 46 | +describe('preserveDecimal(n)', function() { |
| 47 | + it('preserves n\'s decimals (it parses n as a floating point number) and returns the parsed number', function() { |
| 48 | + expect(preserveDecimal('2.222')).toEqual(2.222) |
55 | 49 | })
|
56 | 50 |
|
57 |
| - describe('preserveDecimal(n)', () => { |
58 |
| - it('preserves n\'s decimals (it parses n as a floating point number) and returns the parsed number', () => { |
59 |
| - expect(preserveDecimal('2.222')).toEqual(2.222) |
60 |
| - }) |
61 |
| - |
62 |
| - it('returns NaN as appropriate', () => { |
63 |
| - expect(isNaN(preserveDecimal('sldkjflksjf'))).toEqual(true) |
64 |
| - }) |
| 51 | + it('returns NaN as appropriate', function() { |
| 52 | + expect(isNaN(preserveDecimal('sldkjflksjf'))).toEqual(true) |
65 | 53 | })
|
66 | 54 | })
|
0 commit comments