Update tests to (Foo) { ... } syntax.

This commit is contained in:
Christoffer Lerno
2025-02-18 18:53:30 +01:00
parent 168c11e006
commit cbacd64987
98 changed files with 449 additions and 551 deletions

View File

@@ -11,9 +11,9 @@ fn void test_abs() @test
assert(math::abs(z) == 21.0f);
$assert @typeis(math::abs(z), float);
int[<3>] xx = { -1, -1000, 1000 };
assert(math::abs(xx) == int[<3>] { 1, 1000, 1000 });
assert(math::abs(xx) == (int[<3>]) { 1, 1000, 1000 });
double[<3>] yy = { -1, -0.5, 1000 };
assert(math::abs(yy) == double[<3>] { 1, 0.5, 1000 });
assert(math::abs(yy) == (double[<3>]) { 1, 0.5, 1000 });
}
fn void test_acos() @test
@@ -269,7 +269,7 @@ fn void test_ceil() @test
assert(math::ceil(f) == 0.0f);
$assert @typeis(math::ceil(f), float);
double[<5>] vec = { -123.1, 123.1, 0.1, -0.9, 0 };
assert(math::ceil(vec) == double[<5>] { -123, 124, 1, 0, 0 });
assert(math::ceil(vec) == (double[<5>]) { -123, 124, 1, 0, 0 });
}
fn void test_cos() @test
@@ -351,7 +351,7 @@ fn void test_floor() @test
assert(math::floor(f) == -1.0f);
$assert @typeis(math::floor(f), float);
double[<5>] vec = { -123.1, 123.1, 0.9, -0.1, 0 };
assert(math::floor(vec) == double[<5>] { -124, 123, 0, -1, 0 });
assert(math::floor(vec) == (double[<5>]) { -124, 123, 0, -1, 0 });
}
fn void test_log() @test
@@ -536,7 +536,7 @@ fn void test_trunc() @test
assert(math::trunc(f) == -0.0f);
$assert @typeis(math::trunc(f), float);
double[<5>] vec = { -123.9, 123.9, 0.9, -0.9, 0 };
assert(math::trunc(vec) == double[<5>] { -123, 123, 0, 0, 0 });
assert(math::trunc(vec) == (double[<5>]) { -123, 123, 0, 0, 0 });
}
fn void test_round_decimals() @test
@@ -579,14 +579,14 @@ fn void test_muldiv()
assert(h.muldiv(2_000_000_000_000u64, 1_000_000_000u64) == 2_000_000_000_000_000u64);
char[<4>] i = {20, 30, 40, 50};
assert(i.muldiv(12,10) == char[<4>] {24, 36, 48, 60});
assert(i.muldiv(char[<4>]{11, 12, 13, 14}, char[<4>]{10,10,10,10}) == char[<4>]{22, 36, 52, 70});
assert(i.muldiv(12,10) == (char[<4>]) {24, 36, 48, 60});
assert(i.muldiv((char[<4>]){11, 12, 13, 14}, (char[<4>]){10,10,10,10}) == (char[<4>]){22, 36, 52, 70});
long[<4>] j = {1_000_000_000_000i64, 2_000_000_000_000i64, 3_000_000_000_000i64, 4_000_000_000_000i64};
assert(j.muldiv(2_000_000_000_000i64, 1_000_000_000i64) == long[<4>]{2_000_000_000_000_000i64, 4_000_000_000_000_000i64, 6_000_000_000_000_000i64, 8_000_000_000_000_000i64});
assert(j.muldiv(2_000_000_000_000i64, 1_000_000_000i64) == (long[<4>]){2_000_000_000_000_000i64, 4_000_000_000_000_000i64, 6_000_000_000_000_000i64, 8_000_000_000_000_000i64});
ichar[<4>] k = {20, 30, 40, 50};
assert(k.muldiv(20,-10) == ichar[<4>]{-40,-60,-80,-100});
assert(k.muldiv(20,-10) == (ichar[<4>]){-40,-60,-80,-100});
}
fn void test_gcd() @test

View File

@@ -12,36 +12,36 @@ def ComplexType = Complex(<ElementType>);
fn void complex_mul_imaginary()
{
ComplexType i = complex::IMAGINARY(<ElementType>);
assert(i.mul(i).equals(ComplexType{-1, 0}));
assert(i.mul(i).mul(i).equals(ComplexType{0, -1}));
assert(i.mul(i).equals((ComplexType){-1, 0}));
assert(i.mul(i).mul(i).equals((ComplexType){0, -1}));
}
fn void complex_add()
{
ComplexType a = {3, 4};
ComplexType b = {1, 2};
assert(a.add(b).equals(ComplexType{4, 6}));
assert(a.add_each(1).equals(ComplexType{4, 5}));
assert(a.add(b).equals((ComplexType){4, 6}));
assert(a.add_each(1).equals((ComplexType){4, 5}));
}
fn void complex_sub()
{
ComplexType a = {3, 4};
ComplexType b = {1, 2};
assert(a.sub(b).equals(ComplexType{2, 2}));
assert(a.sub_each(1).equals(ComplexType{2, 3}));
assert(a.sub(b).equals((ComplexType){2, 2}));
assert(a.sub_each(1).equals((ComplexType){2, 3}));
}
fn void complex_scale()
{
ComplexType a = {2, 1};
assert(a.scale(2).equals(ComplexType{4, 2}));
assert(a.scale(2).equals((ComplexType){4, 2}));
}
fn void complex_conjugate()
{
ComplexType a = {3, 4};
assert(a.conjugate().equals(ComplexType{3, -4}));
assert(a.conjugate().equals((ComplexType){3, -4}));
}
fn void complex_inverse() @if(types::is_float(ElementType))
@@ -54,6 +54,6 @@ fn void complex_div() @if(types::is_float(ElementType))
{
ComplexType a = {2, 5};
ComplexType b = {4, -1};
assert(a.div(b).equals(ComplexType{3.0/17.0, 22.0/17.0}));
assert(a.div(b).equals((ComplexType){3.0/17.0, 22.0/17.0}));
}

View File

@@ -9,7 +9,7 @@ fn void test_mat4()
Matrix4 calc = mat.mul(mat2);
assert(calc.m == mat.m);
Matrix4 translated = mat.translate(Vec3{0.0, 0.0, 0.0});
Matrix4 translated = mat.translate({0.0, 0.0, 0.0});
assert(translated.m == mat.m);
};
@@ -117,6 +117,6 @@ fn void test_mat2_inverse()
fn void test_vec3()
{
Vec3 cross = Vec3{2,3,4}.cross(Vec3{5,6,7});
assert(cross == Vec3{-3,6,-3});
Vec3 cross = (Vec3){2,3,4}.cross({5,6,7});
assert(cross == {-3,6,-3});
}

View File

@@ -29,8 +29,8 @@ fn void test()
0.000000, 0.000000, 0.000000, 1.000000
};
Matrix4 rotation = Quaternion {0.5, 0.5, 0.5, 1}.to_matrix();
Matrix4f rotation_f = Quaternionf {0.5, 0.5, 0.5, 1}.to_matrixf();
Matrix4 rotation = (Quaternion) {0.5, 0.5, 0.5, 1}.to_matrix();
Matrix4f rotation_f = (Quaternionf) {0.5, 0.5, 0.5, 1}.to_matrixf();
assert(math::round_to_decimals((double[<16>])result.m, 2) == math::round_to_decimals((double[<16>])rotation.m, 2));
assert(math::round_to_decimals((float[<16>])result.m, 2) == math::round_to_decimals((float[<16>])rotation_f.m, 2));