|
| 1 | +const Measurement = require('../Measurement'); |
| 2 | +const Unit = require('../Unit'); |
| 3 | +const multiply = require('./multiply'); |
| 4 | + |
| 5 | +describe(multiply, () => { |
| 6 | + it('throws if a Measurement is not supplied', () => { |
| 7 | + expect(() => multiply(2, 3)).toThrowError( |
| 8 | + new TypeError('Expected a Measurement but got none') |
| 9 | + ); |
| 10 | + }); |
| 11 | + |
| 12 | + it('throws if more than one Measurement is supplied', () => { |
| 13 | + const foot = new Unit('foot'); |
| 14 | + expect(() => |
| 15 | + multiply(new Measurement(2, foot), new Measurement(3, foot)) |
| 16 | + ).toThrowError(new TypeError('Cannot multiply more than one Measurement')); |
| 17 | + }); |
| 18 | + |
| 19 | + it('throws if just a single value is provided', () => { |
| 20 | + const foot = new Unit('foot'); |
| 21 | + expect(() => multiply(new Measurement(2, foot))).toThrowError( |
| 22 | + new TypeError('Cannot multiply a Measurement with nothing') |
| 23 | + ); |
| 24 | + }); |
| 25 | + |
| 26 | + it('multiplies a Measurement and a number', () => { |
| 27 | + const foot = new Unit('foot'); |
| 28 | + expect(multiply(new Measurement(2, foot), 3)).toEqual( |
| 29 | + new Measurement(6, foot) |
| 30 | + ); |
| 31 | + expect(multiply(5, new Measurement(4, foot))).toEqual( |
| 32 | + new Measurement(20, foot) |
| 33 | + ); |
| 34 | + }); |
| 35 | + |
| 36 | + it('multiplies a Measurement and multiple numbers', () => { |
| 37 | + const foot = new Unit('foot'); |
| 38 | + const values = [4, 5, new Measurement(2, foot), 3]; |
| 39 | + expect(multiply(...values)).toEqual(new Measurement(120, foot)); |
| 40 | + }); |
| 41 | +}); |
0 commit comments