Skip to content

Commit 83259b3

Browse files
Add tests
1 parent 2be2bce commit 83259b3

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

Maths/CircularArc.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
/**
2-
* @function degreesToRadians
3-
* @description convert from degrees to radians
4-
* @param {Integer} angle in degrees
5-
* @return {Integer} degrees * pi / 180
6-
* @see https://en.wikipedia.org/wiki/Degree_(angle)
7-
* @example degreesToRadians(45) = 0.7853981633974483
8-
*/
9-
function degreesToRadians (degrees) {
10-
return degrees * Math.PI / 180
11-
}
1+
import { degreeToRadian } from "./DegreeToRadian.js"
122

133
/**
144
* @function circularArcLength
@@ -20,7 +10,7 @@ function degreesToRadians (degrees) {
2010
* @example circularArcLength(3, 45) = 2.356194490192345
2111
*/
2212
function circularArcLength (radius, degrees) {
23-
return radius * degreesToRadians(degrees)
13+
return radius * degreeToRadian(degrees)
2414
}
2515
/**
2616
* @function circularArcArea
@@ -32,7 +22,7 @@ function circularArcLength (radius, degrees) {
3222
* @example circularArcArea(3,45) = 3.5342917352885173
3323
*/
3424
function circularArcArea (radius, degrees) {
35-
return Math.pow(radius, 2) * degreesToRadians(degrees) / 2
25+
return Math.pow(radius, 2) * degreeToRadian(degrees) / 2
3626
}
3727

3828
export {

Maths/test/CircularArc.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { circularArcLength } from "../CircularArc";
2+
import { circularArcArea } from "../CircularArc";
3+
4+
describe('circularArcLength', () => {
5+
it('with natural number', () => {
6+
const arcLengthOfOneThirty = circularArcLength(1, 30)
7+
const arcLengthOfThreeSixty = circularArcLength(3, 60)
8+
expect(arcLengthOfOneThirty).toBe(0.5235987755982988)
9+
expect(arcLengthOfThreeSixty).toBe(3.141592653589793)
10+
})
11+
})
12+
13+
describe('circularArcArea', () => {
14+
it('with natural number', () => {
15+
const arcAreaOfOneThirty = circularArcArea(1, 30)
16+
const arcAreaOfThreeSixty = circularArcArea(3, 60)
17+
expect(arcAreaOfOneThirty).toBe(0.2617993877991494)
18+
expect(arcAreaOfThreeSixty).toBe(4.71238898038469)
19+
})
20+
})

0 commit comments

Comments
 (0)