mirror of
https://github.com/vlang/v.git
synced 2025-09-10 16:00:31 -04:00
math.fractions: fix deprecation warnings in tests (#19906)
This commit is contained in:
parent
c3cf9ee832
commit
439aeeffa0
@ -7,19 +7,19 @@ import math
|
|||||||
fn test_half() {
|
fn test_half() {
|
||||||
float_val := 0.5
|
float_val := 0.5
|
||||||
fract_val := fractions.approximate(float_val)
|
fract_val := fractions.approximate(float_val)
|
||||||
assert fract_val.equals(fractions.fraction(1, 2))
|
assert fract_val == fractions.fraction(1, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_third() {
|
fn test_third() {
|
||||||
float_val := 1.0 / 3.0
|
float_val := 1.0 / 3.0
|
||||||
fract_val := fractions.approximate(float_val)
|
fract_val := fractions.approximate(float_val)
|
||||||
assert fract_val.equals(fractions.fraction(1, 3))
|
assert fract_val == fractions.fraction(1, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_minus_one_twelfth() {
|
fn test_minus_one_twelfth() {
|
||||||
float_val := -1.0 / 12.0
|
float_val := -1.0 / 12.0
|
||||||
fract_val := fractions.approximate(float_val)
|
fract_val := fractions.approximate(float_val)
|
||||||
assert fract_val.equals(fractions.fraction(-1, 12))
|
assert fract_val == fractions.fraction(-1, 12)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_zero() {
|
fn test_zero() {
|
||||||
@ -27,37 +27,37 @@ fn test_zero() {
|
|||||||
println('Pre')
|
println('Pre')
|
||||||
fract_val := fractions.approximate(float_val)
|
fract_val := fractions.approximate(float_val)
|
||||||
println('Post')
|
println('Post')
|
||||||
assert fract_val.equals(fractions.fraction(0, 1))
|
assert fract_val == fractions.fraction(0, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_minus_one() {
|
fn test_minus_one() {
|
||||||
float_val := -1.0
|
float_val := -1.0
|
||||||
fract_val := fractions.approximate(float_val)
|
fract_val := fractions.approximate(float_val)
|
||||||
assert fract_val.equals(fractions.fraction(-1, 1))
|
assert fract_val == fractions.fraction(-1, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_thirty_three() {
|
fn test_thirty_three() {
|
||||||
float_val := 33.0
|
float_val := 33.0
|
||||||
fract_val := fractions.approximate(float_val)
|
fract_val := fractions.approximate(float_val)
|
||||||
assert fract_val.equals(fractions.fraction(33, 1))
|
assert fract_val == fractions.fraction(33, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_millionth() {
|
fn test_millionth() {
|
||||||
float_val := 1.0 / 1000000.0
|
float_val := 1.0 / 1000000.0
|
||||||
fract_val := fractions.approximate(float_val)
|
fract_val := fractions.approximate(float_val)
|
||||||
assert fract_val.equals(fractions.fraction(1, 1000000))
|
assert fract_val == fractions.fraction(1, 1000000)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_minus_27_by_57() {
|
fn test_minus_27_by_57() {
|
||||||
float_val := -27.0 / 57.0
|
float_val := -27.0 / 57.0
|
||||||
fract_val := fractions.approximate(float_val)
|
fract_val := fractions.approximate(float_val)
|
||||||
assert fract_val.equals(fractions.fraction(-27, 57))
|
assert fract_val == fractions.fraction(-27, 57)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_29_by_104() {
|
fn test_29_by_104() {
|
||||||
float_val := 29.0 / 104.0
|
float_val := 29.0 / 104.0
|
||||||
fract_val := fractions.approximate(float_val)
|
fract_val := fractions.approximate(float_val)
|
||||||
assert fract_val.equals(fractions.fraction(29, 104))
|
assert fract_val == fractions.fraction(29, 104)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_140710_232() {
|
fn test_140710_232() {
|
||||||
@ -69,121 +69,118 @@ fn test_140710_232() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_1_digit() {
|
fn test_pi_1_digit() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-2).equals(fractions.fraction(22,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-2) == fractions.fraction(22, 7)
|
||||||
7))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_2_digits() {
|
fn test_pi_2_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-3).equals(fractions.fraction(22,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-3) == fractions.fraction(22, 7)
|
||||||
7))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_3_digits() {
|
fn test_pi_3_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-4).equals(fractions.fraction(333,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-4) == fractions.fraction(333,
|
||||||
106))
|
106)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_4_digits() {
|
fn test_pi_4_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-5).equals(fractions.fraction(355,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-5) == fractions.fraction(355,
|
||||||
113))
|
113)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_5_digits() {
|
fn test_pi_5_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-6).equals(fractions.fraction(355,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-6) == fractions.fraction(355,
|
||||||
113))
|
113)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_6_digits() {
|
fn test_pi_6_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-7).equals(fractions.fraction(355,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-7) == fractions.fraction(355,
|
||||||
113))
|
113)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_7_digits() {
|
fn test_pi_7_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-8).equals(fractions.fraction(103993,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-8) == fractions.fraction(103993,
|
||||||
33102))
|
33102)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_8_digits() {
|
fn test_pi_8_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-9).equals(fractions.fraction(103993,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-9) == fractions.fraction(103993,
|
||||||
33102))
|
33102)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_9_digits() {
|
fn test_pi_9_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-10).equals(fractions.fraction(104348,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-10) == fractions.fraction(104348,
|
||||||
33215))
|
33215)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_10_digits() {
|
fn test_pi_10_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-11).equals(fractions.fraction(312689,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-11) == fractions.fraction(312689,
|
||||||
99532))
|
99532)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_11_digits() {
|
fn test_pi_11_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-12).equals(fractions.fraction(1146408,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-12) == fractions.fraction(1146408,
|
||||||
364913))
|
364913)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pi_12_digits() {
|
fn test_pi_12_digits() {
|
||||||
assert fractions.approximate_with_eps(math.pi, 5.0e-13).equals(fractions.fraction(4272943,
|
assert fractions.approximate_with_eps(math.pi, 5.0e-13) == fractions.fraction(4272943,
|
||||||
1360120))
|
1360120)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_1_digit() {
|
fn test_phi_1_digit() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-2).equals(fractions.fraction(5,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-2) == fractions.fraction(5, 3)
|
||||||
3))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_2_digits() {
|
fn test_phi_2_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-3).equals(fractions.fraction(21,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-3) == fractions.fraction(21,
|
||||||
13))
|
13)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_3_digits() {
|
fn test_phi_3_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-4).equals(fractions.fraction(55,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-4) == fractions.fraction(55,
|
||||||
34))
|
34)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_4_digits() {
|
fn test_phi_4_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-5).equals(fractions.fraction(233,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-5) == fractions.fraction(233,
|
||||||
144))
|
144)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_5_digits() {
|
fn test_phi_5_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-6).equals(fractions.fraction(610,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-6) == fractions.fraction(610,
|
||||||
377))
|
377)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_6_digits() {
|
fn test_phi_6_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-7).equals(fractions.fraction(1597,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-7) == fractions.fraction(1597,
|
||||||
987))
|
987)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_7_digits() {
|
fn test_phi_7_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-8).equals(fractions.fraction(6765,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-8) == fractions.fraction(6765,
|
||||||
4181))
|
4181)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_8_digits() {
|
fn test_phi_8_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-9).equals(fractions.fraction(17711,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-9) == fractions.fraction(17711,
|
||||||
10946))
|
10946)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_9_digits() {
|
fn test_phi_9_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-10).equals(fractions.fraction(75025,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-10) == fractions.fraction(75025,
|
||||||
46368))
|
46368)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_10_digits() {
|
fn test_phi_10_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-11).equals(fractions.fraction(196418,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-11) == fractions.fraction(196418,
|
||||||
121393))
|
121393)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_11_digits() {
|
fn test_phi_11_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-12).equals(fractions.fraction(514229,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-12) == fractions.fraction(514229,
|
||||||
317811))
|
317811)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_phi_12_digits() {
|
fn test_phi_12_digits() {
|
||||||
assert fractions.approximate_with_eps(math.phi, 5.0e-13).equals(fractions.fraction(2178309,
|
assert fractions.approximate_with_eps(math.phi, 5.0e-13) == fractions.fraction(2178309,
|
||||||
1346269))
|
1346269)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user