aboutsummaryrefslogtreecommitdiff
path: root/core/math/big
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2021-08-11 12:31:55 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2021-08-11 20:59:54 +0200
commit851780b8f449847953c49e59d7ce401f2d53c779 (patch)
tree4bdfbd3ca92e3ce590723a90deef9ac673d41fd6 /core/math/big
parent5f34ff9f9f6bdbc62d6111f85167229ac8440747 (diff)
big: Add arguments and usage to test.py.
Diffstat (limited to 'core/math/big')
-rw-r--r--core/math/big/api.odin4
-rw-r--r--core/math/big/common.odin2
-rw-r--r--core/math/big/example.odin2
-rw-r--r--core/math/big/helpers.odin2
-rw-r--r--core/math/big/internal.odin2
-rw-r--r--core/math/big/logical.odin2
-rw-r--r--core/math/big/prime.odin4
-rw-r--r--core/math/big/private.odin2
-rw-r--r--core/math/big/public.odin2
-rw-r--r--core/math/big/radix.odin2
-rw-r--r--core/math/big/test.odin2
-rw-r--r--core/math/big/test.py78
-rw-r--r--core/math/big/tune.odin2
13 files changed, 70 insertions, 36 deletions
diff --git a/core/math/big/api.odin b/core/math/big/api.odin
index 047e91335..e1b687c14 100644
--- a/core/math/big/api.odin
+++ b/core/math/big/api.odin
@@ -1,4 +1,4 @@
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
@@ -14,7 +14,7 @@ package big
*/
=== === === === === === === === === === === === === === === === === === === === === === === ===
Basic arithmetic.
- See `basic.odin`.
+ See `public.odin`.
=== === === === === === === === === === === === === === === === === === === === === === === ===
*/
diff --git a/core/math/big/common.odin b/core/math/big/common.odin
index a0cddb88e..bc9f189cf 100644
--- a/core/math/big/common.odin
+++ b/core/math/big/common.odin
@@ -1,4 +1,4 @@
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
diff --git a/core/math/big/example.odin b/core/math/big/example.odin
index 467c4d517..5b9fbb481 100644
--- a/core/math/big/example.odin
+++ b/core/math/big/example.odin
@@ -1,5 +1,5 @@
//+ignore
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
diff --git a/core/math/big/helpers.odin b/core/math/big/helpers.odin
index d0262ba19..14c88be5f 100644
--- a/core/math/big/helpers.odin
+++ b/core/math/big/helpers.odin
@@ -1,4 +1,4 @@
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
diff --git a/core/math/big/internal.odin b/core/math/big/internal.odin
index aac2db9ec..fb4cd6572 100644
--- a/core/math/big/internal.odin
+++ b/core/math/big/internal.odin
@@ -1,5 +1,5 @@
//+ignore
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
diff --git a/core/math/big/logical.odin b/core/math/big/logical.odin
index f72ecb18d..1eb26332a 100644
--- a/core/math/big/logical.odin
+++ b/core/math/big/logical.odin
@@ -1,4 +1,4 @@
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
diff --git a/core/math/big/prime.odin b/core/math/big/prime.odin
index 25d5ddda3..388ac3f98 100644
--- a/core/math/big/prime.odin
+++ b/core/math/big/prime.odin
@@ -1,4 +1,4 @@
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
@@ -8,7 +8,7 @@ package big
For the theoretical underpinnings, see Knuth's The Art of Computer Programming, Volume 2, section 4.3.
The code started out as an idiomatic source port of libTomMath, which is in the public domain, with thanks.
- This file contains basic arithmetic operations like `add`, `sub`, `mul`, `div`, ...
+ This file contains prime finding operations.
*/
/*
diff --git a/core/math/big/private.odin b/core/math/big/private.odin
index 9b5677bb0..0a5cd6163 100644
--- a/core/math/big/private.odin
+++ b/core/math/big/private.odin
@@ -1,4 +1,4 @@
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
diff --git a/core/math/big/public.odin b/core/math/big/public.odin
index 3ab5a8924..b7a00fbc0 100644
--- a/core/math/big/public.odin
+++ b/core/math/big/public.odin
@@ -1,4 +1,4 @@
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
diff --git a/core/math/big/radix.odin b/core/math/big/radix.odin
index e8468851b..01c0489d8 100644
--- a/core/math/big/radix.odin
+++ b/core/math/big/radix.odin
@@ -1,4 +1,4 @@
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
diff --git a/core/math/big/test.odin b/core/math/big/test.odin
index 044a3329e..2846dac6d 100644
--- a/core/math/big/test.odin
+++ b/core/math/big/test.odin
@@ -1,5 +1,5 @@
//+ignore
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
diff --git a/core/math/big/test.py b/core/math/big/test.py
index 8da890e55..b60698881 100644
--- a/core/math/big/test.py
+++ b/core/math/big/test.py
@@ -6,32 +6,66 @@ import platform
import time
import gc
from enum import Enum
+import argparse
+
+parser = argparse.ArgumentParser(
+ description = "Odin core:math/big test suite",
+ epilog = "By default we run regression and random tests with preset parameters.",
+ formatter_class = argparse.ArgumentDefaultsHelpFormatter,
+)
#
-# Normally, we report the number of passes and fails.
-# With EXIT_ON_FAIL set, we exit at the first fail.
+# Normally, we report the number of passes and fails. With this option set, we exit at first fail.
#
-EXIT_ON_FAIL = True
-EXIT_ON_FAIL = False
-
+parser.add_argument(
+ "-exit-on-fail",
+ help = "Exit when a test fails",
+ action = "store_true",
+)
#
-# We skip randomized tests altogether if NO_RANDOM_TESTS is set.
+# We skip randomized tests altogether if this is set.
#
-NO_RANDOM_TESTS = True
-NO_RANDOM_TESTS = False
+no_random = parser.add_mutually_exclusive_group()
+
+no_random.add_argument(
+ "-no-random",
+ help = "No random tests",
+ action = "store_true",
+)
#
-# If TIMED_TESTS == False and FAST_TESTS == True, we cut down the number of iterations.
-# See below.
+# Normally we run a given number of cycles on each test.
+# Timed tests budget 1 second per 20_000 bits instead.
+#
+# For timed tests we budget a second per `n` bits and iterate until we hit that time.
#
-FAST_TESTS = True
+timed_or_fast = no_random.add_mutually_exclusive_group()
+
+timed_or_fast.add_argument(
+ "-timed",
+ type = bool,
+ default = False,
+ help = "Timed tests instead of a preset number of iterations.",
+)
+parser.add_argument(
+ "-timed-bits",
+ type = int,
+ metavar = "BITS",
+ default = 20_000,
+ help = "Timed tests. Every `BITS` worth of input is given a second of running time.",
+)
#
-# For timed tests we budget a second per `n` bits and iterate until we hit that time.
-# Otherwise, we specify the number of iterations per bit depth in BITS_AND_ITERATIONS.
+# For normal tests (non-timed), `-fast-tests` cuts down on the number of iterations.
#
-TIMED_TESTS = False
-TIMED_BITS_PER_SECOND = 20_000
+timed_or_fast.add_argument(
+ "-fast-tests",
+ help = "Cut down on the number of iterations of each test",
+ default = True,
+ action = "store_true",
+)
+
+args = parser.parse_args()
#
# How many iterations of each random test do we want to run?
@@ -43,12 +77,12 @@ BITS_AND_ITERATIONS = [
(12_000, 10),
]
-if FAST_TESTS:
+if args.fast_tests:
for k in range(len(BITS_AND_ITERATIONS)):
b, i = BITS_AND_ITERATIONS[k]
BITS_AND_ITERATIONS[k] = (b, i // 10 if i >= 100 else 5)
-if NO_RANDOM_TESTS:
+if args.no_random:
BITS_AND_ITERATIONS = []
#
@@ -70,7 +104,7 @@ UNTIL_TIME = 0
UNTIL_ITERS = 0
def we_iterate():
- if TIMED_TESTS:
+ if args.timed:
return TOTAL_TIME < UNTIL_TIME
else:
global UNTIL_ITERS
@@ -178,7 +212,7 @@ def test(test_name: "", res: Res, param=[], expected_error = Error.Okay, expecte
print(error, flush=True)
passed = False
- if EXIT_ON_FAIL and not passed: exit(res.err)
+ if args.exit_on_fail and not passed: exit(res.err)
return passed
@@ -488,7 +522,7 @@ TESTS = {
],
}
-if not FAST_TESTS:
+if not args.fast_tests:
TESTS[test_factorial].append(
# This one on its own takes around 800ms, so we exclude it for FAST_TESTS
[ 100_000 ],
@@ -517,7 +551,7 @@ for test_proc in TESTS:
res = test_proc(*t)
if __name__ == '__main__':
- print("---- math/big tests ----")
+ print("\n---- math/big tests ----")
print()
for test_proc in TESTS:
@@ -566,7 +600,7 @@ if __name__ == '__main__':
if test_proc == test_root_n and BITS == 1_200:
UNTIL_ITERS /= 10
- UNTIL_TIME = TOTAL_TIME + BITS / TIMED_BITS_PER_SECOND
+ UNTIL_TIME = TOTAL_TIME + BITS / args.timed_bits
# We run each test for a second per 20k bits
index = 0
diff --git a/core/math/big/tune.odin b/core/math/big/tune.odin
index 59f533d44..a51c04a78 100644
--- a/core/math/big/tune.odin
+++ b/core/math/big/tune.odin
@@ -1,5 +1,5 @@
//+ignore
-package big
+package math_big
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.