Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cadence/tests/scripts/uint64-linked-list/contains.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import "UInt64LinkedList"

/// Returns true if contains is accurate for present and absent ids.
access(all) fun main(): Bool {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 10)
list.insertAtHead(id: 20)
let ok = list.contains(id: 10)
&& list.contains(id: 20)
&& !list.contains(id: 99)
destroy list
return ok
}
11 changes: 11 additions & 0 deletions cadence/tests/scripts/uint64-linked-list/empty_list_state.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "UInt64LinkedList"

/// Returns true if a freshly created list has nil head, nil tail, and contains nothing.
access(all) fun main(): Bool {
let list <- UInt64LinkedList.createList()
let ok = list.head == nil
&& list.tail == nil
&& !list.contains(id: 1)
destroy list
return ok
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "UInt64LinkedList"

/// Expected to fail — inserting a duplicate id violates the pre-condition.
access(all) fun main() {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 1)
list.insertAtHead(id: 1)
destroy list
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import "UInt64LinkedList"

/// Returns true if head is the most recently inserted element and tail is the oldest.
access(all) fun main(): Bool {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 1)
list.insertAtHead(id: 2)
list.insertAtHead(id: 3)
// head = 3 (most recent), tail = 1 (oldest)
let ok = list.head == 3 && list.tail == 1
destroy list
return ok
}
12 changes: 12 additions & 0 deletions cadence/tests/scripts/uint64-linked-list/insert_single.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "UInt64LinkedList"

/// Returns true if a single inserted element becomes both head and tail.
access(all) fun main(): Bool {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 42)
let ok = list.contains(id: 42)
&& list.head == 42
&& list.tail == 42
destroy list
return ok
}
10 changes: 10 additions & 0 deletions cadence/tests/scripts/uint64-linked-list/remove_absent.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import "UInt64LinkedList"

/// Returns true if removing a non-existent id returns false without panicking.
access(all) fun main(): Bool {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 5)
let removed = list.remove(id: 999)
destroy list
return !removed
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "UInt64LinkedList"

/// Returns true if removing from an empty list returns false without panicking.
access(all) fun main(): Bool {
let list <- UInt64LinkedList.createList()
let removed = list.remove(id: 42)
destroy list
return !removed
}
15 changes: 15 additions & 0 deletions cadence/tests/scripts/uint64-linked-list/remove_head.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import "UInt64LinkedList"

/// Returns true if removing the head promotes the next element to head.
access(all) fun main(): Bool {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 1)
list.insertAtHead(id: 2)
list.insertAtHead(id: 3)
// list: 3 <-> 2 <-> 1 (head=3, tail=1)
let removed = list.remove(id: 3)
// list: 2 <-> 1
let ok = removed && list.head == 2 && list.tail == 1
destroy list
return ok
}
20 changes: 20 additions & 0 deletions cadence/tests/scripts/uint64-linked-list/remove_middle.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import "UInt64LinkedList"

/// Returns true if removing a middle element re-links its neighbors correctly.
access(all) fun main(): Bool {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 1)
list.insertAtHead(id: 2)
list.insertAtHead(id: 3)
// list: 3 <-> 2 <-> 1
let removed = list.remove(id: 2)
// list: 3 <-> 1
let ok = removed
&& list.head == 3
&& list.tail == 1
&& !list.contains(id: 2)
&& list.contains(id: 3)
&& list.contains(id: 1)
destroy list
return ok
}
14 changes: 14 additions & 0 deletions cadence/tests/scripts/uint64-linked-list/remove_single.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import "UInt64LinkedList"

/// Returns true if removing the only element leaves an empty list.
access(all) fun main(): Bool {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 7)
let removed = list.remove(id: 7)
let ok = removed
&& list.head == nil
&& list.tail == nil
&& !list.contains(id: 7)
destroy list
return ok
}
15 changes: 15 additions & 0 deletions cadence/tests/scripts/uint64-linked-list/remove_tail.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import "UInt64LinkedList"

/// Returns true if removing the tail promotes the previous element to tail.
access(all) fun main(): Bool {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 1)
list.insertAtHead(id: 2)
list.insertAtHead(id: 3)
// list: 3 <-> 2 <-> 1 (head=3, tail=1)
let removed = list.remove(id: 1)
// list: 3 <-> 2
let ok = removed && list.head == 3 && list.tail == 2
destroy list
return ok
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "UInt64LinkedList"

