|
| 1 | +import * as area from './Area' |
| 2 | + |
| 3 | +describe('Testing surfaceAreaCube calculations', () => { |
| 4 | + it('with natural number', () => { |
| 5 | + const surfaceAreaOfOne = area.surfaceAreaCube(1.2) |
| 6 | + const surfaceAreaOfThree = area.surfaceAreaCube(3) |
| 7 | + expect(surfaceAreaOfOne).toBe(8.64) |
| 8 | + expect(surfaceAreaOfThree).toBe(54) |
| 9 | + }) |
| 10 | + it('with negative argument, expect throw', () => { |
| 11 | + expect(() => area.surfaceAreaCube(-1)).toThrow() |
| 12 | + }) |
| 13 | + it('with non-numeric argument, expect throw', () => { |
| 14 | + expect(() => area.surfaceAreaCube('199')).toThrow() |
| 15 | + }) |
| 16 | +}) |
| 17 | +describe('Testing surfaceAreaSphere calculations', () => { |
| 18 | + it('with correct value', () => { |
| 19 | + const calculateArea = area.surfaceAreaSphere(5) |
| 20 | + const expected = 314.1592653589793 |
| 21 | + expect(calculateArea).toBe(expected) |
| 22 | + }) |
| 23 | + it('with negative value, expect throw', () => { |
| 24 | + expect(() => area.surfaceAreaSphere(-1)).toThrow() |
| 25 | + }) |
| 26 | +}) |
| 27 | +describe('Testing areaRectangle calculations', () => { |
| 28 | + it('with correct args', () => { |
| 29 | + const areaRectangle = area.areaRectangle(2.5, 2) |
| 30 | + expect(areaRectangle).toBe(5.0) |
| 31 | + }) |
| 32 | + it('with incorrect args, expect throw', () => { |
| 33 | + expect(() => area.areaRectangle(-1, 20)).toThrow() |
| 34 | + expect(() => area.areaRectangle('1', 0)).toThrow() |
| 35 | + expect(() => area.areaRectangle(23, -1)).toThrow() |
| 36 | + expect(() => area.areaRectangle(23, 'zero')).toThrow() |
| 37 | + }) |
| 38 | +}) |
| 39 | +describe('Testing areaSquare calculations', () => { |
| 40 | + it('with correct args', () => { |
| 41 | + const areaSquare = area.areaSquare(2.5) |
| 42 | + expect(areaSquare).toBe(6.25) |
| 43 | + }) |
| 44 | + it('with incorrect side length, expect throw', () => { |
| 45 | + expect(() => area.areaSquare(-1)).toThrow() |
| 46 | + expect(() => area.areaSquare('zero')).toThrow() |
| 47 | + }) |
| 48 | +}) |
| 49 | +describe('Testing areaTriangle calculations', () => { |
| 50 | + it('with correct args', () => { |
| 51 | + const areaTriangle = area.areaTriangle(1.66, 3.44) |
| 52 | + expect(areaTriangle).toBe(2.8552) |
| 53 | + }) |
| 54 | + it('with incorrect base and height, expect throw', () => { |
| 55 | + expect(() => area.areaTriangle(-1, 1)).toThrow() |
| 56 | + expect(() => area.areaTriangle(9, 'zero')).toThrow() |
| 57 | + }) |
| 58 | +}) |
| 59 | +describe('Testing areaParallelogram calculations', () => { |
| 60 | + it('with correct args', () => { |
| 61 | + const areaParallelogram = area.areaParallelogram(1.66, 3.44) |
| 62 | + expect(areaParallelogram).toBe(5.7104) |
| 63 | + }) |
| 64 | + it('with incorrect base and height, expect throw', () => { |
| 65 | + expect(() => area.areaParallelogram(-1, 1)).toThrow() |
| 66 | + expect(() => area.areaParallelogram(9, 'zero')).toThrow() |
| 67 | + }) |
| 68 | +}) |
| 69 | +describe('Testing areaTrapezium calculations', () => { |
| 70 | + it('with correct args', () => { |
| 71 | + const areaTrapezium = area.areaTrapezium(1.66, 2.41, 4.1) |
| 72 | + expect(areaTrapezium).toBe(8.3435) |
| 73 | + }) |
| 74 | + it('with incorrect bases and height, expect throw', () => { |
| 75 | + expect(() => area.areaTrapezium(-1, 1, 0)).toThrow() |
| 76 | + expect(() => area.areaTrapezium(9, 'zero', 2)).toThrow() |
| 77 | + expect(() => area.areaTrapezium(9, 1, 'seven')).toThrow() |
| 78 | + }) |
| 79 | +}) |
| 80 | +describe('Testing areaCircle calculations', () => { |
| 81 | + it('with correct args', () => { |
| 82 | + const areaCircle = area.areaCircle(3.456) |
| 83 | + expect(areaCircle).toBe(37.52298159254666) |
| 84 | + }) |
| 85 | + it('with incorrect diagonal, expect throw', () => { |
| 86 | + expect(() => area.areaCircle(-1)).toThrow() |
| 87 | + expect(() => area.areaCircle('zero')).toThrow() |
| 88 | + }) |
| 89 | +}) |
| 90 | +describe('Testing areaRhombus calculations', () => { |
| 91 | + it('with correct args', () => { |
| 92 | + const areaRhombus = area.areaRhombus(2.5, 2.0) |
| 93 | + expect(areaRhombus).toBe(2.5) |
| 94 | + }) |
| 95 | + it('with incorrect diagonals, expect throw', () => { |
| 96 | + expect(() => area.areaRhombus(7, -1)).toThrow() |
| 97 | + expect(() => area.areaRhombus('zero', 2)).toThrow() |
| 98 | + }) |
| 99 | +}) |
0 commit comments