mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Add initial tests for big rationals
This commit is contained in:
@@ -160,6 +160,5 @@ destroy :: proc {
|
|||||||
int_destroy :: proc(integers: ..^Int)
|
int_destroy :: proc(integers: ..^Int)
|
||||||
*/
|
*/
|
||||||
int_destroy,
|
int_destroy,
|
||||||
}
|
internal_rat_destroy,
|
||||||
|
}
|
||||||
|
|
||||||
@@ -11,4 +11,6 @@ echo Running core:math/big tests
|
|||||||
echo ---
|
echo ---
|
||||||
|
|
||||||
%PATH_TO_ODIN% build . %COMMON% -o:speed -out:%OUT_NAME%
|
%PATH_TO_ODIN% build . %COMMON% -o:speed -out:%OUT_NAME%
|
||||||
python3 test.py %TEST_ARGS%
|
python3 test.py %TEST_ARGS%
|
||||||
|
|
||||||
|
odin test test_core_math_big.odin -file
|
||||||
@@ -35,3 +35,51 @@ test_permutations_and_combinations :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, error, nil)
|
testing.expect_value(t, error, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rational_Vectors :: struct {
|
||||||
|
numerator: int,
|
||||||
|
denominator: int,
|
||||||
|
expected_f64: f64,
|
||||||
|
expected_f32: f32,
|
||||||
|
expected_f16: f16,
|
||||||
|
exact_f64: bool,
|
||||||
|
exact_f32: bool,
|
||||||
|
exact_f16: bool,
|
||||||
|
}
|
||||||
|
rational_vectors := []Rational_Vectors{
|
||||||
|
{-1, 1, -1.00, -1.00, -1.00, true, true, true},
|
||||||
|
{ 1, 4, 0.25, 0.25, 0.25, true, true, true},
|
||||||
|
{ 3, 4, 0.75, 0.75, 0.75, true, true, true},
|
||||||
|
{-3, 4, -0.75, -0.75, -0.75, true, true, true},
|
||||||
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_rational_to_float :: proc(t: ^testing.T) {
|
||||||
|
for vec in rational_vectors {
|
||||||
|
r: big.Rat
|
||||||
|
defer big.destroy(&r)
|
||||||
|
big.set(&r.a, vec.numerator)
|
||||||
|
big.set(&r.b, vec.denominator)
|
||||||
|
|
||||||
|
{
|
||||||
|
float, exact, err := big.rat_to_f64(&r)
|
||||||
|
testing.expect_value(t, float, vec.expected_f64)
|
||||||
|
testing.expect(t, exact == vec.exact_f64)
|
||||||
|
testing.expect(t, err == nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
float, exact, err := big.rat_to_f32(&r)
|
||||||
|
testing.expect_value(t, float, vec.expected_f32)
|
||||||
|
testing.expect(t, exact == vec.exact_f32)
|
||||||
|
testing.expect(t, err == nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
float, exact, err := big.rat_to_f16(&r)
|
||||||
|
testing.expect_value(t, float, vec.expected_f16)
|
||||||
|
testing.expect(t, exact == vec.exact_f16)
|
||||||
|
testing.expect(t, err == nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user