Skip to content

Commit

Permalink
Test: Add loop based linked list
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Oct 24, 2024
1 parent 5e065c8 commit eccdaeb
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
File renamed without changes.
60 changes: 60 additions & 0 deletions tests/list_while.vpy
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit eccdaeb

Please sign in to comment.