Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7cda09

Browse files
vil02appgurueu
andcommitted
style: use simpler syntax express polynomials
Co-authored-by: appgurueu <34514239+appgurueu@users.noreply.github.com>
1 parentf2f10bd commitc7cda09

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

‎Maths/test/BisectionMethod.test.js

Lines changed: 3 additions & 26 deletions
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-
constroot=findRoot(
5-
0,
6-
1.5,
7-
(x)=>{
8-
returnMath.pow(x,2)-3*x+2
9-
},
10-
8
11-
)
4+
constroot=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-
constroot=findRoot(
41-
-1.0,
42-
1.0,
43-
(x)=>{
44-
returnMath.pow(x,3)
45-
},
46-
32
47-
)
33+
constroot=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-
returnMath.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)

[8]ページ先頭

©2009-2025 Movatter.jp