diff options
Diffstat (limited to 'tests')
28 files changed, 301 insertions, 0 deletions
diff --git a/tests/basics/run-tests b/tests/basics/run-tests index 0c3995da15..bc2969ae3d 100755 --- a/tests/basics/run-tests +++ b/tests/basics/run-tests @@ -42,4 +42,7 @@ echo "$numpassed tests passed" if [[ $numfailed != 0 ]] then echo "$numfailed tests failed -$namefailed" + exit 1 +else + exit 0 fi diff --git a/tests/basics/tests/containment.py b/tests/basics/tests/containment.py new file mode 100644 index 0000000000..84d40b4e8f --- /dev/null +++ b/tests/basics/tests/containment.py @@ -0,0 +1,23 @@ +for i in 1, 2: + for o in {1:2}, {1}, {1:2}.keys(): + print("{} in {}: {}".format(i, o, i in o)) + print("{} not in {}: {}".format(i, o, i not in o)) + +haystack = "supercalifragilistc" +for needle in (haystack[i:] for i in range(len(haystack))): + print(needle, "in", haystack, "::", needle in haystack) + print(needle, "not in", haystack, "::", needle not in haystack) + print(haystack, "in", needle, "::", haystack in needle) + print(haystack, "not in", needle, "::", haystack not in needle) +for needle in (haystack[:i+1] for i in range(len(haystack))): + print(needle, "in", haystack, "::", needle in haystack) + print(needle, "not in", haystack, "::", needle not in haystack) + print(haystack, "in", needle, "::", haystack in needle) + print(haystack, "not in", needle, "::", haystack not in needle) + +# until here, the tests would work without the 'second attempt' iteration thing. + +for i in 1, 2: + for o in [], [1], [1, 2]: + print("{} in {}: {}".format(i, o, i in o)) + print("{} not in {}: {}".format(i, o, i not in o)) diff --git a/tests/basics/tests/enumerate.py b/tests/basics/tests/enumerate.py new file mode 100644 index 0000000000..f2bdf4f326 --- /dev/null +++ b/tests/basics/tests/enumerate.py @@ -0,0 +1,6 @@ +print(list(enumerate([]))) +print(list(enumerate([1, 2, 3]))) +print(list(enumerate([1, 2, 3], 5))) +print(list(enumerate([1, 2, 3], -5))) +print(list(enumerate(range(10000)))) + diff --git a/tests/basics/tests/eval1.py b/tests/basics/tests/eval1.py new file mode 100644 index 0000000000..8b9d02e61b --- /dev/null +++ b/tests/basics/tests/eval1.py @@ -0,0 +1,13 @@ +# builtin eval + +eval('1 + 2') +eval('1 + 2\n') +eval('1 + 2\n\n#comment\n') + +x = 4 +eval('x') + +eval('lambda x: x + 10')(-5) + +y = 6 +eval('lambda: y * 2')() diff --git a/tests/basics/tests/exception1.py b/tests/basics/tests/exception1.py new file mode 100644 index 0000000000..71d5ad3041 --- /dev/null +++ b/tests/basics/tests/exception1.py @@ -0,0 +1,9 @@ +print(repr(IndexError())) +print(str(IndexError())) + +print(repr(IndexError("foo"))) +print(str(IndexError("foo"))) + +a = IndexError(1, "test", [100, 200]) +print(repr(a)) +print(str(a)) diff --git a/tests/basics/tests/filter.py b/tests/basics/tests/filter.py new file mode 100644 index 0000000000..5883e3d00b --- /dev/null +++ b/tests/basics/tests/filter.py @@ -0,0 +1,2 @@ +print(list(filter(lambda x: x & 1, range(-3, 4)))) +print(list(filter(None, range(-3, 4)))) diff --git a/tests/basics/tests/int-small.py b/tests/basics/tests/int-small.py new file mode 100644 index 0000000000..be338c4a4c --- /dev/null +++ b/tests/basics/tests/int-small.py @@ -0,0 +1,26 @@ +# This test small int range for 32-bit machine + +a = 0x3fffff +print(a) +a *= 0x10 +print(a) +a *= 0x10 +print(a) +a += 0xff +print(a) +# This would overflow +#a += 1 + +a = -0x3fffff +print(a) +a *= 0x10 +print(a) +a *= 0x10 +print(a) +a -= 0xff +print(a) +# This still doesn't overflow +a -= 1 +print(a) +# This would overflow +#a -= 1 diff --git a/tests/basics/tests/is-isnot.py b/tests/basics/tests/is-isnot.py new file mode 100644 index 0000000000..990190aa41 --- /dev/null +++ b/tests/basics/tests/is-isnot.py @@ -0,0 +1,14 @@ +print(1 is 1) +print(1 is 2) +print(1 is not 1) +print(1 is not 2) + + +print([1, 2] is [1, 2]) +a = [1, 2] +b = a +print(b is a) + +# TODO: strings require special "is" handling, postponed +# until qstr refactor. +#print("a" is "a") diff --git a/tests/basics/tests/list_compare.py b/tests/basics/tests/list_compare.py new file mode 100644 index 0000000000..eea8814247 --- /dev/null +++ b/tests/basics/tests/list_compare.py @@ -0,0 +1,50 @@ +print([] == []) +print([] > []) +print([] < []) +print([] == [1]) +print([1] == []) +print([] > [1]) +print([1] > []) +print([] < [1]) +print([1] < []) +print([] >= [1]) +print([1] >= []) +print([] <= [1]) +print([1] <= []) + +print([1] == [1]) +print([1] != [1]) +print([1] == [2]) +print([1] == [1, 0]) + +print([1] > [1]) +print([1] > [2]) +print([2] > [1]) +print([1, 0] > [1]) +print([1, -1] > [1]) +print([1] > [1, 0]) +print([1] > [1, -1]) + +print([1] < [1]) +print([2] < [1]) +print([1] < [2]) +print([1] < [1, 0]) +print([1] < [1, -1]) +print([1, 0] < [1]) +print([1, -1] < [1]) + +print([1] >= [1]) +print([1] >= [2]) +print([2] >= [1]) +print([1, 0] >= [1]) +print([1, -1] >= [1]) +print([1] >= [1, 0]) +print([1] >= [1, -1]) + +print([1] <= [1]) +print([2] <= [1]) +print([1] <= [2]) +print([1] <= [1, 0]) +print([1] <= [1, -1]) +print([1, 0] <= [1]) +print([1, -1] <= [1]) diff --git a/tests/basics/tests/map.py b/tests/basics/tests/map.py new file mode 100644 index 0000000000..62dca44ede --- /dev/null +++ b/tests/basics/tests/map.py @@ -0,0 +1,4 @@ +print(list(map(lambda x: x & 1, range(-3, 4)))) +print(list(map(abs, range(-3, 4)))) +print(list(map(set, [[i] for i in range(-3, 4)]))) +print(list(map(pow, range(4), range(4)))) diff --git a/tests/basics/tests/set_add.py b/tests/basics/tests/set_add.py new file mode 100644 index 0000000000..f2a372f307 --- /dev/null +++ b/tests/basics/tests/set_add.py @@ -0,0 +1,5 @@ +s = {1, 2, 3, 4} +print(s.add(5)) +l = list(s) +l.sort() +print(l) diff --git a/tests/basics/tests/set_binop.py b/tests/basics/tests/set_binop.py new file mode 100644 index 0000000000..d0d0b8027b --- /dev/null +++ b/tests/basics/tests/set_binop.py @@ -0,0 +1,30 @@ +def r(s): + l = list(s) + l.sort() + return l +sets = [set(), {1}, {1, 2}, {1, 2, 3}, {2, 3}, {2, 3, 5}, {5}, {7}] +for s in sets: + for t in sets: + print(s, '|', t, '=', r(s | t)) + print(s, '^', t, '=', r(s ^ t)) + print(s, '&', t, '=', r(s & t)) + print(s, '-', t, '=', r(s - t)) + u = s.copy() + u |= t + print(s, "|=", t, '-->', r(u)) + u = s.copy() + u ^= t + print(s, "^=", t, '-->', r(u)) + u = s.copy() + u &= t + print(s, "&=", t, "-->", r(u)) + u = s.copy() + u -= t + print(s, "-=", t, "-->", r(u)) + + print(s, '==', t, '=', s == t) + print(s, '!=', t, '=', s != t) + print(s, '>', t, '=', s > t) + print(s, '>=', t, '=', s >= t) + print(s, '<', t, '=', s < t) + print(s, '<=', t, '=', s <= t) diff --git a/tests/basics/tests/set_clear.py b/tests/basics/tests/set_clear.py new file mode 100644 index 0000000000..6fda93f0fb --- /dev/null +++ b/tests/basics/tests/set_clear.py @@ -0,0 +1,3 @@ +s = {1, 2, 3, 4} +print(s.clear()) +print(list(s)) diff --git a/tests/basics/tests/set_copy.py b/tests/basics/tests/set_copy.py new file mode 100644 index 0000000000..2ea308b0db --- /dev/null +++ b/tests/basics/tests/set_copy.py @@ -0,0 +1,8 @@ +s = {1, 2, 3, 4} +t = s.copy() +s.add(5) +t.add(7) +for i in s, t: + l = list(i) + l.sort() + print(l) diff --git a/tests/basics/tests/set_difference.py b/tests/basics/tests/set_difference.py new file mode 100644 index 0000000000..26976116f3 --- /dev/null +++ b/tests/basics/tests/set_difference.py @@ -0,0 +1,21 @@ +def report(s): + l = list(s) + l.sort() + print(l) + +l = [1, 2, 3, 4] +s = set(l) +outs = [s.difference(), + s.difference({1}), + s.difference({1}, [1, 2]), + s.difference({1}, {1, 2}, {2, 3})] +for out in outs: + report(out) + +s = set(l) +print(s.difference_update()) +report(s) +print(s.difference_update({1})) +report(s) +print(s.difference_update({1}, [2])) +report(s) diff --git a/tests/basics/tests/set_discard.py b/tests/basics/tests/set_discard.py new file mode 100644 index 0000000000..baac26413c --- /dev/null +++ b/tests/basics/tests/set_discard.py @@ -0,0 +1,3 @@ +s = {1, 2} +print(s.discard(1)) +print(list(s)) diff --git a/tests/basics/tests/set_intersection.py b/tests/basics/tests/set_intersection.py new file mode 100644 index 0000000000..6f3dfc7414 --- /dev/null +++ b/tests/basics/tests/set_intersection.py @@ -0,0 +1,12 @@ +def report(s): + l = list(s) + l.sort() + print(l) + +s = {1, 2, 3, 4} +report(s) +report(s.intersection({1, 3})) +report(s.intersection([3, 4])) + +print(s.intersection_update([1])) +report(s) diff --git a/tests/basics/tests/set_isdisjoint.py b/tests/basics/tests/set_isdisjoint.py new file mode 100644 index 0000000000..7fb7e769bb --- /dev/null +++ b/tests/basics/tests/set_isdisjoint.py @@ -0,0 +1,6 @@ +s = {1, 2, 3, 4} +print(s.isdisjoint({1})) +print(s.isdisjoint([2])) +print(s.isdisjoint([])) +print(s.isdisjoint({7,8,9,10})) +print(s.isdisjoint([7,8,9,1])) diff --git a/tests/basics/tests/set_isfooset.py b/tests/basics/tests/set_isfooset.py new file mode 100644 index 0000000000..ce7952cd2c --- /dev/null +++ b/tests/basics/tests/set_isfooset.py @@ -0,0 +1,5 @@ +sets = [set(), {1}, {1, 2, 3}, {3, 4, 5}, {5, 6, 7}] +for i in sets: + for j in sets: + print(i.issubset(j)) + print(i.issuperset(j)) diff --git a/tests/basics/tests/set_iter.py b/tests/basics/tests/set_iter.py new file mode 100644 index 0000000000..2960177303 --- /dev/null +++ b/tests/basics/tests/set_iter.py @@ -0,0 +1,5 @@ +s = {1, 2, 3, 4} +l = list(s) +l.sort() +print(l) + diff --git a/tests/basics/tests/set_pop.py b/tests/basics/tests/set_pop.py new file mode 100644 index 0000000000..0cd478ce25 --- /dev/null +++ b/tests/basics/tests/set_pop.py @@ -0,0 +1,9 @@ +s = {1} +print(s.pop()) +try: + print(s.pop(), "!!!") +except KeyError: + pass +else: + print("Failed to raise KeyError") + diff --git a/tests/basics/tests/set_remove.py b/tests/basics/tests/set_remove.py new file mode 100644 index 0000000000..208ab137f3 --- /dev/null +++ b/tests/basics/tests/set_remove.py @@ -0,0 +1,9 @@ +s = {1} +print(s.remove(1)) +print(list(s)) +try: + print(s.remove(1), "!!!") +except KeyError: + pass +else: + print("failed to raise KeyError") diff --git a/tests/basics/tests/set_symmetric_difference.py b/tests/basics/tests/set_symmetric_difference.py new file mode 100644 index 0000000000..acf298385a --- /dev/null +++ b/tests/basics/tests/set_symmetric_difference.py @@ -0,0 +1,7 @@ +print({1,2}.symmetric_difference({2,3})) +print({1,2}.symmetric_difference([2,3])) +s = {1,2} +print(s.symmetric_difference_update({2,3})) +l = list(s) +l.sort() +print(l) diff --git a/tests/basics/tests/set_union.py b/tests/basics/tests/set_union.py new file mode 100644 index 0000000000..2adcc972c0 --- /dev/null +++ b/tests/basics/tests/set_union.py @@ -0,0 +1 @@ +print({1}.union({2})) diff --git a/tests/basics/tests/set_update.py b/tests/basics/tests/set_update.py new file mode 100644 index 0000000000..78cd763560 --- /dev/null +++ b/tests/basics/tests/set_update.py @@ -0,0 +1,12 @@ +def report(s): + l = list(s) + l.sort() + print(l) + +s = {1} +s.update() +report(s) +s.update([2]) +report(s) +s.update([1,3], [2,2,4]) +report(s) diff --git a/tests/basics/tests/sorted.py b/tests/basics/tests/sorted.py new file mode 100644 index 0000000000..bbec319460 --- /dev/null +++ b/tests/basics/tests/sorted.py @@ -0,0 +1,2 @@ +print(sorted(set(range(100)))) +print(sorted(set(range(100)), key=lambda x: x + 100*(x % 2))) diff --git a/tests/basics/tests/string_find.py b/tests/basics/tests/string_find.py new file mode 100644 index 0000000000..90063228f8 --- /dev/null +++ b/tests/basics/tests/string_find.py @@ -0,0 +1,11 @@ +print("hello world".find("ll")) +print("hello world".find("ll", None)) +print("hello world".find("ll", 1)) +print("hello world".find("ll", 1, None)) +print("hello world".find("ll", None, None)) +print("hello world".find("ll", 1, -1)) +print("hello world".find("ll", 1, 1)) +print("hello world".find("ll", 1, 2)) +print("hello world".find("ll", 1, 3)) +print("hello world".find("ll", 1, 4)) +print("hello world".find("ll", 1, 5)) diff --git a/tests/basics/tests/zip.py b/tests/basics/tests/zip.py new file mode 100644 index 0000000000..c0109094f4 --- /dev/null +++ b/tests/basics/tests/zip.py @@ -0,0 +1,2 @@ +print(list(zip())) +print(list(zip([1], {2,3}))) |