-
Notifications
You must be signed in to change notification settings - Fork 0
Add unit tests for UInt64LinkedList contract #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
holyfuchs
wants to merge
5
commits into
main
Choose a base branch
from
holyfuchs/uint64-linked-list-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4c5e4e7
Add unit tests for UInt64LinkedList contract
holyfuchs b7e6b1b
Merge branch 'main' into holyfuchs/uint64-linked-list-tests
holyfuchs 8b1e7b2
inline tests
holyfuchs bde3787
clean up tests
holyfuchs d78d7ab
Merge branch 'main' into holyfuchs/uint64-linked-list-tests
holyfuchs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| import Test | ||
| import "UInt64LinkedList" | ||
|
|
||
| access(all) fun setup() { | ||
| let err = Test.deployContract( | ||
| name: "UInt64LinkedList", | ||
| path: "../contracts/UInt64LinkedList.cdc", | ||
| arguments: [] | ||
| ) | ||
| Test.expect(err, Test.beNil()) | ||
| } | ||
|
|
||
| // ─── Tests ─────────────────────────────────────────────────────────────────── | ||
|
|
||
| access(all) fun test_EmptyListState() { | ||
| let list <- UInt64LinkedList.createList() | ||
| let ok = list.head == nil | ||
| && list.tail == nil | ||
| && !list.contains(id: 1) | ||
| destroy list | ||
| Test.assertEqual(true, ok) | ||
| } | ||
|
|
||
| access(all) fun test_InsertSingle() { | ||
| let list <- UInt64LinkedList.createList() | ||
| list.insertAtHead(id: 42) | ||
| let ok = list.contains(id: 42) | ||
| && list.head == 42 | ||
| && list.tail == 42 | ||
| destroy list | ||
| Test.assertEqual(true, ok) | ||
| } | ||
|
|
||
| access(all) fun test_InsertMultiple_HeadAndTailOrder() { | ||
| 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 | ||
| Test.assertEqual(true, ok) | ||
| } | ||
|
|
||
| access(all) fun test_Contains() { | ||
| 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 | ||
| Test.assertEqual(true, ok) | ||
| } | ||
|
|
||
| access(all) fun test_RemoveSingle() { | ||
| 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 | ||
| Test.assertEqual(true, ok) | ||
| } | ||
|
|
||
| access(all) fun test_RemoveHead() { | ||
| 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 | ||
| Test.assertEqual(true, ok) | ||
| } | ||
|
|
||
| access(all) fun test_RemoveTail() { | ||
| 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 | ||
| Test.assertEqual(true, ok) | ||
| } | ||
|
|
||
| access(all) fun test_RemoveMiddle() { | ||
| 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 | ||
| Test.assertEqual(true, ok) | ||
| } | ||
|
|
||
| access(all) fun test_RemoveAbsent() { | ||
| let list <- UInt64LinkedList.createList() | ||
| list.insertAtHead(id: 5) | ||
| let removed = list.remove(id: 999) | ||
| destroy list | ||
| Test.assertEqual(true, !removed) | ||
| } | ||
|
|
||
| access(all) fun test_RemoveFromEmpty() { | ||
| let list <- UInt64LinkedList.createList() | ||
| let removed = list.remove(id: 42) | ||
| destroy list | ||
| Test.assertEqual(true, !removed) | ||
| } | ||
|
|
||
| access(all) fun test_TailWalk_Order() { | ||
| 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 | ||
| let expected: [UInt64] = [1, 2, 3] | ||
| Test.assertEqual(expected, walked) | ||
| } | ||
|
|
||
| access(all) fun test_TailWalk_Limit() { | ||
| let list <- UInt64LinkedList.createList() | ||
| list.insertAtHead(id: 1) | ||
| list.insertAtHead(id: 2) | ||
| list.insertAtHead(id: 3) | ||
| let walked = list.tailWalk(limit: 2) | ||
| destroy list | ||
| Test.assertEqual(2, walked.length) | ||
| } | ||
|
|
||
| access(all) fun test_TailWalk_Empty() { | ||
| let list <- UInt64LinkedList.createList() | ||
| let walked = list.tailWalk(limit: 5) | ||
| destroy list | ||
| Test.assertEqual(0, walked.length) | ||
| } | ||
|
|
||
| access(all) fun test_InsertDuplicate_Panics() { | ||
| Test.expectFailure(fun() { | ||
| let list <- UInt64LinkedList.createList() | ||
| list.insertAtHead(id: 1) | ||
| list.insertAtHead(id: 1) | ||
| destroy list | ||
| }, errorMessageSubstring: "ID already exists in list") | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.