aboutsummaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2021-07-28 21:57:49 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2021-08-11 20:59:51 +0200
commitfb6c9af1ae76be61acbc5881ae520ace265bb704 (patch)
tree11d209a5a21c7f2f0c94ba0dd8327754c1a97bb5 /core/math
parent85aa4dd670ce308eaf51b6eefd10dd62a227c998 (diff)
big: Improve tests.
Diffstat (limited to 'core/math')
-rw-r--r--core/math/big/example.odin1
-rw-r--r--core/math/big/test.py51
2 files changed, 43 insertions, 9 deletions
diff --git a/core/math/big/example.odin b/core/math/big/example.odin
index 6dad8ebd7..5857c0a2e 100644
--- a/core/math/big/example.odin
+++ b/core/math/big/example.odin
@@ -67,7 +67,6 @@ print :: proc(name: string, a: ^Int, base := i8(10)) {
demo :: proc() {
// err: Error;
-
// r := &rnd.Rand{};
// rnd.init(r, 12345);
diff --git a/core/math/big/test.py b/core/math/big/test.py
index c0e2c2173..913e0ac24 100644
--- a/core/math/big/test.py
+++ b/core/math/big/test.py
@@ -54,26 +54,61 @@ except:
print("Couldn't find exported function 'test_error_string'")
exit(2)
-def error(res: Res, param=[]):
- if res.err != E_None:
+def test(test_name: "", res: Res, param=[], expected_result = "", expected_error = E_None):
+ had_error = False
+ r = None
+
+ if res.err != expected_error:
error_type = l.test_error_string(res.err).decode('utf-8')
error_loc = res.res.decode('utf-8')
- error_string = "'{}' error in '{}'".format(error_type, error_loc)
+ error_string = "{}: '{}' error in '{}'".format(test_name, error_type, error_loc)
if len(param):
error_string += " with params {}".format(param)
print(error_string, flush=True)
- os._exit(res.err)
+ had_error = True
+ elif res.err == E_None:
+ try:
+ r = res.res.decode('utf-8')
+ except:
+ pass
+
+ r = eval(res.res)
+ if r != expected_result:
+ error_string = "{}: Result was '{}', expected '{}'".format(test_name, r, expected_result)
+ if len(param):
+ error_string += " with params {}".format(param)
+ print(error_string, flush=True)
+ had_error = True
-def test_add_two(a = 0, b = 0, radix = 10):
+ return had_error
+
+def test_add_two(a = 0, b = 0, radix = 10, expected_result = "", expected_error = E_None):
res = add_two(str(a).encode('utf-8'), str(b).encode('utf-8'), radix)
- error(res, [str(a), str(b), radix])
+ return test("test_add_two", res, [str(a), str(b), radix], expected_result, expected_error)
+
+
+ADD_TESTS = [
+ [ 1234, 5432, 10,
+ 6666, E_None, ],
+ [ 1234, 5432, 110,
+ 6666, E_Invalid_Argument, ],
+]
if __name__ == '__main__':
print("---- core:math/big tests ----")
print()
- test_add_two(1234, 5432, 10)
- test_add_two(1234, 5432, 110) \ No newline at end of file
+ count_pass = 0
+ count_fail = 0
+
+ for t in ADD_TESTS:
+ res = test_add_two(*t)
+ if res:
+ count_fail += 1
+ else:
+ count_pass += 1
+
+ print("ADD_TESTS: {} passes, {} failures.".format(count_pass, count_fail)) \ No newline at end of file