Skip to content

Commit ab761ec

Browse files
authored
Added Volume.test.js file
Volume.test.js file is to test on the calculations for the Volume.js file.
1 parent f2aad7b commit ab761ec

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

Maths/test/Volume.test.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import * as volume from '../Volume'
2+
3+
test('Testing on volCuboid', () => {
4+
it('with correct args', () => {
5+
const volCuboid = volume.volCuboid(2.0, 5.0, 3)
6+
expect(volCuboid).toBe(30.0)
7+
})
8+
it('with incorrect args', () => {
9+
expect(() => volume.volCuboid(-1, 5.0, 3)).toThrow()
10+
expect(() => volume.volCuboid(2.0, -1, 3)).toThrow()
11+
expect(() => volume.volCuboid(2.0, 5.0, -1)).toThrow()
12+
expect(() => volume.volCuboid('2.0', 5.0, 3)).toThrow()
13+
expect(() => volume.volCuboid(2.0, '5.0', 3)).toThrow()
14+
expect(() => volume.volCuboid(2.0, 5.0, '3')).toThrow()
15+
expect(() => volume.volCuboid(2000000000000000, 5.0, 3)).toThrow()
16+
expect(() => volume.volCuboid(2.0, 500000000000000000, 3)).toThrow()
17+
expect(() => volume.volCuboid(2.0, 5.0, 30000000000000000000)).toThrow()
18+
})
19+
})
20+
21+
test('Testing on volCube', () => {
22+
it('with correct args', () => {
23+
const volCube = volume.volCube(2.0)
24+
expect(volCube).toBe(8.0)
25+
})
26+
it('with incorrect args', () => {
27+
expect(() => volume.volCube(-2.0)).toThrow()
28+
expect(() => volume.volCube('2.0')).toThrow()
29+
expect(() => volume.volCube(2000000000000000000000000)).toThrow()
30+
})
31+
})
32+
33+
test('Testing on volCone', () => {
34+
it('with correct args', () => {
35+
const volCone = volume.volCone(2.0, 8.0)
36+
expect(volCone).toBe(33.5103)
37+
})
38+
it('with incorrect args', () => {
39+
expect(() => volume.volCone(-2.0, 8.0)).toThrow()
40+
expect(() => volume.volCone(2.0, -8.0)).toThrow()
41+
expect(() => volume.volCone('2.0', 8.0)).toThrow()
42+
expect(() => volume.volCone(2.0, '8.0')).toThrow()
43+
expect(() => volume.volCone(2000000000000000000000000, 8.0)).toThrow()
44+
expect(() => volume.volCone(2.0, 8000000000000000000000000000)).toThrow()
45+
})
46+
})
47+
48+
test('Testing on volPyramid', () => {
49+
it('with correct args', () => {
50+
const volPyramid = volume.volPyramid(2.0, 3.0, 8.0)
51+
expect(volPyramid).toBe(16.0)
52+
})
53+
it('with incorrect args', () => {
54+
expect(() => volume.volPyramid(-2.0, 3.0, 8.0)).toThrow()
55+
expect(() => volume.volPyramid(2.0, -3.0, 8.0)).toThrow()
56+
expect(() => volume.volPyramid(2.0, 3.0, -8.0)).toThrow()
57+
expect(() => volume.volPyramid('2.0', 3.0, 8.0)).toThrow()
58+
expect(() => volume.volPyramid(2.0, '3.0', 8.0)).toThrow()
59+
expect(() => volume.volPyramid(2.0, 3.0, '8.0')).toThrow()
60+
expect(() => volume.volPyramid(2000000000000000000000000, 3.0, 8.0)).toThrow()
61+
expect(() => volume.volPyramid(2.0, 3000000000000000000000000000, 8.0)).toThrow()
62+
expect(() => volume.volPyramid(2.0, 3.0, 8000000000000000000000000000)).toThrow()
63+
})
64+
})
65+
66+
test('Testing on volCylinder', () => {
67+
it('with correct args', () => {
68+
const volCylinder = volume.volCylinder(2.0, 8.0)
69+
expect(volCylinder).toBe(100.5310)
70+
})
71+
it('with incorrect args', () => {
72+
expect(() => volume.volCylinder(-2.0, 8.0)).toThrow()
73+
expect(() => volume.volCylinder(2.0, -8.0)).toThrow()
74+
expect(() => volume.volCylinder('2.0', 8.0)).toThrow()
75+
expect(() => volume.volCylinder(2.0, '8.0')).toThrow()
76+
expect(() => volume.volCylinder(2000000000000000000000000, 8.0)).toThrow()
77+
expect(() => volume.volCylinder(2.0, 8000000000000000000000000000)).toThrow()
78+
})
79+
})
80+
81+
test('Testing on volTriangularPrism', () => {
82+
it('with correct args', () => {
83+
const volTriangularPrism = volume.volTriangularPrism(3.0, 6.0, 8.0)
84+
expect(volTriangularPrism).toBe(72.0)
85+
})
86+
it('with incorrect args', () => {
87+
expect(() => volume.volTriangularPrism(-3.0, 6.0, 8.0)).toThrow()
88+
expect(() => volume.volTriangularPrism(3.0, -6.0, 8.0)).toThrow()
89+
expect(() => volume.volTriangularPrism(3.0, 6.0, -8.0)).toThrow()
90+
expect(() => volume.volTriangularPrism('3.0', 6.0, 8.0)).toThrow()
91+
expect(() => volume.volTriangularPrism(3.0, '6.0', 8.0)).toThrow()
92+
expect(() => volume.volTriangularPrism(3.0, 6.0, '8.0')).toThrow()
93+
expect(() => volume.volTriangularPrism(3000000000000000000000000, 6.0, 8.0)).toThrow()
94+
expect(() => volume.volTriangularPrism(3.0, 6000000000000000000000000000, 8.0)).toThrow()
95+
expect(() => volume.volTriangularPrism(3.0, 6.0, 8000000000000000000000000000)).toThrow()
96+
})
97+
})
98+
99+
test('Testing on volPentagonalPrism', () => {
100+
it('with correct args', () => {
101+
const volPentagonalPrism = volume.volPentagonalPrism(1.0, 4.0, 8.0)
102+
expect(volPentagonalPrism).toBe(80.0)
103+
})
104+
it('with incorrect args', () => {
105+
expect(() => volume.volPentagonalPrism(-1.0, 4.0, 8.0)).toThrow()
106+
expect(() => volume.volPentagonalPrism(1.0, -4.0, 8.0)).toThrow()
107+
expect(() => volume.volPentagonalPrism(1.0, 4.0, -8.0)).toThrow()
108+
expect(() => volume.volPentagonalPrism('1.0', 4.0, 8.0)).toThrow()
109+
expect(() => volume.volPentagonalPrism(1.0, '4.0', 8.0)).toThrow()
110+
expect(() => volume.volPentagonalPrism(1.0, 4.0, '8.0')).toThrow()
111+
expect(() => volume.volPentagonalPrism(1000000000000000000000000, 4.0, 8.0)).toThrow()
112+
expect(() => volume.volPentagonalPrism(1.0, 4000000000000000000000000000, 8.0)).toThrow()
113+
expect(() => volume.volPentagonalPrism(1.0, 4.0, 8000000000000000000000000000)).toThrow()
114+
})
115+
})
116+
117+
test('Testing on volSphere', () => {
118+
it('with correct args', () => {
119+
const volSphere = volume.volSphere(4.0)
120+
expect(volSphere).toBe(268.0826)
121+
})
122+
it('with incorrect args', () => {
123+
expect(() => volume.volSphere(-4.0)).toThrow()
124+
expect(() => volume.volSphere('4.0')).toThrow()
125+
expect(() => volume.volSphere(4000000000000000000000000)).toThrow()
126+
})
127+
})
128+
129+
test('Testing on volHemisphere', () => {
130+
it('with correct args', () => {
131+
const volHemisphere = volume.volHemisphere(4.0)
132+
expect(volHemisphere).toBe(134.0413)
133+
})
134+
it('with incorrect args', () => {
135+
expect(() => volume.volHemisphere(-4.0)).toThrow()
136+
expect(() => volume.volHemisphere('4.0')).toThrow()
137+
expect(() => volume.volHemisphere(4000000000000000000000000)).toThrow()
138+
})
139+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy