mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Port tests\core\c\libc
This commit is contained in:
+1
-1
@@ -33,7 +33,7 @@ download_test_assets:
|
|||||||
$(PYTHON) download_assets.py
|
$(PYTHON) download_assets.py
|
||||||
|
|
||||||
c_libc_test:
|
c_libc_test:
|
||||||
$(ODIN) run c/libc $(COMMON) -out:test_core_libc
|
$(ODIN) test c/libc $(COMMON) -out:test_core_libc
|
||||||
|
|
||||||
compress_test:
|
compress_test:
|
||||||
$(ODIN) test compress $(COMMON) -out:test_core_compress
|
$(ODIN) test compress $(COMMON) -out:test_core_compress
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ set COMMON=-no-bounds-check -vet -strict-style
|
|||||||
set COLLECTION=-collection:tests=..
|
set COLLECTION=-collection:tests=..
|
||||||
set PATH_TO_ODIN==..\..\odin
|
set PATH_TO_ODIN==..\..\odin
|
||||||
python3 download_assets.py
|
python3 download_assets.py
|
||||||
|
echo ---
|
||||||
|
echo Running core:c/libc tests
|
||||||
|
echo ---
|
||||||
|
%PATH_TO_ODIN% test c\libc %COMMON% -out:test_libc.exe || exit /b
|
||||||
|
|
||||||
echo ---
|
echo ---
|
||||||
echo Running core:compress tests
|
echo Running core:compress tests
|
||||||
echo ---
|
echo ---
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package test_core_libc
|
|
||||||
|
|
||||||
import "core:fmt"
|
|
||||||
import "core:os"
|
|
||||||
import "core:testing"
|
|
||||||
|
|
||||||
TEST_count := 0
|
|
||||||
TEST_fail := 0
|
|
||||||
|
|
||||||
when ODIN_TEST {
|
|
||||||
expect :: testing.expect
|
|
||||||
log :: testing.log
|
|
||||||
} else {
|
|
||||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
|
||||||
TEST_count += 1
|
|
||||||
if !condition {
|
|
||||||
TEST_fail += 1
|
|
||||||
fmt.printf("[%v] %v\n", loc, message)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
|
||||||
fmt.printf("[%v] ", loc)
|
|
||||||
fmt.printf("log: %v\n", v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main :: proc() {
|
|
||||||
t := testing.T{}
|
|
||||||
test_libc_complex(&t)
|
|
||||||
|
|
||||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
|
||||||
if TEST_fail > 0 {
|
|
||||||
os.exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package test_core_libc
|
package test_core_libc
|
||||||
|
|
||||||
import "core:testing"
|
import "core:testing"
|
||||||
import "core:fmt"
|
|
||||||
import "core:c/libc"
|
import "core:c/libc"
|
||||||
|
import "core:log"
|
||||||
|
|
||||||
reldiff :: proc(lhs, rhs: $T) -> f64 {
|
reldiff :: proc(lhs, rhs: $T) -> f64 {
|
||||||
if lhs == rhs {
|
if lhs == rhs {
|
||||||
@@ -14,7 +14,7 @@ reldiff :: proc(lhs, rhs: $T) -> f64 {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
isclose :: proc(lhs, rhs: $T, rtol:f64 = 1e-12, atol:f64 = 1e-12) -> bool {
|
isclose :: proc(t: ^testing.T, lhs, rhs: $T, rtol:f64 = 1e-12, atol:f64 = 1e-12) -> bool {
|
||||||
adiff := f64(abs(lhs - rhs))
|
adiff := f64(abs(lhs - rhs))
|
||||||
if adiff < atol {
|
if adiff < atol {
|
||||||
return true
|
return true
|
||||||
@@ -23,7 +23,7 @@ isclose :: proc(lhs, rhs: $T, rtol:f64 = 1e-12, atol:f64 = 1e-12) -> bool {
|
|||||||
if rdiff < rtol {
|
if rdiff < rtol {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
fmt.printf("not close -- lhs:%v rhs:%v -- adiff:%e rdiff:%e\n",lhs, rhs, adiff, rdiff)
|
log.infof("not close -- lhs:%v rhs:%v -- adiff:%e rdiff:%e\n",lhs, rhs, adiff, rdiff)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,6 @@ test_libc_complex :: proc(t: ^testing.T) {
|
|||||||
test_libc_pow_binding(t, libc.complex_float, f32, libc_powf, 1e-12, 1e-5)
|
test_libc_pow_binding(t, libc.complex_float, f32, libc_powf, 1e-12, 1e-5)
|
||||||
}
|
}
|
||||||
|
|
||||||
@test
|
|
||||||
test_libc_pow_binding :: proc(t: ^testing.T, $LIBC_COMPLEX:typeid, $F:typeid, pow: proc(LIBC_COMPLEX, LIBC_COMPLEX) -> LIBC_COMPLEX,
|
test_libc_pow_binding :: proc(t: ^testing.T, $LIBC_COMPLEX:typeid, $F:typeid, pow: proc(LIBC_COMPLEX, LIBC_COMPLEX) -> LIBC_COMPLEX,
|
||||||
rtol: f64, atol: f64) {
|
rtol: f64, atol: f64) {
|
||||||
// Tests that c/libc/pow(f) functions have two arguments and that the function works as expected for simple inputs
|
// Tests that c/libc/pow(f) functions have two arguments and that the function works as expected for simple inputs
|
||||||
@@ -56,8 +55,8 @@ test_libc_pow_binding :: proc(t: ^testing.T, $LIBC_COMPLEX:typeid, $F:typeid, po
|
|||||||
for n in -4..=4 {
|
for n in -4..=4 {
|
||||||
complex_power := LIBC_COMPLEX(complex(F(n), F(0.)))
|
complex_power := LIBC_COMPLEX(complex(F(n), F(0.)))
|
||||||
result := pow(complex_base, complex_power)
|
result := pow(complex_base, complex_power)
|
||||||
expect(t, isclose(expected_real, F(real(result)), rtol, atol), fmt.tprintf("ftype:%T, n:%v reldiff(%v, re(%v)) is greater than specified rtol:%e", F{}, n, expected_real, result, rtol))
|
testing.expectf(t, isclose(t, expected_real, F(real(result)), rtol, atol), "ftype:%T, n:%v reldiff(%v, re(%v)) is greater than specified rtol:%e", F{}, n, expected_real, result, rtol)
|
||||||
expect(t, isclose(expected_imag, F(imag(result)), rtol, atol), fmt.tprintf("ftype:%T, n:%v reldiff(%v, im(%v)) is greater than specified rtol:%e", F{}, n, expected_imag, result, rtol))
|
testing.expectf(t, isclose(t, expected_imag, F(imag(result)), rtol, atol), "ftype:%T, n:%v reldiff(%v, im(%v)) is greater than specified rtol:%e", F{}, n, expected_imag, result, rtol)
|
||||||
expected_real *= 2
|
expected_real *= 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,8 +82,8 @@ test_libc_pow_binding :: proc(t: ^testing.T, $LIBC_COMPLEX:typeid, $F:typeid, po
|
|||||||
expected_real = 0.
|
expected_real = 0.
|
||||||
expected_imag = -value
|
expected_imag = -value
|
||||||
}
|
}
|
||||||
expect(t, isclose(expected_real, F(real(result)), rtol, atol), fmt.tprintf("ftype:%T, n:%v reldiff(%v, re(%v)) is greater than specified rtol:%e", F{}, n, expected_real, result, rtol))
|
testing.expectf(t, isclose(t, expected_real, F(real(result)), rtol, atol), "ftype:%T, n:%v reldiff(%v, re(%v)) is greater than specified rtol:%e", F{}, n, expected_real, result, rtol)
|
||||||
expect(t, isclose(expected_imag, F(imag(result)), rtol, atol), fmt.tprintf("ftype:%T, n:%v reldiff(%v, im(%v)) is greater than specified rtol:%e", F{}, n, expected_imag, result, rtol))
|
testing.expectf(t, isclose(t, expected_imag, F(imag(result)), rtol, atol), "ftype:%T, n:%v reldiff(%v, im(%v)) is greater than specified rtol:%e", F{}, n, expected_imag, result, rtol)
|
||||||
value *= 2
|
value *= 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user