|
1 | | -# Copyright 2023-2024 iiPython |
| 1 | +# Copyright (c) 2024 iiPython |
2 | 2 |
|
3 | 3 | # Modules |
4 | | -import sys |
5 | | -import pathlib |
6 | | -sys.path.insert(1, str(pathlib.Path(__file__).parent.parent.resolve())) |
7 | | - |
8 | | -# Start testing |
9 | | -from tests import start_tests |
10 | | -start_tests("Math", [ |
11 | | - |
12 | | - # Addition testing |
13 | | - ("add 2 3", 5), |
14 | | - ("add 0.1 0.2", .1 + .2), |
15 | | - ("add 0.25 (add 1 0.5)", 1.75), |
16 | | - ("add 2 (8 + 10)", 20), |
17 | | - ("add 1 (.1 + .2 + .3 + .4)", 2), |
18 | | - ("add (7 + 4 + (2 + (5 + 2))) (8 + 9 + 2)", 39), |
19 | | - |
20 | | - # Subtraction testing |
21 | | - ("sub 2 3", -1), |
22 | | - ("sub 0.1 0.2", -.1), |
23 | | - ("sub 0.25 (sub 1 0.5)", -.25), |
24 | | - ("sub 2 (8 - 10)", 4), |
25 | | - ("sub 1 (.1 - .2 - .3 - .4)", 1.8), |
26 | | - ("sub (7 - 4 - (2 - (5 - 2))) (8 - 9 - 2)", 7), |
27 | | - |
28 | | - # Multiplication testing |
29 | | - ("mul 2 3", 6), |
30 | | - ("mul 0.1 0.2", .1 * .2), |
31 | | - ("mul 0.25 (mul 1 0.5)", .125), |
32 | | - ("mul 2 (8 * 10)", 160), |
33 | | - ("mul 1 (.1 * .2 * .3 * .4)", .1 * .2 * .3 * .4), |
34 | | - ("mul (7 * 4 * (2 * (5 * 2))) (8 * 9 * 2)", 80640), |
35 | | - |
36 | | - # Division testing |
37 | | - ("div 2 3", 2 / 3), |
38 | | - ("div 0.1 0.2", .1 / .2), |
39 | | - ("div 0.25 (div 1 0.5)", .125), |
40 | | - ("div 2 (8 / 10)", 2.5), |
41 | | - ("div 1 (.1 / .2 / .3 / .4)", .24), |
42 | | - ("div (7 / 4 / (2 / (5 / 2))) (8 / 9 / 2)", 4.921875), |
43 | | -]) |
| 4 | +from xpp.modules.ops.stdlib.math import XOperators |
| 5 | + |
| 6 | +from . import run, full_evaluate |
| 7 | + |
| 8 | +# Begin test definitions |
| 9 | +def test_add(): |
| 10 | + full_evaluate(XOperators.add, [1, 2, 3], 6) |
| 11 | + |
| 12 | +def test_dec(): |
| 13 | + full_evaluate(XOperators.dec, [5], 4) |
| 14 | + |
| 15 | +def test_div(): |
| 16 | + full_evaluate(XOperators.div, [1, 2], .5) |
| 17 | + |
| 18 | +def test_inc(): |
| 19 | + full_evaluate(XOperators.inc, [5], 6) |
| 20 | + |
| 21 | +def test_mul(): |
| 22 | + full_evaluate(XOperators.mul, [5, 3], 15) |
| 23 | + |
| 24 | +def test_pow(): |
| 25 | + full_evaluate(XOperators.pow, [5, 2], 25) |
| 26 | + |
| 27 | +def test_rnd(): |
| 28 | + full_evaluate(XOperators.rnd, [0.3], 0) |
| 29 | + full_evaluate(XOperators.rnd, [0.7], 1) |
| 30 | + full_evaluate(XOperators.rnd, [0.5666, 2], .57) |
| 31 | + full_evaluate(XOperators.rnd, [0.203, 3], .203) |
| 32 | + |
| 33 | +def test_rng(): |
| 34 | + assert isinstance(run(XOperators.rng, [1, 5]), int) |
| 35 | + full_evaluate(XOperators.rng, [1, 1], 1) |
| 36 | + |
| 37 | +def test_sub(): |
| 38 | + full_evaluate(XOperators.sub, [1, 2], -1) |
0 commit comments