Skip to content

Commit c7cda09

Browse files
vil02appgurueu
andcommitted
style: use simpler syntax express polynomials
Co-authored-by: appgurueu <[email protected]>
1 parent f2f10bd commit c7cda09

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

Diff for: Maths/test/BisectionMethod.test.js

+3-26
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import { findRoot } from '../BisectionMethod'
22

33
test('Equation f(x) = x^2 - 3*x + 2 = 0, has root x = 1 in [a, b] = [0, 1.5]', () => {
4-
const root = findRoot(
5-
0,
6-
1.5,
7-
(x) => {
8-
return Math.pow(x, 2) - 3 * x + 2
9-
},
10-
8
11-
)
4+
const root = findRoot(0, 1.5, (x) => x ** 2 - 3 * x + 2, 8)
125
expect(root).toBe(0.9990234375)
136
})
147

@@ -37,26 +30,10 @@ test('Equation f(x) = sqrt(x) + e^(2*x) - 8*x = 0, has root x = 0.93945851 in [a
3730
})
3831

3932
test('Equation f(x) = x^3 = 0, has root x = 0.0 in [a, b] = [-1.0, 1.0]', () => {
40-
const root = findRoot(
41-
-1.0,
42-
1.0,
43-
(x) => {
44-
return Math.pow(x, 3)
45-
},
46-
32
47-
)
33+
const root = findRoot(-1.0, 1.0, (x) => x ** 3, 32)
4834
expect(root).toBeCloseTo(0.0, 5)
4935
})
5036

5137
test('Throws an error when function does not change sign', () => {
52-
expect(() =>
53-
findRoot(
54-
-1.0,
55-
1.0,
56-
(x) => {
57-
return Math.pow(x, 2)
58-
},
59-
10
60-
)
61-
).toThrowError()
38+
expect(() => findRoot(-1.0, 1.0, (x) => x ** 2, 10)).toThrowError()
6239
})

0 commit comments

Comments
 (0)