From eccdaeb07165640974ac143233152d09df3cb428 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Thu, 24 Oct 2024 13:29:53 +0200 Subject: [PATCH] Test: Add loop based linked list --- ...{recursive_list.vpy => list_recursive.vpy} | 0 tests/list_while.vpy | 60 +++++++++++++++++++ 2 files changed, 60 insertions(+) rename tests/{recursive_list.vpy => list_recursive.vpy} (100%) create mode 100644 tests/list_while.vpy diff --git a/tests/recursive_list.vpy b/tests/list_recursive.vpy similarity index 100% rename from tests/recursive_list.vpy rename to tests/list_recursive.vpy diff --git a/tests/list_while.vpy b/tests/list_while.vpy new file mode 100644 index 0000000..72c9690 --- /dev/null +++ b/tests/list_while.vpy @@ -0,0 +1,60 @@ +def new_list(): + def insert(self, item): + node = self.head + while node.next != null: + node = node.next + + node.next = {} + node.next.data = item + node.next.prev = node + + def contains(self, item): + node = self.head + while node.next != null: + if node.data == item: + return True + node = node.next + return False + + def remove(self, item): + node = self.head + while node.next != null: + if node.data == item: + node.prev.next = node.next + if node.next != null: + node.next.prev = node.prev + return True + node = node.next + return False + + list = {} + list.head = {} + list.insert = take insert + list.contains = take contains + list.remove = take remove + return list + +# Dyrona doesn't freeze shared objects automatically (yet) +def freeze_and_hide_proto(value): + proto = value["__proto__"] + freeze(proto) + mermaid_hide(proto) +freeze_and_hide_proto(freeze_and_hide_proto) +freeze_and_hide_proto("string") +drop freeze_and_hide_proto + +list = new_list() + +# Required to not leak memory +region(list) + +value = "x" + +list.insert({}) +list.insert({}) +list.insert(value) +list.insert({}) +list.remove(value) + +drop value +drop list