|
1 | 1 | const _ = require('lodash');
|
2 |
| -const {it, describe} = require('mocha'); |
3 |
| -const {assert,expect} = require('chai') |
| 2 | +const { it, describe } = require('mocha'); |
| 3 | +const { assert, expect } = require('chai') |
4 | 4 |
|
5 |
| -const {potter,freq} = require('./index') |
| 5 | +const { potter, freq, removeZeros, calculateSetPrice, removeSet } = require('./index') |
6 | 6 |
|
7 | 7 | describe('the Potter discounts', () => {
|
8 | 8 | it('should return 0 if nothing given', () => {
|
9 | 9 | expect(potter()).to.equal(0);
|
10 | 10 | });
|
11 | 11 |
|
12 |
| - it('should return the appropriate discount for different books', () =>{ |
| 12 | + it('should return the appropriate discount for different books', () => { |
13 | 13 | expect(potter([0])).to.equal(8);
|
14 |
| - expect(potter([0,1])).to.equal(15.2); |
15 |
| - expect(potter([0,1,2])).to.equal(21.6); |
16 |
| - expect(potter([0,1,2,3])).to.equal(25.6); |
17 |
| - expect(potter([0,1,2,3,4])).to.equal(30) |
18 |
| - }) |
| 14 | + expect(potter([0, 1])).to.equal(15.2); |
| 15 | + expect(potter([0, 1, 2])).to.equal(21.6); |
| 16 | + expect(potter([0, 1, 2, 3])).to.equal(25.6); |
| 17 | + expect(potter([0, 1, 2, 3, 4])).to.equal(30) |
| 18 | + }); |
19 | 19 |
|
20 |
| - it('should not apply discount for two same books', |
21 |
| - ()=>{ |
22 |
| - expect(potter([0,0])).to.equal(16); |
23 |
| - }) |
| 20 | + it('should return the correct prices', () => { |
| 21 | + expect(potter([1, 2, 3, 1, 2, 3, 4, 3])).to.equal(55.2); |
| 22 | + expect(potter([2, 2, 2, 2, 2, 4, 3, 1, 1])).to.equal(64.8); |
| 23 | + expect(potter([0, 1, 2, 4, 2, 3, 2, 1, 0, 0])).to.equal(66.8); |
| 24 | + expect(potter([1, 1, 1, 1, 1, 1, 2])).to.equal(55.2); |
| 25 | + expect(potter([2, 3, 4, 0, 0, 1])).to.equal(38); |
| 26 | + }); |
| 27 | + |
| 28 | + // it('should throw an error if book number is invalid', () => { |
| 29 | + // expect(() => potter([1, 1, 1, 1, 1, 1, 6])).to.throw(); |
| 30 | + // }) |
| 31 | + |
| 32 | + it('should not apply discount for two same books', () => { |
| 33 | + expect(potter([0, 0])).to.equal(16); |
| 34 | + }) |
24 | 35 | })
|
25 | 36 | describe('the frequence function', () => {
|
26 |
| - it('should retunr the frequency function', () => { |
27 |
| - expect(freq([1,1,2,2])).to.deep.equal([0,2,2,0,0]) |
28 |
| -}); |
| 37 | + it('should retunr the frequency function', () => { |
| 38 | + expect(freq([1, 1, 2, 2])).to.deep.equal([0, 2, 2, 0, 0]) |
| 39 | + }); |
29 | 40 | });
|
30 | 41 |
|
| 42 | +describe('removing zeros from frequency array', () => { |
| 43 | + it('should remove zeros from the array', () => { |
| 44 | + expect(removeZeros([0, 0, 1, 2, 1])).to.deep.equal([1, 2, 1]) |
| 45 | + }) |
| 46 | +}) |
| 47 | + |
| 48 | +describe('return the price of the set', () => { |
| 49 | + it('should calculate the price including correct discount', () => { |
| 50 | + expect(calculateSetPrice(1)).to.equal(8); |
| 51 | + expect(calculateSetPrice(2)).to.equal(15.2); |
| 52 | + expect(calculateSetPrice(3)).to.equal(21.6); |
| 53 | + expect(calculateSetPrice(4)).to.equal(25.6); |
| 54 | + expect(calculateSetPrice(5)).to.equal(30) |
| 55 | + }) |
| 56 | +}) |
| 57 | + |
| 58 | +describe('removing the calculated set from the frequency array', () => { |
| 59 | + it('should remove 1 from each element of the array', () => { |
| 60 | + expect(removeSet([1, 2, 1])).to.deep.equal([0, 1, 0]) |
| 61 | + }) |
| 62 | +}) |
| 63 | + |
31 | 64 |
|
0 commit comments