Commit MetaInfo

Revisionc5037f3b67b10f5aee43986ba021ea27ead527ee (tree)
Time2022-06-20 04:17:05
AuthorAntoon Pardon <aej@pard...>
CommiterAntoon Pardon

Log Message

Tests shadow the module name

Change Summary

Incremental Difference

diff -r ebd288b2ec05 -r c5037f3b67b1 build
--- a/build Sun Jun 19 17:29:34 2022 +0200
+++ b/build Sun Jun 19 21:17:05 2022 +0200
@@ -7,7 +7,7 @@
77
88 case $PYTHONPATH in
99 */$ENVIRONMENT/bin/python3)
10- break;;
10+ ;;
1111 *)
1212 echo ""
1313 echo "***" $ENVIRONMENT not activated "***"
diff -r ebd288b2ec05 -r c5037f3b67b1 tests/Makefile
--- a/tests/Makefile Sun Jun 19 17:29:34 2022 +0200
+++ b/tests/Makefile Sun Jun 19 21:17:05 2022 +0200
@@ -2,7 +2,7 @@
22 PYTHON=$(wildcard *.py)
33 TESTS=$(wildcard *.py)
44
5-all: .env .utest .mypy .lint Makefile doall
5+all: .utest .mypy .lint Makefile doall
66
77 # release.cfg
88
@@ -11,21 +11,16 @@
1111 clean:
1212 rm .utest .lint .mypy
1313
14- touch yacc.tpy
15-
1614 release.cfg: .utest .mypy .lint Makefile doall
1715 bump -vm release.cfg
1816
19-.env: $(PYTHON) $(TESTS)
20- @/bin/bash -c '[ X$$(type -p python) = X/opt/conda3.10/bin/python ] || ( echo ""; echo "***" conda3.10 not activated "***"; echo "" && exit 1 ) '
21-
2217 .mypy: $(PYTHON) $(TESTS)
2318 mypy $?
2419 #doall mypy $?
2520 touch .mypy
2621
2722 .lint: $(PYTHON) $(TESTS) #$(PTESTS)
28- pylint $?
23+ pylint --disable C0114,C0103,C0116,E0213 $?
2924 #doall pylint $?
3025 touch .lint
3126
diff -r ebd288b2ec05 -r c5037f3b67b1 tests/iterators-tst.py
--- a/tests/iterators-tst.py Sun Jun 19 17:29:34 2022 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
1-
2-from unittest import TestCase, main as unitmain
3-from random import shuffle
4-
5-from typing import List
6-
7-from AGPlib.iterators import PipeIterator, Apply, Map, concat, SubMap
8-
9-def shuffled_range_list(*args) -> List[int]:
10- step = 1
11- start = 0
12- if len(args) == 1:
13- stop = args[0]
14- elif len(args) == 2:
15- start, stop = args
16- else:
17- start, stop, step = args
18- lst = list(range(start, stop, step))
19- shuffle(lst)
20- return lst
21-
22-def cube(nr: int) -> int:
23- return nr * nr * nr
24-
25-def square(nr: int) -> int:
26- return nr * nr
27-
28-def is_odd(nr: int) -> bool:
29- return bool(nr % 2)
30-
31-def collatz(nr: int) -> int:
32- return 3 * nr + 1 if is_odd(nr) else nr // 2
33-
34-def concater(iterable):
35- for sub_iterable in iterable:
36- yield from sub_iterable
37-
38-class PipeCase(TestCase):
39-
40- def test_apply(s):
41- source = shuffled_range_list(100)
42- for function in list, sum:
43- Function = Apply(function)
44- result1 = function(source)
45- result2 = source | Function
46- result3 = source >> Function
47- s.assertEqual(result1, result2)
48- s.assertEqual(result1, result3)
49-
50- def test_map(s):
51- source = shuffled_range_list(100)
52- for function in square, cube, is_odd, collatz:
53- result0 = list(map(function, source))
54- result1 = source | Map(function) | Apply(list)
55- s.assertEqual(result0, result1)
56- result2 = source >> Map(function) >> Apply(list)
57- s.assertEqual(result0, result2)
58-
59- def test_concat(s):
60- List = Apply(list)
61- source_list = [shuffled_range_list(100) for _ in range(100)]
62- result0 = list(concater(source_list))
63- result1 = source_list | concat | List
64- s.assertEqual(result0, result1)
65- result2 = source_list >> concat >> List
66- s.assertEqual(result0, result2)
67-
68- def test_submap(s):
69- List = Apply(list)
70- source_list = [shuffled_range_list(100) for _ in range(100)]
71- for function in square, cube, is_odd, collatz:
72- result0 = [list(map(function, lst)) for lst in source_list]
73- result1 = source_list | SubMap(function) | Map(list) | List
74- result2 = source_list >> SubMap(function) >> Map(list) >> List
75- s.assertEqual(result0, result1)
76- s.assertEqual(result0, result2)
77-
78-unitmain()
diff -r ebd288b2ec05 -r c5037f3b67b1 tests/iterators.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/iterators.py Sun Jun 19 21:17:05 2022 +0200
@@ -0,0 +1,78 @@
1+
2+from unittest import TestCase, main as unitmain
3+from random import shuffle
4+
5+from typing import List
6+
7+from AGPlib.iterators import PipeIterator, Apply, Map, concat, SubMap
8+
9+def shuffled_range_list(*args) -> List[int]:
10+ step = 1
11+ start = 0
12+ if len(args) == 1:
13+ stop = args[0]
14+ elif len(args) == 2:
15+ start, stop = args
16+ else:
17+ start, stop, step = args
18+ lst = list(range(start, stop, step))
19+ shuffle(lst)
20+ return lst
21+
22+def cube(nr: int) -> int:
23+ return nr * nr * nr
24+
25+def square(nr: int) -> int:
26+ return nr * nr
27+
28+def is_odd(nr: int) -> bool:
29+ return bool(nr % 2)
30+
31+def collatz(nr: int) -> int:
32+ return 3 * nr + 1 if is_odd(nr) else nr // 2
33+
34+def concater(iterable):
35+ for sub_iterable in iterable:
36+ yield from sub_iterable
37+
38+class PipeCase(TestCase):
39+
40+ def test_apply(s):
41+ source = shuffled_range_list(100)
42+ for function in list, sum:
43+ Function = Apply(function)
44+ result1 = function(source)
45+ result2 = source | Function
46+ result3 = source >> Function
47+ s.assertEqual(result1, result2)
48+ s.assertEqual(result1, result3)
49+
50+ def test_map(s):
51+ source = shuffled_range_list(100)
52+ for function in square, cube, is_odd, collatz:
53+ result0 = list(map(function, source))
54+ result1 = source | Map(function) | Apply(list)
55+ s.assertEqual(result0, result1)
56+ result2 = source >> Map(function) >> Apply(list)
57+ s.assertEqual(result0, result2)
58+
59+ def test_concat(s):
60+ List = Apply(list)
61+ source_list = [shuffled_range_list(100) for _ in range(100)]
62+ result0 = list(concater(source_list))
63+ result1 = source_list | concat | List
64+ s.assertEqual(result0, result1)
65+ result2 = source_list >> concat >> List
66+ s.assertEqual(result0, result2)
67+
68+ def test_submap(s):
69+ List = Apply(list)
70+ source_list = [shuffled_range_list(100) for _ in range(100)]
71+ for function in square, cube, is_odd, collatz:
72+ result0 = [list(map(function, lst)) for lst in source_list]
73+ result1 = source_list | SubMap(function) | Map(list) | List
74+ result2 = source_list >> SubMap(function) >> Map(list) >> List
75+ s.assertEqual(result0, result1)
76+ s.assertEqual(result0, result2)
77+
78+unitmain()
Show on old repository browser