From 87b28f6c6e73fe7ee9f397dd4a8e0764e5731741 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Tue, 6 Oct 2020 13:56:39 +0000 Subject: [PATCH 1/9] chore: add area and area test --- Maths/Area.js | 99 ++++++++++++++++++++++++++++++++++++++ Maths/test/Area.test.js | 103 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 Maths/Area.js create mode 100644 Maths/test/Area.test.js diff --git a/Maths/Area.js b/Maths/Area.js new file mode 100644 index 0000000000..a598aaef51 --- /dev/null +++ b/Maths/Area.js @@ -0,0 +1,99 @@ +/** + * Author: dephraiim + * License: GPL-3.0 or later + * + * More on Area: + * https://en.wikipedia.org/wiki/Area + * + */ + +const areaSquare = (length) => { + if (length < 0) + throw new Error('areaSquare() does not accept negative values') + + return length ** 2 +} + +const areaRectangle = (length, width) => { + if (length < 0 || width < 0) + throw new Error('areaRectangle() does not accept negative values') + return length * width +} + +const areaTriangle = (base, height) => { + if (base < 0 || height < 0) + throw new Error('areaTriangle() does not accept negative values') + return (base * height) / 2 +} + +const areaParallelogram = (base, height) => { + if (base < 0 || height < 0) + throw new Error('areaParallelogram() does not accept negative values') + + return base * height +} + +const areaTrapezium = (base1, base2, height) => { + if (base1 < 0 || base2 < 0 || height < 0) + throw new Error('areaTrapezium() does not accept negative values') + + return (1 / 2) * (base1 + base2) * height +} + +const areaRhombus = (diagonal1, diagonal2) => { + if (diagonal1 < 0 || diagonal2 < 0) + throw new Error('areaRhombus() does not accept negative values') + + return (1 / 2) * diagonal1 * diagonal2 +} + +const areaCircle = (radius) => { + if (radius < 0) + throw new Error('areaCircle() does not accept negative values') + + return Math.PI * radius ** 2 +} + +const surfaceAreaSphere = (radius) => { + if (radius < 0) + throw new Error('surfaceAreaSphere() does not accept negative values') + + return 4 * Math.PI * radius ** 2 +} + +const surfaceAreaCube = (length) => { + if (length < 0) + throw new Error('surfaceAreaCube() does not accept negative values') + + return 6 * length ** 2 +} + +const surfaceAreaCylinder = (radius, height) => { + if (height < 0 || radius < 0) + throw new Error('surfaceAreaCylinder() does not accept negative values') + + return 2 * Math.PI * radius * (height + radius) // 2πr(h+r) +} + +const curvedSurfaceAreaCylinder = (radius, height) => { + if (height < 0 || radius < 0) + throw new Error( + 'curvedSurfaceAreaCylinder() does not accept negative values' + ) + + return 2 * Math.PI * radius * height +} + +export { + areaCircle, + areaTriangle, + areaTrapezium, + areaSquare, + areaRhombus, + areaRectangle, + areaParallelogram, + surfaceAreaCube, + surfaceAreaSphere, + surfaceAreaCylinder, + curvedSurfaceAreaCylinder +} diff --git a/Maths/test/Area.test.js b/Maths/test/Area.test.js new file mode 100644 index 0000000000..91ac816328 --- /dev/null +++ b/Maths/test/Area.test.js @@ -0,0 +1,103 @@ +import { + areaCircle, + areaTriangle, + areaTrapezium, + areaSquare, + areaRhombus, + areaRectangle, + areaParallelogram, + surfaceAreaCube, + surfaceAreaSphere, + surfaceAreaCylinder, + curvedSurfaceAreaCylinder +} from '../Area' + +describe('Area', () => { + it('should return the area of a circle', () => { + expect(Math.round(areaCircle(10))).toBe(314) + }) + + it('should throw an error when given negative values', () => { + expect(() => areaCircle(-10)).toThrow() + }) + + it('should return the area of a parallelogram', () => { + expect(areaParallelogram(10, 20)).toBe(200) + }) + + it('should throw an error when given negative values', () => { + expect(() => areaParallelogram(-10, -21)).toThrow() + }) + + it('should return the area of a rectangle', () => { + expect(areaRectangle(10, 20)).toBe(200) + }) + + it('should throw an error when given negative values', () => { + expect(() => areaRectangle(-2, -3)).toThrow() + }) + + it('should return the area of a rhombus', () => { + expect(areaRhombus(10, 10)).toBe(50) + }) + + it('should throw an error when given negative values', () => { + expect(() => areaRhombus(-2, -4)).toThrow() + }) + + it('should return the area of a square', () => { + expect(areaSquare(2)).toBe(4) + }) + + it('should throw an error when given negative values', () => { + expect(() => areaSquare(-2)).toThrow() + }) + + it('should return the area of a trapezium', () => { + expect(areaTrapezium(2, 3, 4)).toBe(10) + }) + + it('should throw an error when given negative values', () => { + expect(() => areaTrapezium(-2, -3, -4)).toThrow() + }) + + it('should return the area of a triangle', () => { + expect(areaTriangle(5, 10)).toBe(25) + }) + + it('should throw an error when given negative values', () => { + expect(() => areaTriangle(-2, -4)).toThrow() + }) + + it('should return the surface area of a cube', () => { + expect(surfaceAreaCube(2)).toBe(24) + }) + + it('should throw an error when given negative values', () => { + expect(() => surfaceAreaCube(-2)).toThrow() + }) + + it('should return the surface area of a cylinder', () => { + expect(Math.round(surfaceAreaCylinder(10, 20))).toBe(1885) + }) + + it('should throw an error when given negative values', () => { + expect(() => surfaceAreaCylinder(-2)).toThrow() + }) + + it('should return the surface area of a sphere', () => { + expect(Math.round(surfaceAreaSphere(2))).toBe(50) + }) + + it('should throw an error when given negative values', () => { + expect(() => surfaceAreaSphere(-2)).toThrow() + }) + + it('should return the curved surface area of a cylinder', () => { + expect(Math.round(curvedSurfaceAreaCylinder(5, 10))).toBe(314) + }) + + it('should throw an error when given negative values', () => { + expect(() => curvedSurfaceAreaCylinder(-2)).toThrow() + }) +}) From a93a96c711173cea7661e8e661ab1e9f37f09025 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Tue, 6 Oct 2020 14:25:24 +0000 Subject: [PATCH 2/9] chore: add armstrong number --- Maths/ArmstrongNumber.js | 24 ++++++++++++++++++++++++ Maths/test/ArmstrongNumber.test.js | 14 ++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Maths/ArmstrongNumber.js create mode 100644 Maths/test/ArmstrongNumber.test.js diff --git a/Maths/ArmstrongNumber.js b/Maths/ArmstrongNumber.js new file mode 100644 index 0000000000..71f448a7fb --- /dev/null +++ b/Maths/ArmstrongNumber.js @@ -0,0 +1,24 @@ +/** + * Author: dephraiim + * License: GPL-3.0 or later + * + * An Armstrong number is equal to the sum of the cubes of its digits. + * For example, 370 is an Armstrong number because 3*3*3 + 7*7*7 + 0*0*0 = 370. + * An Armstrong number is often called Narcissistic number. + * + */ + +const armstrongNumber = (num) => { + if (num < 0 || typeof num !== 'number') return false + + let newSum = 0 + + const numArr = num.toString().split('') + numArr.forEach((num) => { + newSum += parseInt(num) ** numArr.length + }) + + return newSum === num +} + +export { armstrongNumber } diff --git a/Maths/test/ArmstrongNumber.test.js b/Maths/test/ArmstrongNumber.test.js new file mode 100644 index 0000000000..01da1631da --- /dev/null +++ b/Maths/test/ArmstrongNumber.test.js @@ -0,0 +1,14 @@ +import { armstrongNumber } from '../ArmstrongNumber' + +describe('ArmstrongNumber', () => { + it('should return true for an armstrong number', () => { + expect(armstrongNumber(371)).toBeTruthy() + }) + + it('should return false for a non-armstrong number', () => { + expect(armstrongNumber(300)).toBeFalsy() + }) + it('should return false for negative values', () => { + expect(armstrongNumber(-2)).toBeFalsy() + }) +}) From 3e6e72307dd036ecaafe2e99457fe54fd7ef380f Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Tue, 6 Oct 2020 15:03:04 +0000 Subject: [PATCH 3/9] chore: add factors --- Maths/Factors.js | 16 ++++++++++++++++ Maths/test/Factors.test.js | 10 ++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Maths/Factors.js create mode 100644 Maths/test/Factors.test.js diff --git a/Maths/Factors.js b/Maths/Factors.js new file mode 100644 index 0000000000..68bbde6d23 --- /dev/null +++ b/Maths/Factors.js @@ -0,0 +1,16 @@ +/** + * Author: dephraiim + * License: GPL-3.0 or later + * + * More on Factors: + * https://www.mathsisfun.com/definitions/factor.html + * + */ + +const factorsOfANumber = (number = 0) => { + return Array.from(Array(number + 1).keys()).filter( + (num) => number % num === 0 + ) +} + +export { factorsOfANumber } diff --git a/Maths/test/Factors.test.js b/Maths/test/Factors.test.js new file mode 100644 index 0000000000..1ad60132d3 --- /dev/null +++ b/Maths/test/Factors.test.js @@ -0,0 +1,10 @@ +import { factorsOfANumber } from '../Factors' + +describe('Factors', () => { + factorsOfANumber(50).forEach((num) => { + it(`${num} is a factor of 50`, () => { + const isFactor = 50 % num === 0 + expect(isFactor).toBeTruthy() + }) + }) +}) From 01d19fee5e4c5b7903821672431e463111867b03 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Tue, 6 Oct 2020 15:33:05 +0000 Subject: [PATCH 4/9] chore: add perfect cube --- Maths/PerfectCube.js | 9 +++++++++ Maths/test/PerfectCube.test.js | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 Maths/PerfectCube.js create mode 100644 Maths/test/PerfectCube.test.js diff --git a/Maths/PerfectCube.js b/Maths/PerfectCube.js new file mode 100644 index 0000000000..bbfc821e2a --- /dev/null +++ b/Maths/PerfectCube.js @@ -0,0 +1,9 @@ +/** + * Author: dephraiim + * License: GPL-3.0 or later + * + */ + +const perfectCube = (num) => Math.round(num ** (1 / 3)) ** 3 === num + +export { perfectCube } diff --git a/Maths/test/PerfectCube.test.js b/Maths/test/PerfectCube.test.js new file mode 100644 index 0000000000..ff4b74f8f8 --- /dev/null +++ b/Maths/test/PerfectCube.test.js @@ -0,0 +1,10 @@ +import { perfectCube } from '../PerfectCube' + +describe('PerfectCube', () => { + it('should return true for a perfect cube', () => { + expect(perfectCube(125)).toBeTruthy() + }) + it('should return false for a non perfect cube', () => { + expect(perfectCube(100)).toBeFalsy() + }) +}) From 2973831f0c60da0e6f8fdff3d2136a52d4f0165d Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Tue, 6 Oct 2020 15:40:00 +0000 Subject: [PATCH 5/9] chore: add perfect square --- Maths/PerfectSquare.js | 9 +++++++++ Maths/test/PerfectSquare.test.js | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 Maths/PerfectSquare.js create mode 100644 Maths/test/PerfectSquare.test.js diff --git a/Maths/PerfectSquare.js b/Maths/PerfectSquare.js new file mode 100644 index 0000000000..d4909dbd4f --- /dev/null +++ b/Maths/PerfectSquare.js @@ -0,0 +1,9 @@ +/** + * Author: dephraiim + * License: GPL-3.0 or later + * + */ + +const perfectSquare = (num) => Math.sqrt(num) ** 2 === num + +export { perfectSquare } diff --git a/Maths/test/PerfectSquare.test.js b/Maths/test/PerfectSquare.test.js new file mode 100644 index 0000000000..86c8c34033 --- /dev/null +++ b/Maths/test/PerfectSquare.test.js @@ -0,0 +1,10 @@ +import { perfectSquare } from '../PerfectSquare' + +describe('PerfectSquare', () => { + it('should return true for a perfect cube', () => { + expect(perfectSquare(16)).toBeTruthy() + }) + it('should return false for a non perfect cube', () => { + expect(perfectSquare(10)).toBeFalsy() + }) +}) From 68a049d37563355ddef02d731ac3e4337d20532b Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Tue, 6 Oct 2020 16:07:19 +0000 Subject: [PATCH 6/9] chore: add perfect number --- Maths/PerfectNumber.js | 30 ++++++++++++++++++++++++++++++ Maths/test/PerfectNumber.test.js | 10 ++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Maths/PerfectNumber.js create mode 100644 Maths/test/PerfectNumber.test.js diff --git a/Maths/PerfectNumber.js b/Maths/PerfectNumber.js new file mode 100644 index 0000000000..ce8adefb6c --- /dev/null +++ b/Maths/PerfectNumber.js @@ -0,0 +1,30 @@ +/** + * Author: dephraiim + * License: GPL-3.0 or later + * + * == Perfect Number == + * In number theory, a perfect number is a positive integer that is equal to the sum of + * its positive divisors(factors), excluding the number itself. + * For example: 6 ==> divisors[1, 2, 3, 6] + * Excluding 6, the sum(divisors) is 1 + 2 + 3 = 6 + * So, 6 is a Perfect Number + * Other examples of Perfect Numbers: 28, 486, ... + * + * More on Perfect Number: + * https://en.wikipedia.org/wiki/Perfect_number + * + */ + +const factorsExcludingNumber = (n) => { + return [...Array(n).keys()].filter((num) => n % num === 0) +} + +const perfectNumber = (n) => { + const factorSum = factorsExcludingNumber(n).reduce((num, initialValue) => { + return num + initialValue + }, 0) + + return factorSum === n +} + +export { perfectNumber } diff --git a/Maths/test/PerfectNumber.test.js b/Maths/test/PerfectNumber.test.js new file mode 100644 index 0000000000..55b7d84269 --- /dev/null +++ b/Maths/test/PerfectNumber.test.js @@ -0,0 +1,10 @@ +import { perfectNumber } from '../PerfectNumber' + +describe('PerfectNumber', () => { + it('should return true for a perfect cube', () => { + expect(perfectNumber(28)).toBeTruthy() + }) + it('should return false for a non perfect cube', () => { + expect(perfectNumber(10)).toBeFalsy() + }) +}) From 9874c1effcc59e99067d46cde02e7ac01990b95b Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Tue, 6 Oct 2020 18:21:06 +0000 Subject: [PATCH 7/9] chore: add number of digits --- Maths/NumberOfDigits.js | 12 ++++++++++++ Maths/test/NumberOfDigits.test.js | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 Maths/NumberOfDigits.js create mode 100644 Maths/test/NumberOfDigits.test.js diff --git a/Maths/NumberOfDigits.js b/Maths/NumberOfDigits.js new file mode 100644 index 0000000000..6414c65deb --- /dev/null +++ b/Maths/NumberOfDigits.js @@ -0,0 +1,12 @@ +/** + * + * Author: dephraiim + * License: GPL-3.0 or later + * + * Returns the number of digits of a given integer + * + */ + +const numberOfDigit = (n) => Math.abs(n).toString().length + +export { numberOfDigit } diff --git a/Maths/test/NumberOfDigits.test.js b/Maths/test/NumberOfDigits.test.js new file mode 100644 index 0000000000..631e2cce36 --- /dev/null +++ b/Maths/test/NumberOfDigits.test.js @@ -0,0 +1,11 @@ +import { numberOfDigit } from '../NumberOfDigits' + +describe('NumberOfDigits', () => { + it('should return the correct number of digits for an integer', () => { + expect(numberOfDigit(1234000)).toBe(7) + }) + + it('should return the correct number of digits for a negative number', () => { + expect(numberOfDigit(-2346243)).toBe(7) + }) +}) From 9aecba5d6756d47cabadc65f9a8b15b7a08840e7 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Tue, 6 Oct 2020 18:22:24 +0000 Subject: [PATCH 8/9] chore: fix according to standardjs --- Maths/Area.js | 33 ++++++++++----------------- Recursive/FibonacciNumberRecursive.js | 1 - 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/Maths/Area.js b/Maths/Area.js index a598aaef51..5bc03dd80c 100644 --- a/Maths/Area.js +++ b/Maths/Area.js @@ -8,78 +8,69 @@ */ const areaSquare = (length) => { - if (length < 0) - throw new Error('areaSquare() does not accept negative values') + if (length < 0) { throw new Error('areaSquare() does not accept negative values') } return length ** 2 } const areaRectangle = (length, width) => { - if (length < 0 || width < 0) - throw new Error('areaRectangle() does not accept negative values') + if (length < 0 || width < 0) { throw new Error('areaRectangle() does not accept negative values') } return length * width } const areaTriangle = (base, height) => { - if (base < 0 || height < 0) - throw new Error('areaTriangle() does not accept negative values') + if (base < 0 || height < 0) { throw new Error('areaTriangle() does not accept negative values') } return (base * height) / 2 } const areaParallelogram = (base, height) => { - if (base < 0 || height < 0) - throw new Error('areaParallelogram() does not accept negative values') + if (base < 0 || height < 0) { throw new Error('areaParallelogram() does not accept negative values') } return base * height } const areaTrapezium = (base1, base2, height) => { - if (base1 < 0 || base2 < 0 || height < 0) - throw new Error('areaTrapezium() does not accept negative values') + if (base1 < 0 || base2 < 0 || height < 0) { throw new Error('areaTrapezium() does not accept negative values') } return (1 / 2) * (base1 + base2) * height } const areaRhombus = (diagonal1, diagonal2) => { - if (diagonal1 < 0 || diagonal2 < 0) - throw new Error('areaRhombus() does not accept negative values') + if (diagonal1 < 0 || diagonal2 < 0) { throw new Error('areaRhombus() does not accept negative values') } return (1 / 2) * diagonal1 * diagonal2 } const areaCircle = (radius) => { - if (radius < 0) - throw new Error('areaCircle() does not accept negative values') + if (radius < 0) { throw new Error('areaCircle() does not accept negative values') } return Math.PI * radius ** 2 } const surfaceAreaSphere = (radius) => { - if (radius < 0) - throw new Error('surfaceAreaSphere() does not accept negative values') + if (radius < 0) { throw new Error('surfaceAreaSphere() does not accept negative values') } return 4 * Math.PI * radius ** 2 } const surfaceAreaCube = (length) => { - if (length < 0) - throw new Error('surfaceAreaCube() does not accept negative values') + if (length < 0) { throw new Error('surfaceAreaCube() does not accept negative values') } return 6 * length ** 2 } const surfaceAreaCylinder = (radius, height) => { - if (height < 0 || radius < 0) - throw new Error('surfaceAreaCylinder() does not accept negative values') + if (height < 0 || radius < 0) { throw new Error('surfaceAreaCylinder() does not accept negative values') } return 2 * Math.PI * radius * (height + radius) // 2πr(h+r) } const curvedSurfaceAreaCylinder = (radius, height) => { - if (height < 0 || radius < 0) + if (height < 0 || radius < 0) { throw new Error( 'curvedSurfaceAreaCylinder() does not accept negative values' ) + } return 2 * Math.PI * radius * height } diff --git a/Recursive/FibonacciNumberRecursive.js b/Recursive/FibonacciNumberRecursive.js index 406c866846..e5c5bb95bb 100644 --- a/Recursive/FibonacciNumberRecursive.js +++ b/Recursive/FibonacciNumberRecursive.js @@ -6,7 +6,6 @@ const fibonacci = (N) => { return fibonacci(N - 2) + fibonacci(N - 1) } - // testing (() => { const number = 5 From bf9506f2148a2c6d3c3c2b6ba3af95ac95eb9a6b Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Sun, 11 Oct 2020 14:46:28 +0000 Subject: [PATCH 9/9] chore: remove conflicting files --- Maths/Area.js | 90 ----------------------------------- Maths/test/Area.test.js | 103 ---------------------------------------- 2 files changed, 193 deletions(-) delete mode 100644 Maths/Area.js delete mode 100644 Maths/test/Area.test.js diff --git a/Maths/Area.js b/Maths/Area.js deleted file mode 100644 index 5bc03dd80c..0000000000 --- a/Maths/Area.js +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Author: dephraiim - * License: GPL-3.0 or later - * - * More on Area: - * https://en.wikipedia.org/wiki/Area - * - */ - -const areaSquare = (length) => { - if (length < 0) { throw new Error('areaSquare() does not accept negative values') } - - return length ** 2 -} - -const areaRectangle = (length, width) => { - if (length < 0 || width < 0) { throw new Error('areaRectangle() does not accept negative values') } - return length * width -} - -const areaTriangle = (base, height) => { - if (base < 0 || height < 0) { throw new Error('areaTriangle() does not accept negative values') } - return (base * height) / 2 -} - -const areaParallelogram = (base, height) => { - if (base < 0 || height < 0) { throw new Error('areaParallelogram() does not accept negative values') } - - return base * height -} - -const areaTrapezium = (base1, base2, height) => { - if (base1 < 0 || base2 < 0 || height < 0) { throw new Error('areaTrapezium() does not accept negative values') } - - return (1 / 2) * (base1 + base2) * height -} - -const areaRhombus = (diagonal1, diagonal2) => { - if (diagonal1 < 0 || diagonal2 < 0) { throw new Error('areaRhombus() does not accept negative values') } - - return (1 / 2) * diagonal1 * diagonal2 -} - -const areaCircle = (radius) => { - if (radius < 0) { throw new Error('areaCircle() does not accept negative values') } - - return Math.PI * radius ** 2 -} - -const surfaceAreaSphere = (radius) => { - if (radius < 0) { throw new Error('surfaceAreaSphere() does not accept negative values') } - - return 4 * Math.PI * radius ** 2 -} - -const surfaceAreaCube = (length) => { - if (length < 0) { throw new Error('surfaceAreaCube() does not accept negative values') } - - return 6 * length ** 2 -} - -const surfaceAreaCylinder = (radius, height) => { - if (height < 0 || radius < 0) { throw new Error('surfaceAreaCylinder() does not accept negative values') } - - return 2 * Math.PI * radius * (height + radius) // 2πr(h+r) -} - -const curvedSurfaceAreaCylinder = (radius, height) => { - if (height < 0 || radius < 0) { - throw new Error( - 'curvedSurfaceAreaCylinder() does not accept negative values' - ) - } - - return 2 * Math.PI * radius * height -} - -export { - areaCircle, - areaTriangle, - areaTrapezium, - areaSquare, - areaRhombus, - areaRectangle, - areaParallelogram, - surfaceAreaCube, - surfaceAreaSphere, - surfaceAreaCylinder, - curvedSurfaceAreaCylinder -} diff --git a/Maths/test/Area.test.js b/Maths/test/Area.test.js deleted file mode 100644 index 91ac816328..0000000000 --- a/Maths/test/Area.test.js +++ /dev/null @@ -1,103 +0,0 @@ -import { - areaCircle, - areaTriangle, - areaTrapezium, - areaSquare, - areaRhombus, - areaRectangle, - areaParallelogram, - surfaceAreaCube, - surfaceAreaSphere, - surfaceAreaCylinder, - curvedSurfaceAreaCylinder -} from '../Area' - -describe('Area', () => { - it('should return the area of a circle', () => { - expect(Math.round(areaCircle(10))).toBe(314) - }) - - it('should throw an error when given negative values', () => { - expect(() => areaCircle(-10)).toThrow() - }) - - it('should return the area of a parallelogram', () => { - expect(areaParallelogram(10, 20)).toBe(200) - }) - - it('should throw an error when given negative values', () => { - expect(() => areaParallelogram(-10, -21)).toThrow() - }) - - it('should return the area of a rectangle', () => { - expect(areaRectangle(10, 20)).toBe(200) - }) - - it('should throw an error when given negative values', () => { - expect(() => areaRectangle(-2, -3)).toThrow() - }) - - it('should return the area of a rhombus', () => { - expect(areaRhombus(10, 10)).toBe(50) - }) - - it('should throw an error when given negative values', () => { - expect(() => areaRhombus(-2, -4)).toThrow() - }) - - it('should return the area of a square', () => { - expect(areaSquare(2)).toBe(4) - }) - - it('should throw an error when given negative values', () => { - expect(() => areaSquare(-2)).toThrow() - }) - - it('should return the area of a trapezium', () => { - expect(areaTrapezium(2, 3, 4)).toBe(10) - }) - - it('should throw an error when given negative values', () => { - expect(() => areaTrapezium(-2, -3, -4)).toThrow() - }) - - it('should return the area of a triangle', () => { - expect(areaTriangle(5, 10)).toBe(25) - }) - - it('should throw an error when given negative values', () => { - expect(() => areaTriangle(-2, -4)).toThrow() - }) - - it('should return the surface area of a cube', () => { - expect(surfaceAreaCube(2)).toBe(24) - }) - - it('should throw an error when given negative values', () => { - expect(() => surfaceAreaCube(-2)).toThrow() - }) - - it('should return the surface area of a cylinder', () => { - expect(Math.round(surfaceAreaCylinder(10, 20))).toBe(1885) - }) - - it('should throw an error when given negative values', () => { - expect(() => surfaceAreaCylinder(-2)).toThrow() - }) - - it('should return the surface area of a sphere', () => { - expect(Math.round(surfaceAreaSphere(2))).toBe(50) - }) - - it('should throw an error when given negative values', () => { - expect(() => surfaceAreaSphere(-2)).toThrow() - }) - - it('should return the curved surface area of a cylinder', () => { - expect(Math.round(curvedSurfaceAreaCylinder(5, 10))).toBe(314) - }) - - it('should throw an error when given negative values', () => { - expect(() => curvedSurfaceAreaCylinder(-2)).toThrow() - }) -})