From 3a9424e2864b1bf05e9ad93d8d9c8445ddafeca6 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 28 Mar 2024 14:43:54 +0530 Subject: [PATCH] Tests: Add tests --- integration_tests/CMakeLists.txt | 1 + integration_tests/test_set_discard.py | 48 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 integration_tests/test_set_discard.py diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index d73ab6f5d3..e5f6ff3aa8 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -583,6 +583,7 @@ RUN(NAME test_dict_nested1 LABELS cpython llvm) RUN(NAME test_set_len LABELS cpython llvm) RUN(NAME test_set_add LABELS cpython llvm) RUN(NAME test_set_remove LABELS cpython llvm) +RUN(NAME test_set_discard LABELS cpython llvm) RUN(NAME test_global_set LABELS cpython llvm) RUN(NAME test_for_loop LABELS cpython llvm c) RUN(NAME modules_01 LABELS cpython llvm c wasm wasm_x86 wasm_x64) diff --git a/integration_tests/test_set_discard.py b/integration_tests/test_set_discard.py new file mode 100644 index 0000000000..730abaff7d --- /dev/null +++ b/integration_tests/test_set_discard.py @@ -0,0 +1,48 @@ +from lpython import i32 + +def test_set_discard(): + s1: set[i32] + s2: set[tuple[i32, tuple[i32, i32], str]] + s3: set[str] + st1: str + i: i32 + j: i32 + k: i32 + + for k in range(2): + s1 = {0} + s2 = {(0, (1, 2), "a")} + for i in range(20): + j = i % 10 + s1.add(j) + s2.add((j, (j + 1, j + 2), "a")) + + for i in range(10): + s1.discard(i) + s2.discard((i, (i + 1, i + 2), "a")) + assert len(s1) == 10 - 1 - i + assert len(s1) == len(s2) + + st1 = "a" + s3 = {st1} + for i in range(20): + s3.add(st1) + if i < 10: + if i > 0: + st1 += "a" + + st1 = "a" + for i in range(10): + s3.discard(st1) + assert len(s3) == 10 - 1 - i + if i < 10: + st1 += "a" + + for i in range(20): + s1.add(i) + if i % 2 == 0: + s1.discard(i) + assert len(s1) == (i + 1) // 2 + + +test_set_discard()