From 26b6805b8fc7f011aa50d6ae28b8b4f559747b57 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sat, 6 Jun 2026 20:09:39 +0200 Subject: [PATCH 1/2] update test spec for simple-linked-list --- .../simple-linked-list/.meta/tests.toml | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 exercises/practice/simple-linked-list/.meta/tests.toml diff --git a/exercises/practice/simple-linked-list/.meta/tests.toml b/exercises/practice/simple-linked-list/.meta/tests.toml new file mode 100644 index 00000000..b1e320eb --- /dev/null +++ b/exercises/practice/simple-linked-list/.meta/tests.toml @@ -0,0 +1,101 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[962d998c-c203-41e2-8fbd-85a7b98b79b9] +description = "count -> Empty list has length of zero" + +[9760262e-d7e4-4639-9840-87e2e2fbb115] +description = "count -> Singleton list has length of one" + +[d9955c90-637c-441b-b41d-8cfb48e924a8] +description = "count -> Non-empty list has correct length" + +[0c3966db-58f9-4632-b94c-8ea13e54c2c8] +description = "pop -> Pop from empty list is an error" + +[a4f9d2e1-7425-49ef-9ee8-6c0cb3407cf0] +description = "pop -> Can pop from singleton list" + +[6dcbb2c9-d98a-47bc-a010-9c19703d3ea2] +description = "pop -> Can pop from non-empty list" + +[e83aade9-f030-4096-aaf0-f9dc6491e6cf] +description = "pop -> Can pop multiple items" + +[5c46bcf2-c0a9-4654-ae17-f3192436fcf1] +description = "pop -> Pop updates the count" + +[70d747a1-2e84-4ebc-bc3f-dcbee6a05f6b] +description = "push -> Can push to an empty list" +include = false + +[f3197f0a-1fea-45a5-939f-4a5ea60387ec] +description = "push -> Can push to an empty list" +reimplements = "70d747a1-2e84-4ebc-bc3f-dcbee6a05f6b" + +[391e332e-1f91-4033-b1e0-0e0c17812fa7] +description = "push -> Can push to a non-empty list" + +[ed4b0e01-3bbd-4895-af25-152b5914b3da] +description = "push -> Push updates count" + +[41666790-b932-4e5a-b323-e848a83d12d5] +description = "push -> Push and pop" + +[930a4a5c-76f6-47ec-9be3-4e70993173a1] +description = "peek -> Peek on empty list is an error" + +[43255a50-d919-4e81-afce-e4a271eaedbd] +description = "peek -> Can peek on singleton list" + +[48353020-e25d-4621-a854-e35fb1e15fa7] +description = "peek -> Can peek on non-empty list" + +[96fcead9-a713-46c2-8005-3f246c873851] +description = "peek -> Peek does not change the count" + +[7576ed05-7ff7-4b84-8efb-d34d62c110f5] +description = "peek -> Can peek after a pop and push" + +[b97d00b6-2fab-435d-ae74-3233dcc13698] +description = "toList LIFO -> Empty linked list to list is empty" + +[eedeb95f-b5cf-431d-8ad6-5854ba6b251c] +description = "toList LIFO -> To list with multiple values" + +[838678de-eaf3-4c14-b34e-7e35b6d851e8] +description = "toList LIFO -> To list after a pop" + +[03fc83a5-48a8-470b-a2d2-a286c5e8365f] +description = "toList FIFO -> Empty linked list to list is empty" + +[1282484e-a58c-426a-972e-90746bda61fc] +description = "toList FIFO -> To list with multiple values" + +[05ca3109-1249-4c0c-a567-a3b2f8352a7c] +description = "toList FIFO -> To list after a pop" + +[5e6c1a3d-e34b-46d3-be59-3f132a820ed5] +description = "reverse -> Reversed empty list has same values" + +[93c87ed3-862a-474f-820b-ba3fd6b6daf6] +description = "reverse -> Reversed singleton list is same list" + +[92851ebe-9f52-4406-b92e-0718c441a2ab] +description = "reverse -> Reversed non-empty list is reversed" +include = false + +[1210eeda-b23f-4790-930c-7ac6d0c8e723] +description = "reverse -> Reversed non-empty list is reversed" +reimplements = "92851ebe-9f52-4406-b92e-0718c441a2ab" + +[9b53af96-7494-4cfa-9b77-b7366fed5c4c] +description = "reverse -> Double reverse" From f9c15be1b7db2445ec29d2a23e4c791941fb25c4 Mon Sep 17 00:00:00 2001 From: 0xNeshi Date: Sat, 6 Jun 2026 20:20:31 +0200 Subject: [PATCH 2/2] update test suite --- .../simple-linked-list/.meta/tests.toml | 3 + .../tests/simple_linked_list.cairo | 229 +++++++++++++----- 2 files changed, 167 insertions(+), 65 deletions(-) diff --git a/exercises/practice/simple-linked-list/.meta/tests.toml b/exercises/practice/simple-linked-list/.meta/tests.toml index b1e320eb..9a628e22 100644 --- a/exercises/practice/simple-linked-list/.meta/tests.toml +++ b/exercises/practice/simple-linked-list/.meta/tests.toml @@ -67,12 +67,15 @@ description = "peek -> Can peek after a pop and push" [b97d00b6-2fab-435d-ae74-3233dcc13698] description = "toList LIFO -> Empty linked list to list is empty" +include = false [eedeb95f-b5cf-431d-8ad6-5854ba6b251c] description = "toList LIFO -> To list with multiple values" +include = false [838678de-eaf3-4c14-b34e-7e35b6d851e8] description = "toList LIFO -> To list after a pop" +include = false [03fc83a5-48a8-470b-a2d2-a286c5e8365f] description = "toList FIFO -> Empty linked list to list is empty" diff --git a/exercises/practice/simple-linked-list/tests/simple_linked_list.cairo b/exercises/practice/simple-linked-list/tests/simple_linked_list.cairo index 9bfe2304..4b4361c8 100644 --- a/exercises/practice/simple-linked-list/tests/simple_linked_list.cairo +++ b/exercises/practice/simple-linked-list/tests/simple_linked_list.cairo @@ -1,124 +1,223 @@ use simple_linked_list::{SimpleLinkedList, SimpleLinkedListTrait}; +// count + #[test] -fn new_list_is_empty() { +fn empty_list_has_length_of_zero() { let list = SimpleLinkedListTrait::::new(); - assert_eq!(list.len(), 0, "list's length must be 0"); + assert_eq!(list.len(), 0); } #[test] #[ignore] -fn push_increments_length() { - let mut list = SimpleLinkedListTrait::::new(); - list.push(1); - assert_eq!(list.len(), 1, "list's length must be 1"); - list.push(2); - assert_eq!(list.len(), 2, "list's length must be 2"); +fn singleton_list_has_length_of_one() { + let list: SimpleLinkedList = array![1].into(); + assert_eq!(list.len(), 1); } #[test] #[ignore] -fn pop_decrements_length() { - let mut list = SimpleLinkedListTrait::::new(); - list.push(1); - list.push(2); - list.pop().unwrap(); - assert_eq!(list.len(), 1, "list's length must be 1"); - list.pop().unwrap(); - assert_eq!(list.len(), 0, "list's length must be 0"); +fn non_empty_list_has_correct_length() { + let list: SimpleLinkedList = array![1, 2, 3].into(); + assert_eq!(list.len(), 3); } +// pop + #[test] #[ignore] -fn pop_returns_head_element_and_removes_it() { +fn pop_from_empty_list_is_an_error() { let mut list = SimpleLinkedListTrait::::new(); - list.push(1); - list.push(2); - assert_eq!(list.pop(), Option::Some(2), "Element must be 2"); - assert_eq!(list.pop(), Option::Some(1), "Element must be 1"); let none: Option = Option::None; - assert_eq!(list.pop(), none, "No element should be contained in list"); + assert_eq!(list.pop(), none); } #[test] #[ignore] -fn peek_returns_reference_to_head_element_but_does_not_remove_it() { +fn can_pop_from_singleton_list() { + let mut list: SimpleLinkedList = array![1].into(); + assert_eq!(list.pop(), Option::Some(1)); +} + +#[test] +#[ignore] +fn can_pop_from_non_empty_list() { + let mut list: SimpleLinkedList = array![1, 2].into(); + assert_eq!(list.pop(), Option::Some(2)); +} + +#[test] +#[ignore] +fn can_pop_multiple_items() { + let mut list: SimpleLinkedList = array![1, 2].into(); + assert_eq!(list.pop(), Option::Some(2)); + assert_eq!(list.pop(), Option::Some(1)); +} + +#[test] +#[ignore] +fn pop_updates_the_count() { + let mut list: SimpleLinkedList = array![1, 2].into(); + assert_eq!(list.len(), 2); + assert_eq!(list.pop(), Option::Some(2)); + assert_eq!(list.len(), 1); + assert_eq!(list.pop(), Option::Some(1)); + assert_eq!(list.len(), 0); +} + +// push + +#[test] +#[ignore] +fn can_push_to_an_empty_list() { let mut list = SimpleLinkedListTrait::::new(); - let none: Option<@u32> = Option::None; - assert_eq!(list.peek(), none, "No element should be contained in list"); - list.push(2); - assert_eq!(list.peek(), Option::Some(@2), "Element must be 2"); - assert_eq!(list.peek(), Option::Some(@2), "Element must be still 2"); + list.push(1); + assert_eq!(list.peek(), Option::Some(@1)); +} + +#[test] +#[ignore] +fn can_push_to_a_non_empty_list() { + let mut list: SimpleLinkedList = array![1, 2].into(); list.push(3); - assert_eq!(list.peek(), Option::Some(@3), "Head element is now 3"); - assert_eq!(list.pop(), Option::Some(3), "Element must be 3"); - assert_eq!(list.peek(), Option::Some(@2), "Head element is now 2"); - assert_eq!(list.pop(), Option::Some(2), "Element must be 2"); - assert_eq!(list.peek(), none, "No element should be contained in list"); + assert_eq!(list.peek(), Option::Some(@3)); } #[test] #[ignore] -fn reverse() { +fn push_updates_count() { + let mut list: SimpleLinkedList = array![1, 2].into(); + list.push(3); + assert_eq!(list.len(), 3); +} + +#[test] +#[ignore] +fn push_and_pop() { let mut list = SimpleLinkedListTrait::::new(); list.push(1); list.push(2); + assert_eq!(list.pop(), Option::Some(2)); list.push(3); - let mut rev_list = list.rev(); - assert_eq!(rev_list.pop(), Option::Some(1)); - assert_eq!(rev_list.pop(), Option::Some(2)); - assert_eq!(rev_list.pop(), Option::Some(3)); - let none: Option = Option::None; - assert_eq!(rev_list.pop(), none); + assert_eq!(list.len(), 2); + assert_eq!(list.pop(), Option::Some(3)); + assert_eq!(list.pop(), Option::Some(1)); + assert_eq!(list.len(), 0); } +// peek + #[test] #[ignore] -fn reverse_empty_list() { - let mut list = SimpleLinkedListTrait::::new(); - let mut rev_list = list.rev(); - let none: Option = Option::None; - assert_eq!(rev_list.pop(), none); - assert_eq!(rev_list.len(), 0); +fn peek_on_empty_list_is_an_error() { + let list = SimpleLinkedListTrait::::new(); + let none: Option<@u32> = Option::None; + assert_eq!(list.peek(), none); } #[test] #[ignore] -fn from_array() { - let mut array: Array = array![1, 2, 3, 4]; - let mut list: SimpleLinkedList = array.into(); - assert_eq!(list.pop(), Option::Some(4)); - assert_eq!(list.pop(), Option::Some(3)); +fn can_peek_on_singleton_list() { + let list: SimpleLinkedList = array![1].into(); + assert_eq!(list.peek(), Option::Some(@1)); +} + +#[test] +#[ignore] +fn can_peek_on_non_empty_list() { + let list: SimpleLinkedList = array![1, 2].into(); + assert_eq!(list.peek(), Option::Some(@2)); +} + +#[test] +#[ignore] +fn peek_does_not_change_the_count() { + let list: SimpleLinkedList = array![1, 2].into(); + assert_eq!(list.peek(), Option::Some(@2)); + assert_eq!(list.len(), 2); +} + +#[test] +#[ignore] +fn can_peek_after_a_pop_and_push() { + let mut list = SimpleLinkedListTrait::::new(); + list.push(1); + list.push(2); + assert_eq!(list.peek(), Option::Some(@2)); assert_eq!(list.pop(), Option::Some(2)); - assert_eq!(list.pop(), Option::Some(1)); + assert_eq!(list.peek(), Option::Some(@1)); + list.push(3); + assert_eq!(list.peek(), Option::Some(@3)); } +// toList FIFO + #[test] #[ignore] -fn from_empty_array_is_empty_list() { - let mut array: Array = array![]; - let mut list: SimpleLinkedList = array.into(); - let none: Option = Option::None; - assert_eq!(list.pop(), none); - assert_eq!(list.len(), 0); +fn empty_linked_list_to_list_is_empty() { + let list = SimpleLinkedListTrait::::new(); + let arr: Array = list.into(); + assert_eq!(arr, array![]); } #[test] #[ignore] -fn into_array() { +fn to_list_with_multiple_values() { + let list: SimpleLinkedList = array![1, 2, 3].into(); + let arr: Array = list.into(); + assert_eq!(arr, array![1, 2, 3]); +} + +#[test] +#[ignore] +fn to_list_after_a_pop() { let mut list = SimpleLinkedListTrait::::new(); list.push(1); list.push(2); list.push(3); + assert_eq!(list.pop(), Option::Some(3)); list.push(4); - let list_as_arr: Array = list.into(); - assert_eq!(array![1, 2, 3, 4], list_as_arr); + let arr: Array = list.into(); + assert_eq!(arr, array![1, 2, 4]); +} + +// reverse + +#[test] +#[ignore] +fn reversed_empty_list_has_same_values() { + let list = SimpleLinkedListTrait::::new(); + let rev_list = list.rev(); + let arr: Array = rev_list.into(); + assert_eq!(arr, array![]); } #[test] #[ignore] -fn empty_list_into_empty_array() { - let mut list = SimpleLinkedListTrait::::new(); - let list_as_arr: Array = list.into(); - assert_eq!(array![], list_as_arr); +fn reversed_singleton_list_is_same_list() { + let list: SimpleLinkedList = array![1].into(); + let rev_list = list.rev(); + let arr: Array = rev_list.into(); + assert_eq!(arr, array![1]); +} + +#[test] +#[ignore] +fn reversed_non_empty_list_is_reversed() { + let list: SimpleLinkedList = array![1, 2, 3].into(); + let mut rev_list = list.rev(); + assert_eq!(rev_list.len(), 3); + assert_eq!(rev_list.pop(), Option::Some(1)); + assert_eq!(rev_list.pop(), Option::Some(2)); + assert_eq!(rev_list.pop(), Option::Some(3)); +} + +#[test] +#[ignore] +fn double_reverse() { + let list: SimpleLinkedList = array![1, 2, 3].into(); + let mut list = list.rev().rev(); + assert_eq!(list.pop(), Option::Some(3)); + assert_eq!(list.pop(), Option::Some(2)); + assert_eq!(list.pop(), Option::Some(1)); }