/// Returns the length of tailWalk on an empty list — should be 0.
access(all) fun main(): Int {
let list <- UInt64LinkedList.createList()
let walked = list.tailWalk(limit: 5)
destroy list
return walked.length
}
12 changes: 12 additions & 0 deletions cadence/tests/scripts/uint64-linked-list/tail_walk_limit.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "UInt64LinkedList"

/// Returns tailWalk result capped to limit=2.
access(all) fun main(): [UInt64] {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 1)
list.insertAtHead(id: 2)
list.insertAtHead(id: 3)
let walked = list.tailWalk(limit: 2)
destroy list
return walked
}
13 changes: 13 additions & 0 deletions cadence/tests/scripts/uint64-linked-list/tail_walk_order.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import "UInt64LinkedList"

/// Returns ids from tailWalk — should be oldest-first (tail toward head).
access(all) fun main(): [UInt64] {
let list <- UInt64LinkedList.createList()
list.insertAtHead(id: 1)
list.insertAtHead(id: 2)
list.insertAtHead(id: 3)
// head=3, tail=1 → tailWalk yields [1, 2, 3]
let walked = list.tailWalk(limit: 10)
destroy list
return walked
}
102 changes: 102 additions & 0 deletions cadence/tests/uint64_linked_list_test.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import Test

access(all) fun setup() {
let err = Test.deployContract(
name: "UInt64LinkedList",
path: "../contracts/UInt64LinkedList.cdc",
arguments: []
)
Test.expect(err, Test.beNil())
}

access(all)
fun executeScript(_ path: String, _ args: [AnyStruct]): Test.ScriptResult {
return Test.executeScript(Test.readFile(path), args)
}

// ─── Tests ───────────────────────────────────────────────────────────────────

access(all) fun test_EmptyListState() {
let res = executeScript("./scripts/uint64-linked-list/empty_list_state.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(true, res.returnValue as! Bool)
}

access(all) fun test_InsertSingle() {
let res = executeScript("./scripts/uint64-linked-list/insert_single.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(true, res.returnValue as! Bool)
}

access(all) fun test_InsertMultiple_HeadAndTailOrder() {
let res = executeScript("./scripts/uint64-linked-list/insert_multiple_order.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(true, res.returnValue as! Bool)
}

access(all) fun test_Contains() {
let res = executeScript("./scripts/uint64-linked-list/contains.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(true, res.returnValue as! Bool)
}

access(all) fun test_RemoveSingle() {
let res = executeScript("./scripts/uint64-linked-list/remove_single.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(true, res.returnValue as! Bool)
}

access(all) fun test_RemoveHead() {
let res = executeScript("./scripts/uint64-linked-list/remove_head.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(true, res.returnValue as! Bool)
}

access(all) fun test_RemoveTail() {
let res = executeScript("./scripts/uint64-linked-list/remove_tail.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(true, res.returnValue as! Bool)
}

access(all) fun test_RemoveMiddle() {
let res = executeScript("./scripts/uint64-linked-list/remove_middle.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(true, res.returnValue as! Bool)
}

access(all) fun test_RemoveAbsent() {
let res = executeScript("./scripts/uint64-linked-list/remove_absent.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(true, res.returnValue as! Bool)
}

access(all) fun test_RemoveFromEmpty() {
let res = executeScript("./scripts/uint64-linked-list/remove_from_empty.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(true, res.returnValue as! Bool)
}

access(all) fun test_TailWalk_Order() {
let res = executeScript("./scripts/uint64-linked-list/tail_walk_order.cdc", [])
Test.expect(res, Test.beSucceeded())
let expected: [UInt64] = [1, 2, 3]
Test.assertEqual(expected, res.returnValue as! [UInt64])
}

access(all) fun test_TailWalk_Limit() {
let res = executeScript("./scripts/uint64-linked-list/tail_walk_limit.cdc", [])
Test.expect(res, Test.beSucceeded())
let walked = res.returnValue as! [UInt64]
Test.assertEqual(2, walked.length)
}

access(all) fun test_TailWalk_Empty() {
let res = executeScript("./scripts/uint64-linked-list/tail_walk_empty.cdc", [])
Test.expect(res, Test.beSucceeded())
Test.assertEqual(0, res.returnValue as! Int)
}

access(all) fun test_InsertDuplicate_Panics() {
let res = executeScript("./scripts/uint64-linked-list/insert_duplicate_panics.cdc", [])
Test.expect(res, Test.beFailed())
}
Loading