diff --git a/test/builtins_auto/container_test.act b/test/builtins_auto/container_test.act deleted file mode 100644 index 64b9e66f1..000000000 --- a/test/builtins_auto/container_test.act +++ /dev/null @@ -1,7 +0,0 @@ -actor main(env): - lst = list(range(1, 100)) - if 17 not in lst or 171 in lst or 100 in lst: - env.exit(1) - env.exit(0) - - diff --git a/test/builtins_auto/dict.act b/test/builtins_auto/dict.act deleted file mode 100644 index c8fc920e6..000000000 --- a/test/builtins_auto/dict.act +++ /dev/null @@ -1,129 +0,0 @@ - - -actor main(env): - # Basic tests with str keys - d: dict[str, str] = {"a": "A"} - - d["b"] = "B" - if d != {"a": "A", "b": "B"}: - print("Unexpected result of dict[\"b\"]=\"b\":", d) - env.exit(1) - - if len(d) != 2: - print("Unexpected result of len(d):", len(d)) - env.exit(1) - - if list(d.keys()) != ["a", "b"]: - print("Unexpected result of d.keys():", d.keys()) - env.exit(1) - - if repr(list(d.items())) != repr([("a", "A"), ("b", "B")]): - print("Unexpected result of d.items():", d.items()) - env.exit(1) - - if list(d.values()) != ["A", "B"]: - print("Unexpected result of d.values():", d.values()) - env.exit(1) - - del d["b"] - if d != {"a": "A"}: - print("Unexpected result of del dict[\"b\"]:", d) - env.exit(1) - - d["pop"] = "123" - - q = d.pop("pop") - if q != "123": - print("Unexpected result of d.pop(\"pop\"):", q) - env.exit(1) - - q = d.pop("pop") - if q != None: - print("Unexpected result of d.pop(\"pop\"):", q) - env.exit(1) - - d["pop"] = "123" - - q = d.pop_def("pop","5") - if q != "123": - print("Unexpected result of d.pop(\"pop\"):", q) - env.exit(1) - - p = d.pop_def("pop","5") - if p != "5": - print("Unexpected result of d.pop(\"pop\"):", p) - env.exit(1) - - d["popi"] = "POPI" - pi = d.popitem() - if pi.0 != "popi" and pi.1 != "POPI": - print("Unexpected result of d.popitem():", str(pi.0), str(pi.1)) - env.exit(1) - - g = d.get_def("a", "") - if g != "A": - print("Unexpected result of d.get(\"a\"):", g) - env.exit(1) - - d.update({"c": "C"}.items()) - if d != {"a": "A", "c": "C"}: - print("Unexpected result of dict.update():", d) - env.exit(1) - - sd = d.setdefault("setdef", "a") - if sd is None or (sd is not None and sd != "a") or d != {'a':'A', 'c':'C', 'setdef':'a'}: - print("Unexpected result of d.setdefault(\"setdef\", \"a\")") - env.exit(1) - -# Code generation for calls of copy is wrong; the hashwit needed is not supplied. -# d = {'a' : 'A', 'b' : 'B'} -# d2 = d.copy() -# if d2 != {'a' : 'A', 'b' : 'B'}: -# print("Unexpected result of d.copy():", d2) -# env.exit(1) - -# d3 = d -# d.clear() -# if d != {} or d3 != {}: -# print("Unexpected result of d.clear():", d) -# env.exit(1) - - d1 : dict[str,?str] = {"a":"A", "b" : None, "c" : "C"} - del d1["a"] - if d1 != {"b" : None, "c" : "C"}: - print("Unexpected result with None value:", d1) - env.exit(1) - - # Slightly higher scale tests using int key - di = {} - for i in range(1, 1000): - di[str(i)] = str(i+1) - - r = 17 - s = 0 - for j in range(1, 200): - r = r*r % 1000 - s += int(di[str(r)]) - if s != 99446: - env.exit(1) - if str(678) not in di: - env.exit(1) - for i in range(1, 1000): - if i%10 > 0: - del di[str(i)] - if len(di) != 99: - env.exit(1) - t = 0 - for k in di: - t += int(k) - if t != 49500: - env.exit(1) - - other = {} - for j in range(11,200,20): - other[str(j)] = str(2*j) - di.update(other.items()) - if len(di) != 109: - env.exit(1) - - env.exit(0) diff --git a/test/builtins_auto/dict1805.act b/test/builtins_auto/dict1805.act deleted file mode 100644 index 4d4f5dfef..000000000 --- a/test/builtins_auto/dict1805.act +++ /dev/null @@ -1,11 +0,0 @@ -actor main(env): - d: dict[int, str] = {} - d[1] = "one" - d[2] = "two" - del d[2] - d[3] = "three" - del d[1] - print(str(d)) - print(str(d[3])) - env.exit(0) - diff --git a/test/builtins_auto/int.act b/test/builtins_auto/int.act deleted file mode 100644 index 10584e3d3..000000000 --- a/test/builtins_auto/int.act +++ /dev/null @@ -1,280 +0,0 @@ -import testing - -# Test all integer types: -# - i16 -# - i32 -# - i64 -# - u16 -# - u32 -# - u64 -# - int - -# TODO: test that division by zero raises ZeroDivisionError - -def test_i16_divzero(): - n = i16(0) - try: - i16(3) / n - except ZeroDivisionError: - try: - i16(3) // n - except ZeroDivisionError: - return - raise testing.NotRaisesError("expected ZeroDivisionError for i16") - -def test_i32_divzero(): - n = i32(0) - try: - i32(3) / n - except ZeroDivisionError: - try: - i32(3) // n - except ZeroDivisionError: - return - raise testing.NotRaisesError("expected ZeroDivisionError for i32") - -def test_i64_divzero(): - n = i64(0) - try: - i64(3) / n - except ZeroDivisionError: - try: - i64(3) // n - except ZeroDivisionError: - return - raise testing.NotRaisesError("expected ZeroDivisionError for i64") - -def test_u16_divzero(): - n = u16(0) - try: - u16(3) / n - except ZeroDivisionError: - try: - u16(3) // n - except ZeroDivisionError: - return - raise testing.NotRaisesError("expected ZeroDivisionError for u16") - -def test_u32_divzero(): - n = u32(0) - try: - u32(3) / n - except ZeroDivisionError: - try: - u32(3) // n - except ZeroDivisionError: - return - - raise testing.NotRaisesError("expected ZeroDivisionError for u32") - -def test_u64_divzero(): - n = u64(0) - try: - u64(3) / n - except ZeroDivisionError: - try: - u64(3) // n - except ZeroDivisionError: - return - raise testing.NotRaisesError("expected ZeroDivisionError for u64") - - -def test_i16(): - test_i16_divzero() - x: i16 = 0 - if (bool(x != 0)): - raise ValueError("unexpected: bool(x) != 0") - if x != 0: - raise ValueError("unexpected: x != 0") - if i16("1234") != 1234: - raise ValueError('i16("1234") gives wrong result') - if i16("0x1234") != 4660: - raise ValueError('i16("0x1234") gives wrong result') - if i16("0o1234") != 668: - raise ValueError('i16("0o1234") gives wrong result') - if i16("0b1111") != 15: - raise ValueError('i16("0b1111") gives wrong result') - if i16("1234",7) != 466: - raise ValueError('i16("1234",7) gives wrong result') - #if i16(2**15-1) + 1 != -2**15: - # raise ValueError("i16 wraparound failed") - return True - -def test_i32(): - test_i32_divzero() - x: i32 = 0 - if (bool(x != 0)): - raise ValueError("unexpected: bool(x) != 0") - if x != 0: - raise ValueError("unexpected: x != 0") - if i32("1234") != 1234: - raise ValueError('i32("1234") gives wrong result') - if i32("0x1234") != 4660: - raise ValueError('i32("0x1234") gives wrong result') - if i32("0o1234") != 668: - raise ValueError('i32("0o1234") gives wrong result') - if i32("0b1111") != 15: - raise ValueError('i32("0b1111") gives wrong result') - if i32("1234", 7) != 466: - raise ValueError('i32("1234",7) gives wrong result') - if int(x) != 0: - raise ValueError("unexpected: int(x) != 0") - if i32(2**31-1) + 1 != -2**31: - raise ValueError("i32 wraparound failed") - return True - -def test_i64(): - test_i64_divzero() - x: i64 = 0 - if (bool(x != 0)): - raise ValueError("unexpected: bool(x) != 0") - if x != 0: - raise ValueError("unexpected: x != 0") - if i64("1234") != 1234: - raise ValueError('i64("1234") gives wrong result') - if i64("0x1234") != 4660: - raise ValueError('i64("0x1234") gives wrong result') - if i64("0o1234") != 668: - raise ValueError('i64("0o1234") gives wrong result') - if i64("0b1111") != 15: - raise ValueError('i64("0b1111") gives wrong result') - if i64("1234", 7) != 466: - raise ValueError('i64("1234",7) gives wrong result') - if int(x) != 0: - raise ValueError("unexpected: int(x) != 0") - if i64(2**63-1) + 1 != -2**63: - raise ValueError("i64 wraparound failed") - return True - -def test_u16(): - test_u16_divzero() - x: u16 = 0 - if (bool(x != 0)): - raise ValueError("unexpected: bool(x) != 0") - if x != 0: - raise ValueError("unexpected: x != 0") - if u16("1234") != 1234: - raise ValueError('u16("1234") gives wrong result') - if u16("0x1234") != 4660: - raise ValueError('u16("0x1234") gives wrong result') - if u16("0o1234") != 668: - raise ValueError('u16("0o1234") gives wrong result') - if u16("0b1111") != 15: - raise ValueError('u16("0b1111") gives wrong result') - if u16("1234", 7) != 466: - raise ValueError('u16("1234",7) gives wrong result') - if int(x) != 0: - raise ValueError("unexpected: int(x) != 0") - #if u16(2**16-1) + 1 != 0: - # raise ValueError("u16 wraparound failed") - return True - -def test_u32(): - test_u32_divzero() - x: u32 = 0 - if (bool(x != 0)): - raise ValueError("unexpected: bool(x) != 0") - if x != 0: - raise ValueError("unexpected: x != 0") - if u32("1234") != 1234: - raise ValueError('u32("1234") gives wrong result') - if u32("0x1234") != 4660: - raise ValueError('u32("0x1234") gives wrong result') - if u32("0o1234") != 668: - raise ValueError('u32("0o1234") gives wrong result') - if u32("0b1111") != 15: - raise ValueError('u32("0b1111") gives wrong result') - if u32("1234", 7) != 466: - raise ValueError('u32("1234",7) gives wrong result') - if int(x) != 0: - raise ValueError("unexpected: int(x) != 0") - if u32(2**32-1) + 1 != 0: - raise ValueError("u32 wraparound failed") - return True - -def test_u64(): - test_u64_divzero() - x: u64 = 0 - if (bool(x != 0)): - raise ValueError("unexpected: bool(x) != 0") - if x != 0: - raise ValueError("unexpected: x != 0") - if u64("1234") != 1234: - raise ValueError('u64("1234") gives wrong result') - if u64("0x1234") != 4660: - raise ValueError('u64("0x1234") gives wrong result') - if u64("0o1234") != 668: - raise ValueError('u64("0o1234") gives wrong result') - if u64("0b1111") != 15: - raise ValueError('u64("0b1111") gives wrong result') - if u64("1234",7) != 466: - raise ValueError('u64("1234",7) gives wrong result') - if int(x) != 0: - raise ValueError("unexpected: int(x) != 0") - if u64(2**64-1) + 1 != 0: - raise ValueError("u64 wraparound failed") - return True - - - -def test_int(): - if (141234567898765434567654345678765456787654 << 12) != 578496790113343219989112199900223311002230784: - raise ValueError("left shift of positive int broken") - if (-141234567898765434567654345678765456787654 << 12) != -578496790113343219989112199900223311002230784: - raise ValueError("left shift of negative int broken") - if (141234567898765434567654345678765456787654 >> 12) != 34481095678409529923743736737979847848: - raise ValueError("right shift of positive int broken") - if (-141234567898765434567654345678765456787654 >> 12) != -34481095678409529923743736737979847848: - raise ValueError("right shift of negative int broken") - if (123457665434567898765434567876545678765456789876587678767876789876578456787645676543456765435 >> 100) != 97390925711186052433660104097118587966803147032967724376831828: - raise ValueError("right shift of positive int broken") - if int(1.23456789e15) != 1234567890000000: - raise ValueError("int() of float e15 not working") - if int(1.23456789e150) != 1234567889999999836491654725378050829066454385249330908721879362956247951768828819773169753596449374655959952724750267483926250851143576906326291251200: - raise ValueError("int() of float e150 not working") - if abs (10**500/10**500 - 1) > 1e-100: - raise ValueError("10**500/10**500 != 1") - if (round(123456789, 10)) != 1.23456789e8: - raise ValueError("round(123456789, 10) != 1.23456789e8") - if round(123456789, -4) != 123460000: - raise ValueError("round(123456789, -10) != 1234567890000000000") - if round(-123456789, -4) != -123460000: - raise ValueError("round(-123456789, -10) != -1234567890000000000") - if int('123') != 123: - raise ValueError("int('123') != 123") - if hash(2**131) >= 2**64: - raise ValueError("hash(2**131) too big") - if int("1234") != 1234: - raise ValueError('int("1234") gives wrong result') - if int("0x1234") != 4660: - raise ValueError('int("0x1234") gives wrong result') - if int("0o1234") != 668: - raise ValueError('int("0o1234") gives wrong result') - if int("0b1111") != 15: - raise ValueError('int("0b1111") gives wrong result') - if int("1234",7) != 466: - raise ValueError('int("1234",7) gives wrong result') - if int(" -0x34ac53ba0976ae3345A4E8765CCD2345",16) != -70014629019847787457594182942686257989: - raise ValueError('int(" -0x34ac53ba0976ae3345A4E8765CCD2345",16) gives wrong result') - if int("123rtgvhu7654erfghjuyt54567ujhgfrtyujhgvfc3456ytyhgt54edf",36) != 1505279714924572685646656049328765658872190236487877560661160764208141566553212677331651: - raise ValueError('int("123rtgvhu7654erfghjuyt54567ujhgfrtyujhgvfc3456ytyhgt54edf",36) gives wrong result') - if int("0") != 0: - raise ValueError('int("0") gives wrong result') - if int("1234567890abcdef" * 100,16) != 0x1234567890abcdef * (2**6400)//(2**64-1): - raise ValueError('int("1234567890abcdef" * 100,16) gives wrong result') - if int('1'* 10000,2) != 2**10000 - 1: - raise ValueError("int('1'* 10000,2) gives wrong result") - -actor main(env): - try: - test_int() - test_i16() - test_i32() - test_i64() - test_u16() - test_u32() - test_u64() - env.exit(0) - except Exception as e: - print(e) - env.exit(1) diff --git a/test/builtins_auto/list.act b/test/builtins_auto/list.act deleted file mode 100644 index daf943af5..000000000 --- a/test/builtins_auto/list.act +++ /dev/null @@ -1,159 +0,0 @@ -import testing - -"""Test lists -""" - -def test_list_index(): - l = [1, 2, 3, 1, 2, 5, 1] - if l.index(1) != 0: - raise testing.NotEqualError(0, l.index(1)) - - if l.index(2) != 1: - raise testing.NotEqualError(1, l.index(2)) - - if l.index(1, 1) != 3: - raise testing.NotEqualError(0, l.index(1, 1)) - - try: - l.index(3, 3) - except KeyError: - pass - -def test_list_index_errs(): - l = [1, 2, 3] - try: - l.index(1, -1) - except ValueError: - try: - l.index(1, 4) - except ValueError: - try: - l.index(1, 1, -1) - except ValueError: - try: - l.index(1, 1, 0) - except ValueError: - try: - l.index(1, 1, 1) - except ValueError: - return - raise testing.NotRaisesError("expected ValueError for l.index(...)") - - -actor main(env): - try: - test_list_index() - test_list_index_errs() - except Exception as e: - print("Unexpected exception", e) - await async env.exit(1) - l: list[int] = [1, 2] - - l.append(3) - if l != [1, 2, 3]: - print("Unexpected result of list.append(3):", l) - await async env.exit(1) - - l.insert(0, 0) - if l != [0, 1, 2, 3]: - print("Unexpected result of list.insert(0, 0):", l) - await async env.exit(1) - - l.insert(2, 37) - if l != [0, 1, 37, 2, 3]: - print("Unexpected result of list.insert(2, 37):", l) - await async env.exit(1) - - if l.index(37) != 2: - print("Unexpected result of list.index(37):", l) - await async env.exit(1) - - l2 = l.copy() - if l2 != [0, 1, 37, 2, 3]: - print("Unexpected result of list.copy():", l2) - await async env.exit(1) - -# c = l.count(37, None, None) -# if c != 1: -# print("Unexpected result of list.count(37):", c) -# await async env.exit(1) - - l.extend([45, 56]) - if l != [0, 1, 37, 2, 3, 45, 56]: - print("Unexpected result of list.extend([45, 56]):", l) - await async env.exit(1) - - l.reverse() - if l != [56, 45, 3, 2, 37, 1, 0]: - print("Unexpected result of list.reverse():", l) - await async env.exit(1) - - lr = list(reversed([])) - if lr != []: - print("Unexpected result of reversed([]):", lr) - await async env.exit(1) - - lr2 = list(reversed([1])) - if lr2 != [1]: - print("Unexpected result of reversed([]):", lr2) - await async env.exit(1) - - lr3 = list(reversed([1,2,3])) - if lr3 != [3,2,1]: - print("Unexpected result of reversed([1,2,3]):", lr3) - await async env.exit(1) - - del l[1] - if l != [56, 3, 2, 37, 1, 0]: - print("Unexpected result of del list[1]:", l) - await async env.exit(1) - - l.pop(-1) - if l != [56, 3, 2, 37, 1]: - print("Unexpected result of list.pop():", l) - await async env.exit(1) - -# l.remove(37) -# if l != [3, 1]: -# print("Unexpected result of list.remove(37):", l) -# await async env.exit(1) - - - l.clear() - if l != []: - print("Unexpected result of list.clear():", l) - await async env.exit(1) - -# sorted - l = [56, 3, 2, 37, 1] - if sorted(l) != [1, 2, 3, 37, 56]: - print("Unexpected result of sorted(l):", sorted(l)) - await async env.exit(1) - - if bool([]): - print("Unexpected result of bool([]):", l) - await async env.exit(1) - -#shrinking - l = list(range(30)) - for i in range(20): - l.pop(-1) - if len(l) != 10 or l[4] != 4: - print("Unexpected shrinking of list") - await async env.exit(1) - - print([1] + []) - if [1] + [2] != [1,2]: - raise ValueError("unexpected: [1] + [2] != [1,2]") - - if [1] + [] != [1]: - raise ValueError("unexpected: [1] + [] != [1]") - - if [] + [2] != [2]: - raise ValueError("unexpected: [] + [2] != [2]") - - l1 = [] - l2 = [] - l1.extend(l2) - - await async env.exit(0) diff --git a/test/builtins_auto/slice_test.act b/test/builtins_auto/slice_test.act deleted file mode 100644 index c44ea5bf2..000000000 --- a/test/builtins_auto/slice_test.act +++ /dev/null @@ -1,11 +0,0 @@ -actor main(env): - lst = list(range(100)) - lst2 = lst[-1:0:-2] - lst2[10:30:2] = range(100, 110) - lst4 = list(range(1000)) - for i in range(100,1,-1): - del lst4[1:1000:i] - if sum(lst4) != 4500: - env.exit(1) - env.exit(0) - diff --git a/test/builtins_auto/str_slice.act b/test/builtins_auto/str_slice.act deleted file mode 100644 index 4516db1ed..000000000 --- a/test/builtins_auto/str_slice.act +++ /dev/null @@ -1,18 +0,0 @@ - -def test_slice(): - a = "asdf" - b = a[1] - -def test_slice_outside_of_range(): - a = "asdf" - i = 7 - b = a[i:] - -actor main(env): - try: - test_slice() - test_slice_outside_of_range() - env.exit(0) - except Exception as e: - print(e) - env.exit(1) diff --git a/test/builtins_auto/string_interpolation_unicode.act b/test/builtins_auto/string_interpolation_unicode.act deleted file mode 100644 index 73810094b..000000000 --- a/test/builtins_auto/string_interpolation_unicode.act +++ /dev/null @@ -1,8 +0,0 @@ - -actor main(env): - try: - print("✓ Hello, world!") - print("✗ Hello, %s!" % "world") - except: - env.exit(1) - env.exit(0) diff --git a/test/builtins_auto/actor_identity.act b/test/builtins_auto/test_actor_identity.act similarity index 100% rename from test/builtins_auto/actor_identity.act rename to test/builtins_auto/test_actor_identity.act diff --git a/test/builtins_auto/actor_mutarg.act b/test/builtins_auto/test_actor_mutarg.act similarity index 100% rename from test/builtins_auto/actor_mutarg.act rename to test/builtins_auto/test_actor_mutarg.act diff --git a/test/builtins_auto/test_all.act b/test/builtins_auto/test_all.act index 1ce7c8aea..96e5d1b1e 100644 --- a/test/builtins_auto/test_all.act +++ b/test/builtins_auto/test_all.act @@ -1,23 +1,20 @@ - - - - -def test_all1(): +def test_all1() -> bool: stuff = [True, True, True] if all(stuff): - return - raise ValueError("all stuff is True but all() returned False") + return True + print("all stuff is True but all() returned False") + return False -def test_all2(): +def test_all2() -> bool: stuff = [True, False, True] if all(stuff): - raise ValueError("not all stuff is True but all() returned True") + print("not all stuff is True but all() returned True") + return False + return True actor main(env): - try: - test_all1() - test_all2() - env.exit(0) - except Exception as e: - print(e) + if not test_all1(): + env.exit(1) + if not test_all2(): env.exit(1) + env.exit(0) diff --git a/test/builtins_auto/test_any.act b/test/builtins_auto/test_any.act index 59dd58af6..4dbdf56be 100644 --- a/test/builtins_auto/test_any.act +++ b/test/builtins_auto/test_any.act @@ -1,31 +1,29 @@ - - - - -def test_any1(): +def test_any1() -> bool: stuff = [True, True, True] if any(stuff): - return - raise ValueError("all stuff is True but any() returned False") + return True + print("all stuff is True but any() returned False") + return False -def test_any2(): +def test_any2() -> bool: stuff = [True, False, True] if any(stuff): - return - raise ValueError("some stuff is True but any() returned False") + return True + print("some stuff is True but any() returned False") + return False -def test_any3(): +def test_any3() -> bool: stuff = [False, False, False] - if any(stuff): - raise ValueError("no stuff is True but any() returned True") - return + if not any(stuff): + return True + print("no stuff is True but any() returned True") + return False actor main(env): - try: - test_any1() - test_any2() - test_any3() - env.exit(0) - except Exception as e: - print(e) + if not test_any1(): + env.exit(1) + if not test_any2(): + env.exit(1) + if not test_any3(): env.exit(1) + env.exit(0) diff --git a/test/builtins_auto/builtin_functions_test.act b/test/builtins_auto/test_builtin_functions.act similarity index 100% rename from test/builtins_auto/builtin_functions_test.act rename to test/builtins_auto/test_builtin_functions.act diff --git a/test/builtins_auto/test_bytes.act b/test/builtins_auto/test_bytes.act new file mode 100644 index 000000000..dd6740295 --- /dev/null +++ b/test/builtins_auto/test_bytes.act @@ -0,0 +1,99 @@ +def test_bytes_find() -> bool: + b = b"hello, world!" + if b.find(b"world") != 7: + print("bytes.find() did not return the correct index:", b.find(b"world")) + return False + if b.find(b"world", 0) != 7: + print("bytes.find() did not return the correct index:", b.find(b"world")) + return False + if b.find(b"world", 8) != -1: + print("bytes.find() did not return -1 when the substring is not found") + return False + if b.find(b"world", 0, 5) != -1: + print("bytes.find() did not return -1 when the substring is not found") + return False + if b.find(b"world", 0, 7) != -1: + print("bytes.find() did not return -1 when the substring is not found") + return False + if b.find(b"crap") != -1: + print("bytes.find() did not return -1 when the substring is not found") + return False + return True + +def test_bytes_hex() -> bool: + b = b'\xde\xad\xbe\xef' + if b.hex() != "deadbeef": + print("bytes.hex():", b.hex()) + return False + if bytes.from_hex("deadbeef").hex() != "deadbeef": + print("bytes.from_hex():", bytes.from_hex("deadbeef").hex()) + return False + return True + +def test_bytes_strip() -> bool: + b = b"" + a = [b.strip()] + if str(a) != "[b'']": + print("empty bytes failed") + return False + return True + +def test_bytes_slice() -> bool: + a = b"asdf" + b = a[0:1] + if b != b"a": + print("bytes slice did not return the correct character:", b) + return False + return True + +def test_bytes_slice_outside_of_range() -> bool: + a = b"asdf" + i = 6 + b = a[i:] + if b != b'': + print("bytes slice outside of range did not return an empty string:", b) + return False + return True + +def test_bytes_slice_with_start_and_stop() -> bool: + a = b"abcdef" + b = a[1:4] + if b != b'bcd': + print("bytes slice with start and stop did not return the correct substring:", b) + return False + return True + +def test_bytes_slice_with_negative_stop() -> bool: + a = b"abcdef" + b = a[1:-1] + if b != b'bcde': + print("bytes slice with negative stop did not return the correct substring:", b) + return False + return True + +def test_bytes_slice_with_reverse_stepping() -> bool: + a = b"abcdef" + b = a[::-1] + if b != b'fedcba': + print("bytes slice with reverse stepping did not return the correct substring:", b) + return False + return True + +actor main(env: Env): + if not test_bytes_find(): + env.exit(1) + if not test_bytes_hex(): + env.exit(1) + if not test_bytes_strip(): + env.exit(1) + if not test_bytes_slice(): + env.exit(1) + if not test_bytes_slice_outside_of_range(): + env.exit(1) + if not test_bytes_slice_with_start_and_stop(): + env.exit(1) + if not test_bytes_slice_with_negative_stop(): + env.exit(1) + if not test_bytes_slice_with_reverse_stepping(): + env.exit(1) + env.exit(0) diff --git a/test/builtins_auto/test_complex.act b/test/builtins_auto/test_complex.act index c9ecab0aa..d0888ed88 100644 --- a/test/builtins_auto/test_complex.act +++ b/test/builtins_auto/test_complex.act @@ -1,82 +1,94 @@ -def test_complex() -> bool: - # Test basic construction +def test_basic_construction() -> bool: c1 = complex.from_real_imag(3.0, 4.0) if c1.real() != 3.0 or c1.imag() != 4.0: print("Basic construction failed - expected 3.0+4.0i, got:", c1.real(), "+", c1.imag(), "i") return False + return True - # Test zero components +def test_zero_components() -> bool: c2 = complex.from_real_imag(0.0, 0.0) if c2.real() != 0.0 or c2.imag() != 0.0: print("Zero construction failed - expected 0.0+0.0i, got:", c2.real(), "+", c2.imag(), "i") return False + return True - # Test negative components +def test_negative_components() -> bool: c3 = complex.from_real_imag(-1.0, -1.0) if c3.real() != -1.0 or c3.imag() != -1.0: print("Negative construction failed - expected -1.0-1.0i, got:", c3.real(), "+", c3.imag(), "i") return False + return True - # Test addition +def test_addition() -> bool: a = complex.from_real_imag(1.0, 2.0) b = complex.from_real_imag(3.0, 4.0) sum = a + b if sum.real() != 4.0 or sum.imag() != 6.0: print("Addition failed - expected 4.0+6.0i, got:", sum.real(), "+", sum.imag(), "i") return False + return True - # Test subtraction +def test_subtraction() -> bool: + a = complex.from_real_imag(1.0, 2.0) + b = complex.from_real_imag(3.0, 4.0) diff = b - a if diff.real() != 2.0 or diff.imag() != 2.0: print("Subtraction failed - expected 2.0+2.0i, got:", diff.real(), "+", diff.imag(), "i") return False + return True - # Test multiplication - # (1 + 2i)(3 + 4i) = (1×3 - 2×4) + (1×4 + 2×3)i = -5 + 10i +def test_multiplication() -> bool: + a = complex.from_real_imag(1.0, 2.0) + b = complex.from_real_imag(3.0, 4.0) prod = a * b if prod.real() != -5.0 or prod.imag() != 10.0: print("Multiplication failed - expected -5.0+10.0i, got:", prod.real(), "+", prod.imag(), "i") return False + return True - # Test division - # (1 + 2i)/(1 + i) = (1 + 2i)(1 - i)/(1 + i)(1 - i) = (1 - i + 2i - 2i²)/(1 - i²) = (3 + i)/2 +def test_division() -> bool: num = complex.from_real_imag(1.0, 2.0) den = complex.from_real_imag(1.0, 1.0) quot = num / den if abs(quot.real() - 1.5) > 1e-10 or abs(quot.imag() - 0.5) > 1e-10: print("Division failed - expected 1.5+0.5i, got:", quot.real(), "+", quot.imag(), "i") return False + return True - # Test in-place division +def test_in_place_division() -> bool: dividend = complex.from_real_imag(1.0, 2.0) divisor = complex.from_real_imag(1.0, 1.0) dividend /= divisor if abs(dividend.real() - 1.5) > 1e-10 or abs(dividend.imag() - 0.5) > 1e-10: print("In-place division failed - expected 1.5+0.5i, got:", dividend.real(), "+", dividend.imag(), "i") return False + return True - # Test conjugate +def test_conjugate() -> bool: + a = complex.from_real_imag(1.0, 2.0) conj = a.conjugate() if conj.real() != 1.0 or conj.imag() != -2.0: print("Conjugate failed - expected 1.0-2.0i, got:", conj.real(), "+", conj.imag(), "i") return False + return True - # Test absolute value - # |1 + 2i| = √(1² + 2²) = √5 +def test_absolute_value() -> bool: + a = complex.from_real_imag(1.0, 2.0) abs_val = a.__abs__() if abs(abs_val - 2.236067977499790) > 1e-10: print("Absolute value failed - expected ≈2.236067977499790, got:", abs_val) return False + return True - # Test power operation - # (1 + i)² = 1 + 2i - 1 = 2i +def test_power_operation() -> bool: c = complex.from_real_imag(1.0, 1.0) d = c ** complex.from_real_imag(2, 0) if abs(d.real()) > 1e-10 or abs(d.imag() - 2.0) > 1e-10: print("Power operation failed - expected 0.0+2.0i, got:", d.real(), "+", d.imag(), "i") return False + return True - # Test equality and hash consistency +def test_equality_and_hash_consistency() -> bool: c1 = complex.from_real_imag(1.0, 2.0) c2 = complex.from_real_imag(1.0, 2.0) c3 = complex.from_real_imag(2.0, 1.0) @@ -92,44 +104,80 @@ def test_complex() -> bool: if hash(c1) != hash(c2): print("Hash consistency failed - equal numbers have different hashes") return False + return True - # Test division by zero +def test_division_by_zero() -> bool: try: + a = complex.from_real_imag(1.0, 2.0) zero = complex.from_real_imag(0.0, 0.0) bad = a / zero print("Division by zero didn't raise expected exception") return False except ZeroDivisionError: pass # Expected behavior + return True - # Test very large numbers +def test_very_large_numbers() -> bool: large = 1e308 big = complex.from_real_imag(large, large) overflow = big * big if not (overflow.real() == float('inf') or overflow.imag() == float('inf')): print("Large number multiplication failed to handle overflow correctly") return False + return True - # Test very small numbers +def test_very_small_numbers() -> bool: small = 1e-308 tiny = complex.from_real_imag(small, small) underflow = tiny * tiny if not (underflow.real() == 0.0 or abs(underflow.real()) < 1e-307): print("Small number multiplication failed to handle underflow correctly") return False + return True - # Test complex number as dictionary key +def test_complex_as_dict_key() -> bool: + c2 = complex.from_real_imag(1.0, 2.0) + c3 = complex.from_real_imag(2.0, 1.0) e = {} e[c2] = 42 e[c3] = 43 if not (e[c2] == 42 and e[c3] == 43): print("Complex number as dictionary key failed") return False - return True actor main(env): - if test_complex(): - print("All complex number tests passed!") - env.exit(0) - env.exit(1) + if not test_basic_construction(): + env.exit(1) + if not test_zero_components(): + env.exit(1) + if not test_negative_components(): + env.exit(1) + if not test_addition(): + env.exit(1) + if not test_subtraction(): + env.exit(1) + if not test_multiplication(): + env.exit(1) + if not test_division(): + env.exit(1) + if not test_in_place_division(): + env.exit(1) + if not test_conjugate(): + env.exit(1) + if not test_absolute_value(): + env.exit(1) + if not test_power_operation(): + env.exit(1) + if not test_equality_and_hash_consistency(): + env.exit(1) + if not test_division_by_zero(): + env.exit(1) + if not test_very_large_numbers(): + env.exit(1) + if not test_very_small_numbers(): + env.exit(1) + if not test_complex_as_dict_key(): + env.exit(1) + + env.exit(0) diff --git a/test/builtins_auto/test_float.act b/test/builtins_auto/test_float.act new file mode 100644 index 000000000..c799bd900 --- /dev/null +++ b/test/builtins_auto/test_float.act @@ -0,0 +1,12 @@ +def test_float() -> bool: + d = {} + for i in range(-10000, 10000): + f = float(i) + d[f] = hash(f) + print(d) + return True + +actor main(env): + if not test_float(): + env.exit(1) + env.exit(0) diff --git a/test/builtins_auto/test_int.act b/test/builtins_auto/test_int.act new file mode 100644 index 000000000..95e2bad6b --- /dev/null +++ b/test/builtins_auto/test_int.act @@ -0,0 +1,387 @@ +import testing + +# Test all integer types: +# - i16 +# - i32 +# - i64 +# - u16 +# - u32 +# - u64 +# - int + +# TODO: test that division by zero raises ZeroDivisionError + +def test_slice_operations(): + lst = list(range(100)) + lst2 = lst[-1:0:-2] + lst2[10:30:2] = range(100, 110) + if lst2[10] != 100 or lst2[12] != 101: + print("Slice operation test failed") + return False + + lst4 = list(range(1000)) + for i in range(100, 1, -1): + del lst4[1:1000:i] + if sum(lst4) != 4500: + print("Slice deletion test failed") + return False + + return True + +def test_i16_divzero(): + n = i16(0) + try: + i16(3) / n + except ZeroDivisionError: + try: + i16(3) // n + except ZeroDivisionError: + return True + print("expected ZeroDivisionError for i16") + return False + +def test_i32_divzero(): + n = i32(0) + try: + i32(3) / n + except ZeroDivisionError: + try: + i32(3) // n + except ZeroDivisionError: + return True + print("expected ZeroDivisionError for i32") + return False + +def test_i64_divzero(): + n = i64(0) + try: + i64(3) / n + except ZeroDivisionError: + try: + i64(3) // n + except ZeroDivisionError: + return True + print("expected ZeroDivisionError for i64") + return False + +def test_u16_divzero(): + n = u16(0) + try: + u16(3) / n + except ZeroDivisionError: + try: + u16(3) // n + except ZeroDivisionError: + return True + print("expected ZeroDivisionError for u16") + return False + +def test_u32_divzero(): + n = u32(0) + try: + u32(3) / n + except ZeroDivisionError: + try: + u32(3) // n + except ZeroDivisionError: + return True + print("expected ZeroDivisionError for u32") + return False + +def test_u64_divzero(): + n = u64(0) + try: + u64(3) / n + except ZeroDivisionError: + try: + u64(3) // n + except ZeroDivisionError: + return True + print("expected ZeroDivisionError for u64") + return False + +def test_i16(): + if not test_i16_divzero(): + return False + x: i16 = 0 + if (bool(x != 0)): + print("unexpected: bool(x) != 0") + return False + if x != 0: + print("unexpected: x != 0") + return False + if i16("1234") != 1234: + print('i16("1234") gives wrong result') + return False + if i16("0x1234") != 4660: + print('i16("0x1234") gives wrong result') + return False + if i16("0o1234") != 668: + print('i16("0o1234") gives wrong result') + return False + if i16("0b1111") != 15: + print('i16("0b1111") gives wrong result') + return False + if i16("1234",7) != 466: + print('i16("1234",7) gives wrong result') + return False + #if i16(2**15-1) + 1 != -2**15: + # print("i16 wraparound failed") + # return False + return True + +def test_i32(): + if not test_i32_divzero(): + return False + x: i32 = 0 + if (bool(x != 0)): + print("unexpected: bool(x) != 0") + return False + if x != 0: + print("unexpected: x != 0") + return False + if i32("1234") != 1234: + print('i32("1234") gives wrong result') + return False + if i32("0x1234") != 4660: + print('i32("0x1234") gives wrong result') + return False + if i32("0o1234") != 668: + print('i32("0o1234") gives wrong result') + return False + if i32("0b1111") != 15: + print('i32("0b1111") gives wrong result') + return False + if i32("1234", 7) != 466: + print('i32("1234",7) gives wrong result') + return False + if int(x) != 0: + print("unexpected: int(x) != 0") + return False + if i32(2**31-1) + 1 != -2**31: + print("i32 wraparound failed") + return False + return True + +def test_i64(): + if not test_i64_divzero(): + return False + x: i64 = 0 + if (bool(x != 0)): + print("unexpected: bool(x) != 0") + return False + if x != 0: + print("unexpected: x != 0") + return False + if i64("1234") != 1234: + print('i64("1234") gives wrong result') + return False + if i64("0x1234") != 4660: + print('i64("0x1234") gives wrong result') + return False + if i64("0o1234") != 668: + print('i64("0o1234") gives wrong result') + return False + if i64("0b1111") != 15: + print('i64("0b1111") gives wrong result') + return False + if i64("1234", 7) != 466: + print('i64("1234",7) gives wrong result') + return False + if int(x) != 0: + print("unexpected: int(x) != 0") + return False + if i64(2**63-1) + 1 != -2**63: + print("i64 wraparound failed") + return False + return True + +def test_u16(): + if not test_u16_divzero(): + return False + x: u16 = 0 + if (bool(x != 0)): + print("unexpected: bool(x) != 0") + return False + if x != 0: + print("unexpected: x != 0") + return False + if u16("1234") != 1234: + print('u16("1234") gives wrong result') + return False + if u16("0x1234") != 4660: + print('u16("0x1234") gives wrong result') + return False + if u16("0o1234") != 668: + print('u16("0o1234") gives wrong result') + return False + if u16("0b1111") != 15: + print('u16("0b1111") gives wrong result') + return False + if u16("1234", 7) != 466: + print('u16("1234",7) gives wrong result') + return False + if int(x) != 0: + print("unexpected: int(x) != 0") + return False + #if u16(2**16-1) + 1 != 0: + # print("u16 wraparound failed") + # return False + return True + +def test_u32(): + if not test_u32_divzero(): + return False + x: u32 = 0 + if (bool(x != 0)): + print("unexpected: bool(x) != 0") + return False + if x != 0: + print("unexpected: x != 0") + return False + if u32("1234") != 1234: + print('u32("1234") gives wrong result') + return False + if u32("0x1234") != 4660: + print('u32("0x1234") gives wrong result') + return False + if u32("0o1234") != 668: + print('u32("0o1234") gives wrong result') + return False + if u32("0b1111") != 15: + print('u32("0b1111") gives wrong result') + return False + if u32("1234", 7) != 466: + print('u32("1234",7) gives wrong result') + return False + if int(x) != 0: + print("unexpected: int(x) != 0") + return False + if u32(2**32-1) + 1 != 0: + print("u32 wraparound failed") + return False + return True + +def test_u64(): + if not test_u64_divzero(): + return False + x: u64 = 0 + if (bool(x != 0)): + print("unexpected: bool(x) != 0") + return False + if x != 0: + print("unexpected: x != 0") + return False + if u64("1234") != 1234: + print('u64("1234") gives wrong result') + return False + if u64("0x1234") != 4660: + print('u64("0x1234") gives wrong result') + return False + if u64("0o1234") != 668: + print('u64("0o1234") gives wrong result') + return False + if u64("0b1111") != 15: + print('u64("0b1111") gives wrong result') + return False + if u64("1234",7) != 466: + print('u64("1234",7) gives wrong result') + return False + if int(x) != 0: + print("unexpected: int(x) != 0") + return False + if u64(2**64-1) + 1 != 0: + print("u64 wraparound failed") + return False + return True + +def test_int(): + if (141234567898765434567654345678765456787654 << 12) != 578496790113343219989112199900223311002230784: + print("left shift of positive int broken") + return False + if (-141234567898765434567654345678765456787654 << 12) != -578496790113343219989112199900223311002230784: + print("left shift of negative int broken") + return False + if (141234567898765434567654345678765456787654 >> 12) != 34481095678409529923743736737979847848: + print("right shift of positive int broken") + return False + if (-141234567898765434567654345678765456787654 >> 12) != -34481095678409529923743736737979847848: + print("right shift of negative int broken") + return False + if (123457665434567898765434567876545678765456789876587678767876789876578456787645676543456765435 >> 100) != 97390925711186052433660104097118587966803147032967724376831828: + print("right shift of positive int broken") + return False + if int(1.23456789e15) != 1234567890000000: + print("int() of float e15 not working") + return False + if int(1.23456789e150) != 1234567889999999836491654725378050829066454385249330908721879362956247951768828819773169753596449374655959952724750267483926250851143576906326291251200: + print("int() of float e150 not working") + return False + if abs (10**500/10**500 - 1) > 1e-100: + print("10**500/10**500 != 1") + return False + if (round(123456789, 10)) != 1.23456789e8: + print("round(123456789, 10) != 1.23456789e8") + return False + if round(123456789, -4) != 123460000: + print("round(123456789, -10) != 1234567890000000000") + return False + if round(-123456789, -4) != -123460000: + print("round(-123456789, -10) != -1234567890000000000") + return False + if int('123') != 123: + print("int('123') != 123") + return False + if hash(2**131) >= 2**64: + print("hash(2**131) too big") + return False + if int("1234") != 1234: + print('int("1234") gives wrong result') + return False + if int("0x1234") != 4660: + print('int("0x1234") gives wrong result') + return False + if int("0o1234") != 668: + print('int("0o1234") gives wrong result') + return False + if int("0b1111") != 15: + print('int("0b1111") gives wrong result') + return False + if int("1234",7) != 466: + print('int("1234",7) gives wrong result') + return False + if int(" -0x34ac53ba0976ae3345A4E8765CCD2345",16) != -70014629019847787457594182942686257989: + print('int(" -0x34ac53ba0976ae3345A4E8765CCD2345",16) gives wrong result') + return False + if int("123rtgvhu7654erfghjuyt54567ujhgfrtyujhgvfc3456ytyhgt54edf",36) != 1505279714924572685646656049328765658872190236487877560661160764208141566553212677331651: + print('int("123rtgvhu7654erfghjuyt54567ujhgfrtyujhgvfc3456ytyhgt54edf",36) gives wrong result') + return False + if int("0") != 0: + print('int("0") gives wrong result') + return False + if int("1234567890abcdef" * 100,16) != 0x1234567890abcdef * (2**6400)//(2**64-1): + print('int("1234567890abcdef" * 100,16) gives wrong result') + return False + if int('1'* 10000,2) != 2**10000 - 1: + print("int('1'* 10000,2) gives wrong result") + return False + return True + +actor main(env): + if not test_slice_operations(): + env.exit(1) + if not test_int(): + env.exit(1) + if not test_i16(): + env.exit(1) + if not test_i32(): + env.exit(1) + if not test_i64(): + env.exit(1) + if not test_u16(): + env.exit(1) + if not test_u32(): + env.exit(1) + if not test_u64(): + env.exit(1) + env.exit(0) diff --git a/test/builtins_auto/test_list.act b/test/builtins_auto/test_list.act new file mode 100644 index 000000000..791a4188f --- /dev/null +++ b/test/builtins_auto/test_list.act @@ -0,0 +1,211 @@ +import testing + +"""Test lists +""" + +def test_list_index(): + l = [1, 2, 3, 1, 2, 5, 1] + if l.index(1) != 0: + print("test_list_index failed: expected 0, got", l.index(1)) + return False + + if l.index(2) != 1: + print("test_list_index failed: expected 1, got", l.index(2)) + return False + + if l.index(1, 1) != 3: + print("test_list_index failed: expected 3, got", l.index(1, 1)) + return False + + if 3 in l[3:]: + print("test_list_index failed: 3 found in l[3:]") + return False + + return True + +def test_list_index_errs(): + l = [1, 2, 3] + if 1 in l[-1:]: + print("expected ValueError for l.index(1, -1)") + return False + + if 1 in l[4:]: + print("expected ValueError for l.index(1, 4)") + return False + + if 1 in l[1:-1]: + print("expected ValueError for l.index(1, 1, -1)") + return False + + if 1 in l[1:0]: + print("expected ValueError for l.index(1, 1, 0)") + return False + + if 1 in l[1:1]: + print("expected ValueError for l.index(1, 1, 1)") + return False + + return True + +def test_list_append(): + l = [1, 2] + l.append(3) + if l != [1, 2, 3]: + print("test_list_append failed: expected [1, 2, 3], got", l) + return False + return True + +def test_list_insert(): + l = [1, 2, 3] + l.insert(0, 0) + if l != [0, 1, 2, 3]: + print("test_list_insert failed: expected [0, 1, 2, 3], got", l) + return False + + l.insert(2, 37) + if l != [0, 1, 37, 2, 3]: + print("test_list_insert failed: expected [0, 1, 37, 2, 3], got", l) + return False + + if l.index(37) != 2: + print("test_list_insert failed: expected index 2 for 37, got", l.index(37)) + return False + + return True + +def test_list_copy(): + l = [0, 1, 37, 2, 3] + l2 = l.copy() + if l2 != [0, 1, 37, 2, 3]: + print("test_list_copy failed: expected [0, 1, 37, 2, 3], got", l2) + return False + return True + +def test_list_extend(): + l = [0, 1, 37, 2, 3] + l.extend([45, 56]) + if l != [0, 1, 37, 2, 3, 45, 56]: + print("test_list_extend failed: expected [0, 1, 37, 2, 3, 45, 56], got", l) + return False + return True + +def test_list_reverse(): + l = [0, 1, 37, 2, 3, 45, 56] + l.reverse() + if l != [56, 45, 3, 2, 37, 1, 0]: + print("test_list_reverse failed: expected [56, 45, 3, 2, 37, 1, 0], got", l) + return False + return True + +def test_list_reversed(): + lr = list(reversed([])) + if lr != []: + print("test_list_reversed failed: expected [], got", lr) + return False + + lr2 = list(reversed([1])) + if lr2 != [1]: + print("test_list_reversed failed: expected [1], got", lr2) + return False + + lr3 = list(reversed([1, 2, 3])) + if lr3 != [3, 2, 1]: + print("test_list_reversed failed: expected [3, 2, 1], got", lr3) + return False + + return True + +def test_list_del(): + l = [56, 45, 3, 2, 37, 1, 0] + del l[1] + if l != [56, 3, 2, 37, 1, 0]: + print("test_list_del failed: expected [56, 3, 2, 37, 1, 0], got", l) + return False + return True + +def test_list_pop(): + l = [56, 3, 2, 37, 1, 0] + l.pop(-1) + if l != [56, 3, 2, 37, 1]: + print("test_list_pop failed: expected [56, 3, 2, 37, 1], got", l) + return False + return True + +def test_list_clear(): + l = [56, 3, 2, 37, 1] + l.clear() + if l != []: + print("test_list_clear failed: expected [], got", l) + return False + return True + +def test_sorted(): + l = [56, 3, 2, 37, 1] + if sorted(l) != [1, 2, 3, 37, 56]: + print("test_sorted failed: expected [1, 2, 3, 37, 56], got", sorted(l)) + return False + return True + +def test_bool(): + if bool([]): + print("test_bool failed: expected False, got True") + return False + return True + +def test_shrinking(): + l = list(range(30)) + for i in range(20): + l.pop(-1) + if len(l) != 10 or l[4] != 4: + print("test_shrinking failed: unexpected shrinking of list") + return False + return True + +def test_list_addition(): + if [1] + [2] != [1, 2]: + print("test_list_addition failed: expected [1, 2], got", [1] + [2]) + return False + + if [1] + [] != [1]: + print("test_list_addition failed: expected [1], got", [1] + []) + return False + + if [] + [2] != [2]: + print("test_list_addition failed: expected [2], got", [] + [2]) + return False + + return True + +actor main(env): + if not test_list_index(): + env.exit(1) + if not test_list_index_errs(): + env.exit(1) + if not test_list_append(): + env.exit(1) + if not test_list_insert(): + env.exit(1) + if not test_list_copy(): + env.exit(1) + if not test_list_extend(): + env.exit(1) + if not test_list_reverse(): + env.exit(1) + if not test_list_reversed(): + env.exit(1) + if not test_list_del(): + env.exit(1) + if not test_list_pop(): + env.exit(1) + if not test_list_clear(): + env.exit(1) + if not test_sorted(): + env.exit(1) + if not test_bool(): + env.exit(1) + if not test_shrinking(): + env.exit(1) + if not test_list_addition(): + env.exit(1) + + env.exit(0) diff --git a/test/builtins_auto/max.act b/test/builtins_auto/test_max.act similarity index 100% rename from test/builtins_auto/max.act rename to test/builtins_auto/test_max.act diff --git a/test/builtins_auto/min.act b/test/builtins_auto/test_min.act similarity index 100% rename from test/builtins_auto/min.act rename to test/builtins_auto/test_min.act diff --git a/test/builtins_auto/modinit_large_int.act b/test/builtins_auto/test_modinit_large_int.act similarity index 100% rename from test/builtins_auto/modinit_large_int.act rename to test/builtins_auto/test_modinit_large_int.act diff --git a/test/builtins_auto/protocol_test.act b/test/builtins_auto/test_protocol.act similarity index 100% rename from test/builtins_auto/protocol_test.act rename to test/builtins_auto/test_protocol.act diff --git a/test/builtins_auto/protocol_multi_inheritance.act b/test/builtins_auto/test_protocol_multi_inheritance.act similarity index 100% rename from test/builtins_auto/protocol_multi_inheritance.act rename to test/builtins_auto/test_protocol_multi_inheritance.act diff --git a/test/builtins_auto/set_test.act b/test/builtins_auto/test_set.act similarity index 50% rename from test/builtins_auto/set_test.act rename to test/builtins_auto/test_set.act index 1c96ca3f8..3c8692617 100644 --- a/test/builtins_auto/set_test.act +++ b/test/builtins_auto/test_set.act @@ -1,18 +1,20 @@ - def test_set_pop(): s = {1, 2, 3} if s.pop() not in {1, 2, 3}: - raise ValueError("pop() returned an invalid value") + print("pop() returned an invalid value") + return False if len(s) != 2: - raise ValueError("pop() did not remove an element") + print("pop() did not remove an element") + return False s.pop() s.pop() try: s.pop() except ValueError: - pass + return True else: - raise ValueError("pop() did not raise an exception when called on an empty set") + print("pop() did not raise an exception when called on an empty set") + return False def test_set_update_int(): s1 = {1, 2, 3} @@ -21,7 +23,9 @@ def test_set_update_int(): s1.update(s2) if s1 != sexp: - raise ValueError("update() did not work correctly, result is " + str(s1)) + print("update() did not work correctly, result is " + str(s1)) + return False + return True def test_set_update_str(): s1 = {"a", "b", "c"} @@ -30,17 +34,11 @@ def test_set_update_str(): s1.update(s2) if s1 != sexp: - raise ValueError("update() did not work correctly, result is " + str(s1)) - -actor main(env): - try: - test_set_pop() - test_set_update_int() - test_set_update_str() - except Exception as e: - print("Unexpected exception during testing:", e) - await async env.exit(1) + print("update() did not work correctly, result is " + str(s1)) + return False + return True +def test_set_operations(): s = {400} for i in range(13, 1000): s.add(i*i) @@ -51,14 +49,27 @@ actor main(env): for k in range(1000): if k in s: n += 1 if n != 18: - raise ValueError("n is" + str(n) + ", not 18") + print("n is" + str(n) + ", not 18") + return False - env.exit(1) s2 = {1} for i in range(500): s2.add(i*i*i*i) if len(s) != 985 or len(s2) != 500: - raise ValueError("set length error 1") + print("set length error 1") + return False if len(s & s2) != 27 or len(s | s2) != 1458 or len(s ^ s2) != 1431: - raise ValueError("set length error 2") + print("set length error 2") + return False + return True + +actor main(env): + if not test_set_pop(): + env.exit(1) + if not test_set_update_int(): + env.exit(1) + if not test_set_update_str(): + env.exit(1) + if not test_set_operations(): + env.exit(1) env.exit(0) diff --git a/test/builtins_auto/test_str.act b/test/builtins_auto/test_str.act index ef3429ca9..7d867d618 100644 --- a/test/builtins_auto/test_str.act +++ b/test/builtins_auto/test_str.act @@ -1,34 +1,38 @@ - -def test_str_find(): +def test_str_find() -> bool: s = "hello, world!" if s.find("world") != 7: - raise ValueError("find() did not return the correct index: " + str(s.find("world"))) + print("find() did not return the correct index:", s.find("world")) + return False if s.find("world", 0) != 7: - raise ValueError("find() did not return the correct index: " + str(s.find("world"))) + print("find() did not return the correct index:", s.find("world")) + return False if s.find("world", 8) != -1: - raise ValueError("find() did not return -1 when the substring is not found") + print("find() did not return -1 when the substring is not found") + return False if s.find("world", 0, 5) != -1: - raise ValueError("find() did not return -1 when the substring is not found") + print("find() did not return -1 when the substring is not found") + return False if s.find("world", 0, 7) != -1: - raise ValueError("find() did not return -1 when the substring is not found") + print("find() did not return -1 when the substring is not found") + return False if s.find("crap") != -1: - raise ValueError("find() did not return -1 when the substring is not found") - - -actor main(env): - try: - test_str_find() - except Exception as e: - print("Unexpected exception during testing:", e) - await async env.exit(1) + print("find() did not return -1 when the substring is not found") + return False + return True +def test_bytes_hex() -> bool: b = b'\xde\xad\xbe\xef' if b.hex() != "deadbeef": - print("ERROR: bytes.hex():", b.hex()) - env.exit(1) - + print("bytes.hex():", b.hex()) + return False if bytes.from_hex("deadbeef").hex() != "deadbeef": - print("ERROR: bytes.from_hex():", bytes.from_hex("deadbeef").hex()) - env.exit(1) + print("bytes.from_hex():", bytes.from_hex("deadbeef").hex()) + return False + return True +actor main(env): + if not test_str_find(): + env.exit(1) + if not test_bytes_hex(): + env.exit(1) env.exit(0) diff --git a/test/builtins_auto/strings_and_bytes.act b/test/builtins_auto/test_str_and_bytes.act similarity index 100% rename from test/builtins_auto/strings_and_bytes.act rename to test/builtins_auto/test_str_and_bytes.act diff --git a/test/builtins_auto/strips.act b/test/builtins_auto/test_str_strip.act similarity index 100% rename from test/builtins_auto/strips.act rename to test/builtins_auto/test_str_strip.act diff --git a/test/builtins_auto/sum.act b/test/builtins_auto/test_sum.act similarity index 100% rename from test/builtins_auto/sum.act rename to test/builtins_auto/test_sum.act diff --git a/test/builtins_auto/u64.act b/test/builtins_auto/test_u64.act similarity index 100% rename from test/builtins_auto/u64.act rename to test/builtins_auto/test_u64.act