diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ced5f98d..1028104b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,7 +38,7 @@ jobs: - name: Getting scarb uses: software-mansion/setup-scarb@v1 with: - scarb-version: "2.8.2" + scarb-version: "2.9.2" - name: Verify all exercises env: @@ -56,7 +56,7 @@ jobs: - name: Getting scarb uses: software-mansion/setup-scarb@v1 with: - scarb-version: "2.8.2" + scarb-version: "2.9.2" - name: Format run: ./bin/format_exercises.sh --check diff --git a/.tool-versions b/.tool-versions index cc60fd62..f6645f9f 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 2.8.2 +scarb 2.9.2 diff --git a/README.md b/README.md index 5b7908a5..108337c4 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ _Thoughtful suggestions will likely result faster & more enthusiastic responses ## Testing -Tests currently use Cairo v2.8.2 (included with Scarb v2.8.2). +Tests currently use Cairo v2.9.2 (included with Scarb v2.9.2). To test all exercises, run `./bin/verify-exercises`. This command will iterate over all exercises and check to see if their exemplar/example implementation passes all the tests. diff --git a/bin/format_exercises.sh b/bin/format_exercises.sh index 3420ff9d..2b0a309d 100755 --- a/bin/format_exercises.sh +++ b/bin/format_exercises.sh @@ -22,16 +22,11 @@ for exercise_dir in $exercises; do continue fi - if [ -f "./src/lib.cairo" ]; then - scaffold_solution="./src/lib.cairo" - else + if [ ! -s "./src/lib.cairo" ]; then echo "Could not locate scaffold implementation for $exercise" exit 1 fi - # check scaffold solution formatting - scarb fmt "${SCARB_FMT_ARGS[@]}" - # scarb fmt cannot currently format individual files, so we have to # temporarily move the solution files into the Cairo package, where # 'scarb fmt' can format it as well @@ -47,17 +42,13 @@ for exercise_dir in $exercises; do exit 1 fi - # backup scaffold solution - cp "$scaffold_solution" "$tmp_file" - # copy the example solution file into the package - cp "$solution_file" "$scaffold_solution" + cp "$solution_file" "$tmp_file" - # check example solution formatting scarb fmt "${SCARB_FMT_ARGS[@]}" - # copy the scaffold solution back - cp "$tmp_file" "$scaffold_solution" + # copy the example solution back in case it was formatted + cp "$tmp_file" "$solution_file" rm "$tmp_file" done diff --git a/exercises/concept/annalyns-infiltration/.meta/exemplar.cairo b/exercises/concept/annalyns-infiltration/.meta/exemplar.cairo index 3f52fa17..603a9d8c 100644 --- a/exercises/concept/annalyns-infiltration/.meta/exemplar.cairo +++ b/exercises/concept/annalyns-infiltration/.meta/exemplar.cairo @@ -11,7 +11,7 @@ pub fn can_signal_prisoner(archer_awake: bool, prisoner_awake: bool) -> bool { } pub fn can_free_prisoner( - knight_awake: bool, archer_awake: bool, prisoner_awake: bool, dog_present: bool + knight_awake: bool, archer_awake: bool, prisoner_awake: bool, dog_present: bool, ) -> bool { (prisoner_awake && !knight_awake && !archer_awake) || (dog_present && !archer_awake) } diff --git a/exercises/concept/annalyns-infiltration/Scarb.toml b/exercises/concept/annalyns-infiltration/Scarb.toml index 519969b9..4db3b7fd 100644 --- a/exercises/concept/annalyns-infiltration/Scarb.toml +++ b/exercises/concept/annalyns-infiltration/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/concept/annalyns-infiltration/src/lib.cairo b/exercises/concept/annalyns-infiltration/src/lib.cairo index a5c310ec..db416c99 100644 --- a/exercises/concept/annalyns-infiltration/src/lib.cairo +++ b/exercises/concept/annalyns-infiltration/src/lib.cairo @@ -11,7 +11,7 @@ pub fn can_signal_prisoner(archer_awake: bool, prisoner_awake: bool) -> bool { } pub fn can_free_prisoner( - knight_awake: bool, archer_awake: bool, prisoner_awake: bool, dog_present: bool + knight_awake: bool, archer_awake: bool, prisoner_awake: bool, dog_present: bool, ) -> bool { panic!("implement `can_free_prisoner`") } diff --git a/exercises/concept/calculator-conundrum/Scarb.toml b/exercises/concept/calculator-conundrum/Scarb.toml index ec9c1d1d..de2b24b2 100644 --- a/exercises/concept/calculator-conundrum/Scarb.toml +++ b/exercises/concept/calculator-conundrum/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/concept/calculator-conundrum/tests/calculator_conundrum.cairo b/exercises/concept/calculator-conundrum/tests/calculator_conundrum.cairo index 6c0cb948..d52e4c05 100644 --- a/exercises/concept/calculator-conundrum/tests/calculator_conundrum.cairo +++ b/exercises/concept/calculator-conundrum/tests/calculator_conundrum.cairo @@ -9,7 +9,7 @@ fn addition_with_small_operands() { #[ignore] fn addition_with_large_operands() { assert_eq!( - SimpleCalculator::calculate(378_961, 399_635, "+").unwrap(), "378961 + 399635 = 778596" + SimpleCalculator::calculate(378_961, 399_635, "+").unwrap(), "378961 + 399635 = 778596", ); } @@ -23,7 +23,7 @@ fn multiplication_with_small_operands() { #[ignore] fn multiplication_with_large_operands() { assert_eq!( - SimpleCalculator::calculate(72_441, 2_048, "*").unwrap(), "72441 * 2048 = 148359168" + SimpleCalculator::calculate(72_441, 2_048, "*").unwrap(), "72441 * 2048 = 148359168", ); } @@ -37,7 +37,7 @@ fn division_with_small_operands() { #[ignore] fn division_with_large_operands() { assert_eq!( - SimpleCalculator::calculate(1_338_800, 83_675, "/").unwrap(), "1338800 / 83675 = 16" + SimpleCalculator::calculate(1_338_800, 83_675, "/").unwrap(), "1338800 / 83675 = 16", ); } diff --git a/exercises/concept/chrono-realms-time-tree/Scarb.toml b/exercises/concept/chrono-realms-time-tree/Scarb.toml index 36f69878..8865ffcb 100644 --- a/exercises/concept/chrono-realms-time-tree/Scarb.toml +++ b/exercises/concept/chrono-realms-time-tree/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/concept/chrono-realms/Scarb.toml b/exercises/concept/chrono-realms/Scarb.toml index 9819dcc7..0eee5f77 100644 --- a/exercises/concept/chrono-realms/Scarb.toml +++ b/exercises/concept/chrono-realms/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/concept/low-power-embedded-game/.meta/exemplar.cairo b/exercises/concept/low-power-embedded-game/.meta/exemplar.cairo index d51cfd32..f0effa7d 100644 --- a/exercises/concept/low-power-embedded-game/.meta/exemplar.cairo +++ b/exercises/concept/low-power-embedded-game/.meta/exemplar.cairo @@ -14,7 +14,7 @@ pub impl EvensImpl, +Copy> of EvensTrait { if i % 2 == 0 { result.append(*self.at(i)); } - i += 1; + i += 2; }; result } diff --git a/exercises/concept/low-power-embedded-game/Scarb.toml b/exercises/concept/low-power-embedded-game/Scarb.toml index a27ef7fa..126011aa 100644 --- a/exercises/concept/low-power-embedded-game/Scarb.toml +++ b/exercises/concept/low-power-embedded-game/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/concept/low-power-embedded-game/tests/low_power_embedded_game.cairo b/exercises/concept/low-power-embedded-game/tests/low_power_embedded_game.cairo index e73de209..9977ecd6 100644 --- a/exercises/concept/low-power-embedded-game/tests/low_power_embedded_game.cairo +++ b/exercises/concept/low-power-embedded-game/tests/low_power_embedded_game.cairo @@ -43,7 +43,7 @@ mod evens { #[ignore] fn strs() { let arr: Array = array![ - 'You', 'really', 'must', 'never', 'be', 'above', 'joking.' + 'You', 'really', 'must', 'never', 'be', 'above', 'joking.', ]; assert_eq!(arr.evens(), array!['You', 'must', 'be', 'joking.']); } diff --git a/exercises/concept/lucians-luscious-lasagna/Scarb.toml b/exercises/concept/lucians-luscious-lasagna/Scarb.toml index 340989e0..e6dc80f9 100644 --- a/exercises/concept/lucians-luscious-lasagna/Scarb.toml +++ b/exercises/concept/lucians-luscious-lasagna/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/concept/lucians-luscious-lasagna/tests/lucians_luscious_lasagna.cairo b/exercises/concept/lucians-luscious-lasagna/tests/lucians_luscious_lasagna.cairo index 2fca7ead..d4893955 100644 --- a/exercises/concept/lucians-luscious-lasagna/tests/lucians_luscious_lasagna.cairo +++ b/exercises/concept/lucians-luscious-lasagna/tests/lucians_luscious_lasagna.cairo @@ -1,6 +1,6 @@ use lucians_luscious_lasagna::{ elapsed_time_in_minutes, expected_minutes_in_oven, preparation_time_in_minutes, - remaining_minutes_in_oven + remaining_minutes_in_oven, }; #[test] diff --git a/exercises/concept/the-realm-of-echoes/Scarb.toml b/exercises/concept/the-realm-of-echoes/Scarb.toml index 55e1060d..388076d7 100644 --- a/exercises/concept/the-realm-of-echoes/Scarb.toml +++ b/exercises/concept/the-realm-of-echoes/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/acronym/.meta/example.cairo b/exercises/practice/acronym/.meta/example.cairo index d5626d51..14cd6829 100644 --- a/exercises/practice/acronym/.meta/example.cairo +++ b/exercises/practice/acronym/.meta/example.cairo @@ -14,25 +14,25 @@ pub fn abbreviate(phrase: ByteArray) -> ByteArray { i += 1; }; - return result; + result } fn to_uppercase(c: u8) -> u8 { if is_lowercase(c) { - return c - 32; + c - 32 } else { - return c; + c } } fn is_letter(c: u8) -> bool { - return is_uppercase(c) || is_lowercase(c); + is_uppercase(c) || is_lowercase(c) } fn is_uppercase(c: u8) -> bool { - return c >= 'A' && c <= 'Z'; + c >= 'A' && c <= 'Z' } fn is_lowercase(c: u8) -> bool { - return c >= 'a' && c <= 'z'; + c >= 'a' && c <= 'z' } diff --git a/exercises/practice/acronym/Scarb.toml b/exercises/practice/acronym/Scarb.toml index 72d89a6f..c0b31099 100644 --- a/exercises/practice/acronym/Scarb.toml +++ b/exercises/practice/acronym/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/all-your-base/.meta/example.cairo b/exercises/practice/all-your-base/.meta/example.cairo index 584c560a..f3fbf259 100644 --- a/exercises/practice/all-your-base/.meta/example.cairo +++ b/exercises/practice/all-your-base/.meta/example.cairo @@ -1,3 +1,5 @@ +use core::num::traits::Pow; + #[derive(Drop, Debug, PartialEq)] pub enum Error { InvalidInputBase, @@ -45,7 +47,7 @@ fn convert_to_base_10(digits: Array, input_base: u32) -> u32 { while i < len { let digit = digits[i]; let exp = len - 1 - i; - let pow = pow(input_base, exp); + let pow = input_base.pow(exp); sum += *digit * pow; i += 1; }; @@ -80,17 +82,3 @@ fn reverse_array(arr: Array) -> Array { reversed } - -fn pow(base: u32, mut power: u32) -> u32 { - if base == 0 { - return base; - } - let base: u256 = base.into(); - let mut result = 1_u256; - while power != 0 { - result *= base; - power -= 1; - }; - - result.try_into().expect('too large to fit output type') -} diff --git a/exercises/practice/all-your-base/Scarb.toml b/exercises/practice/all-your-base/Scarb.toml index f5557f14..c6e0d803 100644 --- a/exercises/practice/all-your-base/Scarb.toml +++ b/exercises/practice/all-your-base/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/allergies/.meta/example.cairo b/exercises/practice/allergies/.meta/example.cairo index e2562919..7b5df367 100644 --- a/exercises/practice/allergies/.meta/example.cairo +++ b/exercises/practice/allergies/.meta/example.cairo @@ -1,3 +1,5 @@ +use core::num::traits::Pow; + #[derive(Drop)] struct Allergies { score: u32, @@ -15,17 +17,9 @@ pub enum Allergen { Cats, } -const ALLERGENS: [ - Allergen - ; 8] = [ - Allergen::Eggs, - Allergen::Peanuts, - Allergen::Shellfish, - Allergen::Strawberries, - Allergen::Tomatoes, - Allergen::Chocolate, - Allergen::Pollen, - Allergen::Cats, +const ALLERGENS: [Allergen; 8] = [ + Allergen::Eggs, Allergen::Peanuts, Allergen::Shellfish, Allergen::Strawberries, + Allergen::Tomatoes, Allergen::Chocolate, Allergen::Pollen, Allergen::Cats, ]; #[generate_trait] @@ -45,7 +39,7 @@ pub impl AllergiesImpl of AllergiesTrait { } index += 1; }; - found && (*self.score & pow(2, index)) != 0 + found && (*self.score & 2_u32.pow(index)) != 0 } fn allergies(self: @Allergies) -> Array { @@ -59,16 +53,3 @@ pub impl AllergiesImpl of AllergiesTrait { result } } - -fn pow(base: u32, mut power: u32) -> u32 { - if base == 0 { - return base; - } - let base: u256 = base.into(); - let mut result = 1_u256; - while power != 0 { - result *= base; - power -= 1; - }; - result.try_into().expect('too large to fit output type') -} diff --git a/exercises/practice/allergies/Scarb.toml b/exercises/practice/allergies/Scarb.toml index a9e50611..ac506140 100644 --- a/exercises/practice/allergies/Scarb.toml +++ b/exercises/practice/allergies/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/allergies/tests/allergies.cairo b/exercises/practice/allergies/tests/allergies.cairo index 846d66e8..ef0e6765 100644 --- a/exercises/practice/allergies/tests/allergies.cairo +++ b/exercises/practice/allergies/tests/allergies.cairo @@ -282,7 +282,7 @@ fn testing_for_cats_allergy_allergic_to_everything() { fn compare_allergy_vectors(expected: @Array, actual: @Array) { if actual.len() != expected.len() { panic!( - "Allergy vectors are of different lengths\n expected {expected:?}\n got {actual:?}" + "Allergy vectors are of different lengths\n expected {expected:?}\n got {actual:?}", ); } diff --git a/exercises/practice/anagram/.meta/example.cairo b/exercises/practice/anagram/.meta/example.cairo index 241dd521..06753315 100644 --- a/exercises/practice/anagram/.meta/example.cairo +++ b/exercises/practice/anagram/.meta/example.cairo @@ -2,7 +2,7 @@ use core::dict::Felt252Dict; #[derive(Drop, Debug)] struct Set { - values: Array + values: Array, } #[generate_trait] diff --git a/exercises/practice/anagram/Scarb.toml b/exercises/practice/anagram/Scarb.toml index 615ac4cb..9ef7e5f6 100644 --- a/exercises/practice/anagram/Scarb.toml +++ b/exercises/practice/anagram/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/anagram/tests/anagram.cairo b/exercises/practice/anagram/tests/anagram.cairo index ec69043b..cb0c932c 100644 --- a/exercises/practice/anagram/tests/anagram.cairo +++ b/exercises/practice/anagram/tests/anagram.cairo @@ -44,7 +44,7 @@ fn detects_anagram() { fn detects_three_anagrams() { let word: ByteArray = "allergy"; let inputs = Set::new( - array!["gallery", "ballerina", "regally", "clergy", "largely", "leading",] + array!["gallery", "ballerina", "regally", "clergy", "largely", "leading"], ); let output = anagrams_for(@word, @inputs); let expected = Set::new(array!["gallery", "regally", "largely"]); diff --git a/exercises/practice/armstrong-numbers/.meta/example.cairo b/exercises/practice/armstrong-numbers/.meta/example.cairo index 04b5b4a1..e940259a 100644 --- a/exercises/practice/armstrong-numbers/.meta/example.cairo +++ b/exercises/practice/armstrong-numbers/.meta/example.cairo @@ -1,3 +1,5 @@ +use core::num::traits::Pow; + pub fn is_armstrong_number(mut num: u128) -> bool { let mut original_num = num; let digits = count_digits(num); @@ -7,7 +9,7 @@ pub fn is_armstrong_number(mut num: u128) -> bool { } let lastDigit = num % 10; - let sum = pow(lastDigit, digits); + let sum = lastDigit.pow(digits); num = num / 10; if sum > original_num { break false; @@ -16,7 +18,7 @@ pub fn is_armstrong_number(mut num: u128) -> bool { } } -fn count_digits(mut num: u128) -> u128 { +fn count_digits(mut num: u128) -> u32 { let mut res = 0; while num != 0 { num = num / 10; @@ -24,16 +26,3 @@ fn count_digits(mut num: u128) -> u128 { }; res } - -fn pow(base: u128, mut power: u128) -> u128 { - if base == 0 { - return base; - } - let base: u256 = base.into(); - let mut result = 1_u256; - while power != 0 { - result *= base; - power -= 1; - }; - result.try_into().expect('too large to fit output type') -} diff --git a/exercises/practice/armstrong-numbers/Scarb.toml b/exercises/practice/armstrong-numbers/Scarb.toml index 97a34027..02b3f94a 100644 --- a/exercises/practice/armstrong-numbers/Scarb.toml +++ b/exercises/practice/armstrong-numbers/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/atbash-cipher/Scarb.toml b/exercises/practice/atbash-cipher/Scarb.toml index d766f1c3..9b706313 100644 --- a/exercises/practice/atbash-cipher/Scarb.toml +++ b/exercises/practice/atbash-cipher/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/beer-song/.meta/example.cairo b/exercises/practice/beer-song/.meta/example.cairo index 3628f503..5c44a231 100644 --- a/exercises/practice/beer-song/.meta/example.cairo +++ b/exercises/practice/beer-song/.meta/example.cairo @@ -5,8 +5,8 @@ pub fn verse(n: u32) -> ByteArray { 2 => "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n", _ => format!( "{n} bottles of beer on the wall, {n} bottles of beer.\nTake one down and pass it around, {} bottles of beer on the wall.\n", - n - 1 - ) + n - 1, + ), } } diff --git a/exercises/practice/beer-song/Scarb.toml b/exercises/practice/beer-song/Scarb.toml index 9ef7bc34..7209f179 100644 --- a/exercises/practice/beer-song/Scarb.toml +++ b/exercises/practice/beer-song/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/beer-song/tests/beer_song.cairo b/exercises/practice/beer-song/tests/beer_song.cairo index fda435c9..aac6c29b 100644 --- a/exercises/practice/beer-song/tests/beer_song.cairo +++ b/exercises/practice/beer-song/tests/beer_song.cairo @@ -2,7 +2,7 @@ fn first_generic_verse() { assert_eq!( beer_song::verse(99), - "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n" + "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n", ); } @@ -11,7 +11,7 @@ fn first_generic_verse() { fn last_generic_verse() { assert_eq!( beer_song::verse(3), - "3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n" + "3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n", ); } @@ -20,7 +20,7 @@ fn last_generic_verse() { fn verse_with_2_bottles() { assert_eq!( beer_song::verse(2), - "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n" + "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n", ); } @@ -29,7 +29,7 @@ fn verse_with_2_bottles() { fn verse_with_1_bottle() { assert_eq!( beer_song::verse(1), - "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n" + "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n", ); } @@ -38,7 +38,7 @@ fn verse_with_1_bottle() { fn verse_with_0_bottles() { assert_eq!( beer_song::verse(0), - "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n" + "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n", ); } @@ -47,7 +47,7 @@ fn verse_with_0_bottles() { fn first_two_verses() { assert_eq!( beer_song::verses(99, 1), - "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n\n98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n" + "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n\n98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n", ); } @@ -56,7 +56,7 @@ fn first_two_verses() { fn last_three_verses() { assert_eq!( beer_song::verses(2, 2), - "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n\n1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n\nNo more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n" + "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n\n1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n\nNo more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n", ); } diff --git a/exercises/practice/binary-search-tree/.meta/example.cairo b/exercises/practice/binary-search-tree/.meta/example.cairo index 3c0c7a91..eaa2f127 100644 --- a/exercises/practice/binary-search-tree/.meta/example.cairo +++ b/exercises/practice/binary-search-tree/.meta/example.cairo @@ -20,27 +20,27 @@ pub impl BinarySearchTreeImpl of BinarySearchTreeTrait { fn add(self: BinarySearchTree, value: u32) -> BinarySearchTree { match self { Option::None => Option::Some( - BoxTrait::new(Node { value, left: Option::None, right: Option::None }) + BoxTrait::new(Node { value, left: Option::None, right: Option::None }), ), Option::Some(node) => { if value <= node.value { Option::Some( BoxTrait::new( Node { - value: node.value, left: node.left.add(value), right: node.right - } - ) + value: node.value, left: node.left.add(value), right: node.right, + }, + ), ) } else { Option::Some( BoxTrait::new( Node { - value: node.value, left: node.left, right: node.right.add(value) - } - ) + value: node.value, left: node.left, right: node.right.add(value), + }, + ), ) } - } + }, } } @@ -51,14 +51,14 @@ pub impl BinarySearchTreeImpl of BinarySearchTreeTrait { fn left(self: @BinarySearchTree) -> @BinarySearchTree { @match self { Option::None => Option::None, - Option::Some(bst) => bst.left + Option::Some(bst) => bst.left, } } fn right(self: @BinarySearchTree) -> @BinarySearchTree { @match self { Option::None => Option::None, - Option::Some(bst) => bst.right + Option::Some(bst) => bst.right, } } diff --git a/exercises/practice/binary-search-tree/Scarb.toml b/exercises/practice/binary-search-tree/Scarb.toml index 6b6ce880..c1a57b49 100644 --- a/exercises/practice/binary-search-tree/Scarb.toml +++ b/exercises/practice/binary-search-tree/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/binary-search/.meta/example.cairo b/exercises/practice/binary-search/.meta/example.cairo index 9330fff0..e00862f6 100644 --- a/exercises/practice/binary-search/.meta/example.cairo +++ b/exercises/practice/binary-search/.meta/example.cairo @@ -1,5 +1,5 @@ pub fn find, +Copy, +PartialOrd>( - search_array: @Array, value: T + search_array: @Array, value: T, ) -> Option { let mut base = 0_usize; let mut slice = search_array.span(); diff --git a/exercises/practice/binary-search/Scarb.toml b/exercises/practice/binary-search/Scarb.toml index e06895ec..8f42650e 100644 --- a/exercises/practice/binary-search/Scarb.toml +++ b/exercises/practice/binary-search/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/bob/.meta/example.cairo b/exercises/practice/bob/.meta/example.cairo index abaf2584..8dd6ecec 100644 --- a/exercises/practice/bob/.meta/example.cairo +++ b/exercises/practice/bob/.meta/example.cairo @@ -1,21 +1,15 @@ pub fn response(input: @ByteArray) -> ByteArray { if is_silent(input) { - return "Fine. Be that way!"; + "Fine. Be that way!" + } else if is_loud_question(input) { + "Calm down, I know what I'm doing!" + } else if is_loud_statement(input) { + "Whoa, chill out!" + } else if is_question(input) { + "Sure." + } else { + "Whatever." } - - if is_loud_question(input) { - return "Calm down, I know what I'm doing!"; - } - - if is_loud_statement(input) { - return "Whoa, chill out!"; - } - - if is_question(input) { - return "Sure."; - } - - "Whatever." } @@ -68,9 +62,10 @@ fn is_uppercase(c: u8) -> bool { fn to_uppercase(c: u8) -> u8 { if is_lowercase(c) { - return c - 32; + c - 32 + } else { + c } - return c; } fn is_whitespace(c: u8) -> bool { diff --git a/exercises/practice/bob/Scarb.toml b/exercises/practice/bob/Scarb.toml index 99cdda6d..e1343197 100644 --- a/exercises/practice/bob/Scarb.toml +++ b/exercises/practice/bob/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/clock/.meta/example.cairo b/exercises/practice/clock/.meta/example.cairo index e2344b13..268f4e4c 100644 --- a/exercises/practice/clock/.meta/example.cairo +++ b/exercises/practice/clock/.meta/example.cairo @@ -33,7 +33,7 @@ pub impl ClockImpl of ClockTrait { mins += 1440; }; let mins: u32 = mins.try_into().unwrap(); - Clock { minutes: mins % 1440, } + Clock { minutes: mins % 1440 } } fn add_minutes(ref self: Clock, minutes: i32) -> Clock { diff --git a/exercises/practice/clock/Scarb.toml b/exercises/practice/clock/Scarb.toml index 218bf6cf..a5e0f409 100644 --- a/exercises/practice/clock/Scarb.toml +++ b/exercises/practice/clock/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/collatz-conjecture/.meta/example.cairo b/exercises/practice/collatz-conjecture/.meta/example.cairo index e376b220..8ba0873e 100644 --- a/exercises/practice/collatz-conjecture/.meta/example.cairo +++ b/exercises/practice/collatz-conjecture/.meta/example.cairo @@ -13,5 +13,5 @@ pub fn steps(number: usize) -> usize { count += 1; }; - return count; + count } diff --git a/exercises/practice/collatz-conjecture/Scarb.toml b/exercises/practice/collatz-conjecture/Scarb.toml index 099c04cd..7784c847 100644 --- a/exercises/practice/collatz-conjecture/Scarb.toml +++ b/exercises/practice/collatz-conjecture/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/custom-set/.meta/example.cairo b/exercises/practice/custom-set/.meta/example.cairo index b580a89b..09db272d 100644 --- a/exercises/practice/custom-set/.meta/example.cairo +++ b/exercises/practice/custom-set/.meta/example.cairo @@ -4,7 +4,7 @@ struct CustomSet { } impl CustomSetEq< - T, +Copy, +Drop, +PartialEq, +core::fmt::Display + T, +Copy, +Drop, +PartialEq, +core::fmt::Display, > of PartialEq> { fn eq(lhs: @CustomSet, rhs: @CustomSet) -> bool { if lhs.collection.len() != rhs.collection.len() { @@ -16,10 +16,10 @@ impl CustomSetEq< #[generate_trait] pub impl CustomSetImpl< - T, +Copy, +Drop, +core::fmt::Display, +PartialEq + T, +Copy, +Drop, +core::fmt::Display, +PartialEq, > of CustomSetTrait { fn new(input: @Array) -> CustomSet { - let mut set = CustomSet:: { collection: array![], }; + let mut set = CustomSet:: { collection: array![] }; let input = input.span(); for val in input { set.add(val.clone()); diff --git a/exercises/practice/custom-set/Scarb.toml b/exercises/practice/custom-set/Scarb.toml index bef71c20..c5b3f6ea 100644 --- a/exercises/practice/custom-set/Scarb.toml +++ b/exercises/practice/custom-set/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/custom-set/src/lib.cairo b/exercises/practice/custom-set/src/lib.cairo index da934abd..181a82bd 100644 --- a/exercises/practice/custom-set/src/lib.cairo +++ b/exercises/practice/custom-set/src/lib.cairo @@ -2,7 +2,7 @@ struct CustomSet {} impl CustomSetEq< - T, +Copy, +Drop, +PartialEq, +core::fmt::Display + T, +Copy, +Drop, +PartialEq, +core::fmt::Display, > of PartialEq> { fn eq(lhs: @CustomSet, rhs: @CustomSet) -> bool { // determine whether the two CustomSets are equal @@ -12,7 +12,7 @@ impl CustomSetEq< #[generate_trait] pub impl CustomSetImpl< - T, +Copy, +Drop, +core::fmt::Display, +PartialEq + T, +Copy, +Drop, +core::fmt::Display, +PartialEq, > of CustomSetTrait { fn new(input: @Array) -> CustomSet { // construct a new CustomSet struct diff --git a/exercises/practice/darts/.meta/example.cairo b/exercises/practice/darts/.meta/example.cairo index 9f195a2b..39d2f4bd 100644 --- a/exercises/practice/darts/.meta/example.cairo +++ b/exercises/practice/darts/.meta/example.cairo @@ -1,16 +1,14 @@ pub fn score(x: i64, y: i64) -> u8 { let distance = sqrt(x * x + y * y); if distance <= 1 { - return 10; + 10 + } else if distance <= 5 { + 5 + } else if distance <= 10 { + 1 + } else { + 0 } - if distance <= 5 { - return 5; - } - if distance <= 10 { - return 1; - } - - return 0; } fn sqrt(radicand: i64) -> i64 { @@ -20,6 +18,5 @@ fn sqrt(radicand: i64) -> i64 { candidate += 1; }; } - - return candidate; + candidate } diff --git a/exercises/practice/darts/Scarb.toml b/exercises/practice/darts/Scarb.toml index d0279c4e..975bce83 100644 --- a/exercises/practice/darts/Scarb.toml +++ b/exercises/practice/darts/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/difference-of-squares/.meta/example.cairo b/exercises/practice/difference-of-squares/.meta/example.cairo index f3334079..0b38971f 100644 --- a/exercises/practice/difference-of-squares/.meta/example.cairo +++ b/exercises/practice/difference-of-squares/.meta/example.cairo @@ -1,35 +1,19 @@ -pub fn squareOfSum(number: u64) -> u64 { +pub fn square_of_sum(number: u64) -> u64 { let mut sum = 0; - let mut current = 1; - - loop { - if current > number { - break; - } - + for current in 1..(number + 1) { sum += current; - current += 1; }; - - return sum * sum; + sum * sum } -pub fn sumOfSquares(number: u64) -> u64 { +pub fn sum_of_squares(number: u64) -> u64 { let mut sum = 0; - let mut current = 1; - - loop { - if current > number { - break; - } - + for current in 1..(number + 1) { sum += current * current; - current += 1; }; - - return sum; + sum } -pub fn differenceOfSquares(number: u64) -> u64 { - return squareOfSum(number) - sumOfSquares(number); +pub fn difference_of_squares(number: u64) -> u64 { + square_of_sum(number) - sum_of_squares(number) } diff --git a/exercises/practice/difference-of-squares/Scarb.toml b/exercises/practice/difference-of-squares/Scarb.toml index b66f73c3..a8ca4ffb 100644 --- a/exercises/practice/difference-of-squares/Scarb.toml +++ b/exercises/practice/difference-of-squares/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/difference-of-squares/src/lib.cairo b/exercises/practice/difference-of-squares/src/lib.cairo index 4fd4420b..5daddb71 100644 --- a/exercises/practice/difference-of-squares/src/lib.cairo +++ b/exercises/practice/difference-of-squares/src/lib.cairo @@ -1,11 +1,11 @@ -pub fn squareOfSum(number: u64) -> u64 { - panic!("implement `squareOfSum`") +pub fn square_of_sum(number: u64) -> u64 { + panic!("implement `square_of_sum`") } -pub fn sumOfSquares(number: u64) -> u64 { - panic!("implement `sumOfSquares`") +pub fn sum_of_squares(number: u64) -> u64 { + panic!("implement `sum_of_squares`") } -pub fn differenceOfSquares(number: u64) -> u64 { - panic!("implement `differenceOfSquares`") +pub fn difference_of_squares(number: u64) -> u64 { + panic!("implement `difference_of_squares`") } diff --git a/exercises/practice/difference-of-squares/tests/difference_of_squares.cairo b/exercises/practice/difference-of-squares/tests/difference_of_squares.cairo index 66075f67..09e27ba9 100644 --- a/exercises/practice/difference-of-squares/tests/difference_of_squares.cairo +++ b/exercises/practice/difference-of-squares/tests/difference_of_squares.cairo @@ -1,8 +1,10 @@ -use difference_of_squares::{squareOfSum, sumOfSquares, differenceOfSquares}; +use difference_of_squares::{ + square_of_sum, sum_of_squares, difference_of_squares as diff_of_squares, +}; #[test] fn square_of_sum_1() { - let output = squareOfSum(1); + let output = square_of_sum(1); let expected = 1; assert_eq!(output, expected); } @@ -10,7 +12,7 @@ fn square_of_sum_1() { #[test] #[ignore] fn square_of_sum_5() { - let output = squareOfSum(5); + let output = square_of_sum(5); let expected = 225; assert_eq!(output, expected); } @@ -18,7 +20,7 @@ fn square_of_sum_5() { #[test] #[ignore] fn square_of_sum_100() { - let output = squareOfSum(100); + let output = square_of_sum(100); let expected = 25502500; assert_eq!(output, expected); } @@ -26,7 +28,7 @@ fn square_of_sum_100() { #[test] #[ignore] fn sum_of_squares_1() { - let output = sumOfSquares(1); + let output = sum_of_squares(1); let expected = 1; assert_eq!(output, expected); } @@ -34,7 +36,7 @@ fn sum_of_squares_1() { #[test] #[ignore] fn sum_of_squares_5() { - let output = sumOfSquares(5); + let output = sum_of_squares(5); let expected = 55; assert_eq!(output, expected); } @@ -42,7 +44,7 @@ fn sum_of_squares_5() { #[test] #[ignore] fn sum_of_squares_100() { - let output = sumOfSquares(100); + let output = sum_of_squares(100); let expected = 338350; assert_eq!(output, expected); } @@ -50,7 +52,7 @@ fn sum_of_squares_100() { #[test] #[ignore] fn difference_of_squares_1() { - let output = differenceOfSquares(1); + let output = diff_of_squares(1); let expected = 0; assert_eq!(output, expected); } @@ -58,7 +60,7 @@ fn difference_of_squares_1() { #[test] #[ignore] fn difference_of_squares_5() { - let output = differenceOfSquares(5); + let output = diff_of_squares(5); let expected = 170; assert_eq!(output, expected); } @@ -66,7 +68,7 @@ fn difference_of_squares_5() { #[test] #[ignore] fn difference_of_squares_100() { - let output = differenceOfSquares(100); + let output = diff_of_squares(100); let expected = 25164150; assert_eq!(output, expected); } diff --git a/exercises/practice/dominoes/.meta/example.cairo b/exercises/practice/dominoes/.meta/example.cairo index c0ef58e6..eb38bf08 100644 --- a/exercises/practice/dominoes/.meta/example.cairo +++ b/exercises/practice/dominoes/.meta/example.cairo @@ -10,7 +10,7 @@ pub type Domino = (u8, u8); #[derive(Destruct)] struct AvailabilityTable { d: Felt252Dict, - len: usize + len: usize, } fn index(x: u8, y: u8) -> u8 { @@ -117,7 +117,7 @@ pub fn chain(dominoes: @Array) -> Option> { } else { Option::None } - } + }, } } diff --git a/exercises/practice/dominoes/Scarb.toml b/exercises/practice/dominoes/Scarb.toml index 4f4d3957..d71adc8d 100644 --- a/exercises/practice/dominoes/Scarb.toml +++ b/exercises/practice/dominoes/Scarb.toml @@ -4,6 +4,6 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html diff --git a/exercises/practice/dominoes/tests/dominoes.cairo b/exercises/practice/dominoes/tests/dominoes.cairo index 7f5d7468..de272649 100644 --- a/exercises/practice/dominoes/tests/dominoes.cairo +++ b/exercises/practice/dominoes/tests/dominoes.cairo @@ -6,11 +6,11 @@ enum CheckResult { GotInvalid, // chain returned None Correct, ChainingFailure: Array< - Domino + Domino, >, // failure to match the dots at the right side of one domino with // the one on the left side of the next LengthMismatch: Array, - DominoMismatch: Array, // different dominoes are used in input and output + DominoMismatch: Array // different dominoes are used in input and output } fn normalize(d: Domino) -> Domino { @@ -55,7 +55,7 @@ fn check(input: @Array) -> CheckResult { n = second; i += 1; } - } + }, } } @@ -131,7 +131,7 @@ fn assert_correct(input: @Array) { }, CheckResult::DominoMismatch(output) => { panic!("Domino mismatch for input {input:?}, output {output:?}") - } + }, } } diff --git a/exercises/practice/eliuds-eggs/.meta/example.cairo b/exercises/practice/eliuds-eggs/.meta/example.cairo index f3cf24ce..2e3eb530 100644 --- a/exercises/practice/eliuds-eggs/.meta/example.cairo +++ b/exercises/practice/eliuds-eggs/.meta/example.cairo @@ -14,5 +14,5 @@ pub fn eggCount(number: u64) -> u64 { current /= 2; }; - return count; + count } diff --git a/exercises/practice/eliuds-eggs/Scarb.toml b/exercises/practice/eliuds-eggs/Scarb.toml index 14c72160..2c7a9896 100644 --- a/exercises/practice/eliuds-eggs/Scarb.toml +++ b/exercises/practice/eliuds-eggs/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/grains/.meta/example.cairo b/exercises/practice/grains/.meta/example.cairo index 8709fe69..3f414249 100644 --- a/exercises/practice/grains/.meta/example.cairo +++ b/exercises/practice/grains/.meta/example.cairo @@ -1,6 +1,8 @@ +use core::num::traits::Pow; + pub fn square(s: u8) -> u64 { assert!(1 <= s && s <= 64, "square must be between 1 and 64"); - pow(2, s - 1) + 2_u64.pow(s.into() - 1) } pub fn total() -> u64 { @@ -10,16 +12,3 @@ pub fn total() -> u64 { }; result } - -fn pow(base: u8, mut power: u8) -> u64 { - if base == 0 { - return base.into(); - } - let base: u64 = base.into(); - let mut result = 1_u64; - while power != 0 { - result *= base; - power -= 1; - }; - result.try_into().expect('too large to fit output type') -} diff --git a/exercises/practice/grains/Scarb.toml b/exercises/practice/grains/Scarb.toml index 09fde667..1b2546b4 100644 --- a/exercises/practice/grains/Scarb.toml +++ b/exercises/practice/grains/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/hamming/.meta/example.cairo b/exercises/practice/hamming/.meta/example.cairo index 73840d7f..c3564ee1 100644 --- a/exercises/practice/hamming/.meta/example.cairo +++ b/exercises/practice/hamming/.meta/example.cairo @@ -18,5 +18,5 @@ pub fn distance(strand1: ByteArray, strand2: ByteArray) -> u256 { i += 1; }; - return count; + count } diff --git a/exercises/practice/hamming/Scarb.toml b/exercises/practice/hamming/Scarb.toml index 2414f8e7..68d71b10 100644 --- a/exercises/practice/hamming/Scarb.toml +++ b/exercises/practice/hamming/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/hello-world/Scarb.toml b/exercises/practice/hello-world/Scarb.toml index c6a28af3..53eec7cc 100644 --- a/exercises/practice/hello-world/Scarb.toml +++ b/exercises/practice/hello-world/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/high-scores/.meta/example.cairo b/exercises/practice/high-scores/.meta/example.cairo index 47041474..e4f6384b 100644 --- a/exercises/practice/high-scores/.meta/example.cairo +++ b/exercises/practice/high-scores/.meta/example.cairo @@ -1,6 +1,6 @@ use core::dict::Felt252Dict; -#[derive(Drop,)] +#[derive(Drop)] pub struct HighScores { scores: Array, } @@ -18,7 +18,7 @@ pub impl HighScoresImpl of HighScoresTrait { fn latest(self: @HighScores) -> Option { match self.scores.get(self.scores.len() - 1) { Option::Some(boxed) => Option::Some(*boxed.unbox()), - _ => Option::None + _ => Option::None, } } @@ -56,17 +56,15 @@ fn insertion_sort(span: Span) -> Array { sorted.insert(0, *span[0]); // insert all elements in their sorted position - for i in 1 - ..span - .len() { - let elem = *span[i]; - let mut j: felt252 = i.into(); - while j != 0 && elem > sorted.get(j - 1) { - sorted.insert(j, sorted.get(j - 1)); - j -= 1; - }; - sorted.insert(j.into(), elem); - }; + for i in 1..span.len() { + let elem = *span[i]; + let mut j: felt252 = i.into(); + while j != 0 && elem > sorted.get(j - 1) { + sorted.insert(j, sorted.get(j - 1)); + j -= 1; + }; + sorted.insert(j.into(), elem); + }; // collect all elements into an array let mut sorted_arr: Array = array![]; diff --git a/exercises/practice/high-scores/Scarb.toml b/exercises/practice/high-scores/Scarb.toml index 679160df..1161da8f 100644 --- a/exercises/practice/high-scores/Scarb.toml +++ b/exercises/practice/high-scores/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/high-scores/src/lib.cairo b/exercises/practice/high-scores/src/lib.cairo index 9365d5b8..a0842b56 100644 --- a/exercises/practice/high-scores/src/lib.cairo +++ b/exercises/practice/high-scores/src/lib.cairo @@ -1,4 +1,4 @@ -#[derive(Drop,)] +#[derive(Drop)] pub struct HighScores {} #[generate_trait] diff --git a/exercises/practice/isbn-verifier/Scarb.toml b/exercises/practice/isbn-verifier/Scarb.toml index 7055904b..9332e797 100644 --- a/exercises/practice/isbn-verifier/Scarb.toml +++ b/exercises/practice/isbn-verifier/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/isogram/.meta/example.cairo b/exercises/practice/isogram/.meta/example.cairo index b3775bc4..0672c48f 100644 --- a/exercises/practice/isogram/.meta/example.cairo +++ b/exercises/practice/isogram/.meta/example.cairo @@ -19,13 +19,13 @@ pub fn is_isogram(phrase: ByteArray) -> bool { i += 1; }; - return success; + success } pub fn lowercase(chr: u8) -> u8 { if chr >= 'A' && chr <= 'Z' { - return chr + 32; + chr + 32 } else { - return chr; + chr } } diff --git a/exercises/practice/isogram/Scarb.toml b/exercises/practice/isogram/Scarb.toml index bc1fd2a2..9e41b5b4 100644 --- a/exercises/practice/isogram/Scarb.toml +++ b/exercises/practice/isogram/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/kindergarten-garden/.meta/example.cairo b/exercises/practice/kindergarten-garden/.meta/example.cairo index 0784baef..eae1c252 100644 --- a/exercises/practice/kindergarten-garden/.meta/example.cairo +++ b/exercises/practice/kindergarten-garden/.meta/example.cairo @@ -3,7 +3,7 @@ pub enum Plant { Radishes, Clover, Grass, - Violets + Violets, } #[derive(Drop)] @@ -87,5 +87,5 @@ pub fn plants(diagram: ByteArray, student: Student) -> Array { let plant3 = plant_from_char(line2[start]); let plant4 = plant_from_char(line2[start + 1]); - array![plant1, plant2, plant3, plant4,] + array![plant1, plant2, plant3, plant4] } diff --git a/exercises/practice/kindergarten-garden/Scarb.toml b/exercises/practice/kindergarten-garden/Scarb.toml index 01b6a1ff..c22e5c15 100644 --- a/exercises/practice/kindergarten-garden/Scarb.toml +++ b/exercises/practice/kindergarten-garden/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/kindergarten-garden/src/lib.cairo b/exercises/practice/kindergarten-garden/src/lib.cairo index 5aa9d38e..36130f38 100644 --- a/exercises/practice/kindergarten-garden/src/lib.cairo +++ b/exercises/practice/kindergarten-garden/src/lib.cairo @@ -3,7 +3,7 @@ pub enum Plant { Radishes, Clover, Grass, - Violets + Violets, } #[derive(Drop)] diff --git a/exercises/practice/knapsack/.meta/example.cairo b/exercises/practice/knapsack/.meta/example.cairo index b90d33e9..f9c70b2b 100644 --- a/exercises/practice/knapsack/.meta/example.cairo +++ b/exercises/practice/knapsack/.meta/example.cairo @@ -32,27 +32,23 @@ impl MatrixImpl of MatrixTrait { pub fn maximum_value(maximum_weight: u32, items: Span) -> u32 { let mut max_values = MatrixTrait::new(num_of_cols: maximum_weight + 1); - for row in 1 - ..items.len() - + 1 { - let item_index = row - 1; - let item_weight = *items[item_index].weight; - let item_value = *items[item_index].value; - - for w in 0 - ..maximum_weight - + 1 { - if item_weight <= w { - let max_val = core::cmp::max( - max_values.at(item_index, w), - max_values.at(item_index, w - item_weight) + item_value, - ); - max_values.set(row, w, max_val); - } else { - max_values.set(row, w, max_values.at(item_index, w)); - } - } - }; + for row in 1..items.len() + 1 { + let item_index = row - 1; + let item_weight = *items[item_index].weight; + let item_value = *items[item_index].value; + + for w in 0..maximum_weight + 1 { + if item_weight <= w { + let max_val = core::cmp::max( + max_values.at(item_index, w), + max_values.at(item_index, w - item_weight) + item_value, + ); + max_values.set(row, w, max_val); + } else { + max_values.set(row, w, max_values.at(item_index, w)); + } + } + }; max_values.at(items.len(), maximum_weight) } diff --git a/exercises/practice/knapsack/Scarb.toml b/exercises/practice/knapsack/Scarb.toml index 16914b50..e08d60d1 100644 --- a/exercises/practice/knapsack/Scarb.toml +++ b/exercises/practice/knapsack/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/knapsack/tests/knapsack.cairo b/exercises/practice/knapsack/tests/knapsack.cairo index 78c2aab3..8196771a 100644 --- a/exercises/practice/knapsack/tests/knapsack.cairo +++ b/exercises/practice/knapsack/tests/knapsack.cairo @@ -13,7 +13,7 @@ fn no_items() { #[ignore] fn one_item_too_heavy() { let max_weight = 10; - let items = array![Item { weight: 100, value: 1, }]; + let items = array![Item { weight: 100, value: 1 }]; let output = maximum_value(max_weight, items.span()); let expected = 0; assert_eq!(output, expected); @@ -24,11 +24,11 @@ fn one_item_too_heavy() { fn five_items_cannot_be_greedy_by_weight() { let max_weight = 10; let items = array![ - Item { weight: 2, value: 5, }, - Item { weight: 2, value: 5, }, - Item { weight: 2, value: 5, }, - Item { weight: 2, value: 5, }, - Item { weight: 10, value: 21, }, + Item { weight: 2, value: 5 }, + Item { weight: 2, value: 5 }, + Item { weight: 2, value: 5 }, + Item { weight: 2, value: 5 }, + Item { weight: 10, value: 21 }, ]; let output = maximum_value(max_weight, items.span()); let expected = 21; @@ -40,11 +40,11 @@ fn five_items_cannot_be_greedy_by_weight() { fn five_items_cannot_be_greedy_by_value() { let max_weight = 10; let items = array![ - Item { weight: 2, value: 20, }, - Item { weight: 2, value: 20, }, - Item { weight: 2, value: 20, }, - Item { weight: 2, value: 20, }, - Item { weight: 10, value: 50, }, + Item { weight: 2, value: 20 }, + Item { weight: 2, value: 20 }, + Item { weight: 2, value: 20 }, + Item { weight: 2, value: 20 }, + Item { weight: 10, value: 50 }, ]; let output = maximum_value(max_weight, items.span()); let expected = 80; @@ -56,10 +56,10 @@ fn five_items_cannot_be_greedy_by_value() { fn example_knapsack() { let max_weight = 10; let items = array![ - Item { weight: 5, value: 10, }, - Item { weight: 4, value: 40, }, - Item { weight: 6, value: 30, }, - Item { weight: 4, value: 50, }, + Item { weight: 5, value: 10 }, + Item { weight: 4, value: 40 }, + Item { weight: 6, value: 30 }, + Item { weight: 4, value: 50 }, ]; let output = maximum_value(max_weight, items.span()); let expected = 90; @@ -71,14 +71,14 @@ fn example_knapsack() { fn test_8_items() { let max_weight = 104; let items = array![ - Item { weight: 25, value: 350, }, - Item { weight: 35, value: 400, }, - Item { weight: 45, value: 450, }, - Item { weight: 5, value: 20, }, - Item { weight: 25, value: 70, }, - Item { weight: 3, value: 8, }, - Item { weight: 2, value: 5, }, - Item { weight: 2, value: 5, }, + Item { weight: 25, value: 350 }, + Item { weight: 35, value: 400 }, + Item { weight: 45, value: 450 }, + Item { weight: 5, value: 20 }, + Item { weight: 25, value: 70 }, + Item { weight: 3, value: 8 }, + Item { weight: 2, value: 5 }, + Item { weight: 2, value: 5 }, ]; let output = maximum_value(max_weight, items.span()); let expected = 900; @@ -90,21 +90,21 @@ fn test_8_items() { fn test_15_items() { let max_weight = 750; let items = array![ - Item { weight: 70, value: 135, }, - Item { weight: 73, value: 139, }, - Item { weight: 77, value: 149, }, - Item { weight: 80, value: 150, }, - Item { weight: 82, value: 156, }, - Item { weight: 87, value: 163, }, - Item { weight: 90, value: 173, }, - Item { weight: 94, value: 184, }, - Item { weight: 98, value: 192, }, - Item { weight: 106, value: 201, }, - Item { weight: 110, value: 210, }, - Item { weight: 113, value: 214, }, - Item { weight: 115, value: 221, }, - Item { weight: 118, value: 229, }, - Item { weight: 120, value: 240, }, + Item { weight: 70, value: 135 }, + Item { weight: 73, value: 139 }, + Item { weight: 77, value: 149 }, + Item { weight: 80, value: 150 }, + Item { weight: 82, value: 156 }, + Item { weight: 87, value: 163 }, + Item { weight: 90, value: 173 }, + Item { weight: 94, value: 184 }, + Item { weight: 98, value: 192 }, + Item { weight: 106, value: 201 }, + Item { weight: 110, value: 210 }, + Item { weight: 113, value: 214 }, + Item { weight: 115, value: 221 }, + Item { weight: 118, value: 229 }, + Item { weight: 120, value: 240 }, ]; let output = maximum_value(max_weight, items.span()); let expected = 1458; diff --git a/exercises/practice/largest-series-product/.meta/example.cairo b/exercises/practice/largest-series-product/.meta/example.cairo index edbaebdd..d0f99707 100644 --- a/exercises/practice/largest-series-product/.meta/example.cairo +++ b/exercises/practice/largest-series-product/.meta/example.cairo @@ -3,7 +3,7 @@ pub enum Error { SpanTooLong, InvalidDigit: u8, NegativeSpan, - IndexOutOfBounds + IndexOutOfBounds, } #[derive(Drop, Copy)] @@ -36,7 +36,7 @@ pub fn lsp(input: @ByteArray, span: i32) -> Result { } fn product_from( - input: @ByteArray, span: u32, from: u32, remaining: u32, accumulated: Product + input: @ByteArray, span: u32, from: u32, remaining: u32, accumulated: Product, ) -> Result { if remaining == 0 { return Result::Ok(accumulated); @@ -50,22 +50,20 @@ fn product_from( let digit = input.at(from).try_into_digit()?; if digit == 0 { - return product_from( - input, span, from + 1, span, Product { value: 1, start_index: from + 1 } - ); + product_from(input, span, from + 1, span, Product { value: 1, start_index: from + 1 }) } else { - return product_from( + product_from( input, span, from + 1, remaining - 1, - Product { value: accumulated.value * digit, start_index: accumulated.start_index } - ); + Product { value: accumulated.value * digit, start_index: accumulated.start_index }, + ) } } fn max_product( - input: @ByteArray, span: u32, previous: u64, from: u32, max: u64 + input: @ByteArray, span: u32, previous: u64, from: u32, max: u64, ) -> Result { if from + span >= input.len() { return Result::Ok(max); @@ -77,7 +75,7 @@ fn max_product( // every product that includes digit 0 will be 0, // so calculate the next product after the digit 0 product_from( - input, span, from + span + 1, span, Product { value: 1, start_index: from + span + 1 } + input, span, from + span + 1, span, Product { value: 1, start_index: from + span + 1 }, )? } else { // safe to unwrap, we already processed this digit before diff --git a/exercises/practice/largest-series-product/Scarb.toml b/exercises/practice/largest-series-product/Scarb.toml index 3039c0d6..ccbf2ba7 100644 --- a/exercises/practice/largest-series-product/Scarb.toml +++ b/exercises/practice/largest-series-product/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/leap/Scarb.toml b/exercises/practice/leap/Scarb.toml index e05f57d6..21ed3492 100644 --- a/exercises/practice/leap/Scarb.toml +++ b/exercises/practice/leap/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/linked-list/.meta/example.cairo b/exercises/practice/linked-list/.meta/example.cairo index ff3b9cc3..3caeed8e 100644 --- a/exercises/practice/linked-list/.meta/example.cairo +++ b/exercises/practice/linked-list/.meta/example.cairo @@ -20,16 +20,16 @@ impl DestructDoublyLinkedList, +Felt252DictValue> of Destruct { station: T, next: Index, - previous: Index + previous: Index, } #[generate_trait] pub impl DoublyLinkedListImpl< - T, +Drop, +Copy, +PartialEq, +Felt252DictValue + T, +Drop, +Copy, +PartialEq, +Felt252DictValue, > of DoublyLinkedListTrait { fn new() -> DoublyLinkedList { DoublyLinkedList { - dict: Default::default(), head: Option::None, tail: Option::None, len: 0, next_index: 0 + dict: Default::default(), head: Option::None, tail: Option::None, len: 0, next_index: 0, } } @@ -83,7 +83,7 @@ pub impl DoublyLinkedListImpl< self.dict.insert(self.tail.unwrap(), NullableTrait::new(new_tail)); Option::Some(popped_tail.station) - } + }, } } @@ -110,7 +110,7 @@ pub impl DoublyLinkedListImpl< self.dict.insert(self.head.unwrap(), NullableTrait::new(new_head)); Option::Some(shifted_head.station) - } + }, } } diff --git a/exercises/practice/linked-list/Scarb.toml b/exercises/practice/linked-list/Scarb.toml index 5a94f714..6f95bcc2 100644 --- a/exercises/practice/linked-list/Scarb.toml +++ b/exercises/practice/linked-list/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/luhn/.meta/example.cairo b/exercises/practice/luhn/.meta/example.cairo index 0d0f2f9d..7a6cfced 100644 --- a/exercises/practice/luhn/.meta/example.cairo +++ b/exercises/practice/luhn/.meta/example.cairo @@ -35,7 +35,7 @@ pub fn valid(candidate: ByteArray) -> bool { Option::None => { valid = false; break; - } + }, }; // Process digit according to Luhn's algorithm diff --git a/exercises/practice/luhn/Scarb.toml b/exercises/practice/luhn/Scarb.toml index d67c0f9a..ecc2b3fd 100644 --- a/exercises/practice/luhn/Scarb.toml +++ b/exercises/practice/luhn/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/matching-brackets/.meta/example.cairo b/exercises/practice/matching-brackets/.meta/example.cairo index 1e714c6e..feec651a 100644 --- a/exercises/practice/matching-brackets/.meta/example.cairo +++ b/exercises/practice/matching-brackets/.meta/example.cairo @@ -40,7 +40,7 @@ pub fn is_paired(value: ByteArray) -> bool { result = stack.is_empty(); } - return result; + result } fn paired_brackets() -> Felt252Dict { @@ -48,5 +48,5 @@ fn paired_brackets() -> Felt252Dict { pairs.insert('{', '}'); pairs.insert('[', ']'); pairs.insert('(', ')'); - return pairs; + pairs } diff --git a/exercises/practice/matching-brackets/Scarb.toml b/exercises/practice/matching-brackets/Scarb.toml index 00f3e18b..622c8a09 100644 --- a/exercises/practice/matching-brackets/Scarb.toml +++ b/exercises/practice/matching-brackets/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/minesweeper/.meta/example.cairo b/exercises/practice/minesweeper/.meta/example.cairo index 083cca0b..3ba77629 100644 --- a/exercises/practice/minesweeper/.meta/example.cairo +++ b/exercises/practice/minesweeper/.meta/example.cairo @@ -14,11 +14,10 @@ impl BoardImpl of BoardTrait { let num_rows = *self.num_rows; // Process each row - for y in 0 - ..num_rows { - let annotated_row = self.annotated_row(y); - annotated_board.append(annotated_row); - }; + for y in 0..num_rows { + let annotated_row = self.annotated_row(y); + annotated_board.append(annotated_row); + }; annotated_board } @@ -29,18 +28,17 @@ impl BoardImpl of BoardTrait { let num_cols = *self.num_cols; // Process each cell in the row - for x in 0 - ..num_cols { - let c = self.pieces[y].at(x).expect('indexes should be correct'); - - // If it's an empty square (' '), count neighboring mines - if c == ' ' { - let char_count = self.count_neighbouring_mines_char(x, y); - row.append_byte(char_count); - } else { - row.append_byte(c); - } - }; + for x in 0..num_cols { + let c = self.pieces[y].at(x).expect('indexes should be correct'); + + // If it's an empty square (' '), count neighboring mines + if c == ' ' { + let char_count = self.count_neighbouring_mines_char(x, y); + row.append_byte(char_count); + } else { + row.append_byte(c); + } + }; row } @@ -52,12 +50,8 @@ impl BoardImpl of BoardTrait { let num_rows = self.num_rows; // Iterate through neighboring cells - for x1 in neighbouring_points( - x, num_cols - ) { - for y1 in neighbouring_points( - y, num_rows - ) { + for x1 in neighbouring_points(x, num_cols) { + for y1 in neighbouring_points(y, num_rows) { let piece = self.pieces[y1].at(x1).expect('indexes should be correct'); if piece == '*' { count += 1; @@ -79,7 +73,7 @@ pub fn annotate(pieces: Span) -> Array { return array![]; } - let board = Board { pieces, num_rows: pieces.len(), num_cols: pieces.at(0).len(), }; + let board = Board { pieces, num_rows: pieces.len(), num_cols: pieces.at(0).len() }; board.annotated() } diff --git a/exercises/practice/minesweeper/Scarb.toml b/exercises/practice/minesweeper/Scarb.toml index 5493feed..6816b4c6 100644 --- a/exercises/practice/minesweeper/Scarb.toml +++ b/exercises/practice/minesweeper/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/nth-prime/Scarb.toml b/exercises/practice/nth-prime/Scarb.toml index 4d4cd9f5..ca0dc44b 100644 --- a/exercises/practice/nth-prime/Scarb.toml +++ b/exercises/practice/nth-prime/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/nucleotide-count/.meta/example.cairo b/exercises/practice/nucleotide-count/.meta/example.cairo index 6fa00df5..72adc351 100644 --- a/exercises/practice/nucleotide-count/.meta/example.cairo +++ b/exercises/practice/nucleotide-count/.meta/example.cairo @@ -3,7 +3,7 @@ pub struct Counter { pub a: u64, pub c: u64, pub g: u64, - pub t: u64 + pub t: u64, } pub fn counts(strand: ByteArray) -> Counter { diff --git a/exercises/practice/nucleotide-count/Scarb.toml b/exercises/practice/nucleotide-count/Scarb.toml index f2ad2e61..d05a4ae0 100644 --- a/exercises/practice/nucleotide-count/Scarb.toml +++ b/exercises/practice/nucleotide-count/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/nucleotide-count/src/lib.cairo b/exercises/practice/nucleotide-count/src/lib.cairo index 1e9f32a8..bc5d404f 100644 --- a/exercises/practice/nucleotide-count/src/lib.cairo +++ b/exercises/practice/nucleotide-count/src/lib.cairo @@ -3,7 +3,7 @@ pub struct Counter { pub a: u64, pub c: u64, pub g: u64, - pub t: u64 + pub t: u64, } pub fn counts(strand: ByteArray) -> Counter { diff --git a/exercises/practice/pangram/.meta/example.cairo b/exercises/practice/pangram/.meta/example.cairo index bbf0ad22..0b48fc56 100644 --- a/exercises/practice/pangram/.meta/example.cairo +++ b/exercises/practice/pangram/.meta/example.cairo @@ -25,5 +25,5 @@ pub fn is_pangram(sentence: ByteArray) -> bool { curr += 1; }; - return success; + success } diff --git a/exercises/practice/pangram/Scarb.toml b/exercises/practice/pangram/Scarb.toml index 1914db89..9b0d1307 100644 --- a/exercises/practice/pangram/Scarb.toml +++ b/exercises/practice/pangram/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/pascals-triangle/.meta/example.cairo b/exercises/practice/pascals-triangle/.meta/example.cairo index b1594556..709a961d 100644 --- a/exercises/practice/pascals-triangle/.meta/example.cairo +++ b/exercises/practice/pascals-triangle/.meta/example.cairo @@ -33,5 +33,5 @@ pub fn rows(count: u32) -> Array> { i += 1; }; - return rows; + rows } diff --git a/exercises/practice/pascals-triangle/Scarb.toml b/exercises/practice/pascals-triangle/Scarb.toml index b53b61e0..46c1fe31 100644 --- a/exercises/practice/pascals-triangle/Scarb.toml +++ b/exercises/practice/pascals-triangle/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/pascals-triangle/tests/pascals_triangle.cairo b/exercises/practice/pascals-triangle/tests/pascals_triangle.cairo index 73f70615..cc5125bd 100644 --- a/exercises/practice/pascals-triangle/tests/pascals_triangle.cairo +++ b/exercises/practice/pascals-triangle/tests/pascals_triangle.cairo @@ -36,7 +36,7 @@ fn three_rows() { fn four_rows() { let output = rows(4); let expected: Array> = array![ - array![1], array![1, 1], array![1, 2, 1], array![1, 3, 3, 1] + array![1], array![1, 1], array![1, 2, 1], array![1, 3, 3, 1], ]; assert_eq!(output, expected); } @@ -46,7 +46,7 @@ fn four_rows() { fn five_rows() { let output = rows(5); let expected: Array> = array![ - array![1], array![1, 1], array![1, 2, 1], array![1, 3, 3, 1], array![1, 4, 6, 4, 1] + array![1], array![1, 1], array![1, 2, 1], array![1, 3, 3, 1], array![1, 4, 6, 4, 1], ]; assert_eq!(output, expected); } @@ -61,7 +61,7 @@ fn six_rows() { array![1, 2, 1], array![1, 3, 3, 1], array![1, 4, 6, 4, 1], - array![1, 5, 10, 10, 5, 1] + array![1, 5, 10, 10, 5, 1], ]; assert_eq!(output, expected); } @@ -80,7 +80,7 @@ fn ten_rows() { array![1, 6, 15, 20, 15, 6, 1], array![1, 7, 21, 35, 35, 21, 7, 1], array![1, 8, 28, 56, 70, 56, 28, 8, 1], - array![1, 9, 36, 84, 126, 126, 84, 36, 9, 1] + array![1, 9, 36, 84, 126, 126, 84, 36, 9, 1], ]; assert_eq!(output, expected); } diff --git a/exercises/practice/perfect-numbers/.meta/example.cairo b/exercises/practice/perfect-numbers/.meta/example.cairo index 3c9de301..731ac01a 100644 --- a/exercises/practice/perfect-numbers/.meta/example.cairo +++ b/exercises/practice/perfect-numbers/.meta/example.cairo @@ -42,6 +42,5 @@ fn sqrt(radicand: u64) -> u64 { candidate += 1; }; } - - return candidate; + candidate } diff --git a/exercises/practice/perfect-numbers/Scarb.toml b/exercises/practice/perfect-numbers/Scarb.toml index 9a204b3c..b48efccd 100644 --- a/exercises/practice/perfect-numbers/Scarb.toml +++ b/exercises/practice/perfect-numbers/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/phone-number/.meta/example.cairo b/exercises/practice/phone-number/.meta/example.cairo index 2e5bf70c..0f06050b 100644 --- a/exercises/practice/phone-number/.meta/example.cairo +++ b/exercises/practice/phone-number/.meta/example.cairo @@ -35,7 +35,7 @@ pub fn clean(phrase: ByteArray) -> ByteArray { assert!(cleaned[3] != '0', "exchange code cannot start with zero"); assert!(cleaned[3] != '1', "exchange code cannot start with one"); - return cleaned; + cleaned } @@ -45,13 +45,13 @@ fn assert_valid(c: u8) { } fn is_alphabetic(c: u8) -> bool { - return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'; + c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' } fn is_numeric(c: u8) -> bool { - return c >= '0' && c <= '9'; + c >= '0' && c <= '9' } fn is_allowed_punctuation(c: u8) -> bool { - return c == '(' || c == ')' || c == '-' || c == ' ' || c == '.' || c == '+'; + c == '(' || c == ')' || c == '-' || c == ' ' || c == '.' || c == '+' } diff --git a/exercises/practice/phone-number/Scarb.toml b/exercises/practice/phone-number/Scarb.toml index 4737bad2..f9425308 100644 --- a/exercises/practice/phone-number/Scarb.toml +++ b/exercises/practice/phone-number/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/prime-factors/Scarb.toml b/exercises/practice/prime-factors/Scarb.toml index 29bdbcaa..c4572df0 100644 --- a/exercises/practice/prime-factors/Scarb.toml +++ b/exercises/practice/prime-factors/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/protein-translation/.meta/example.cairo b/exercises/practice/protein-translation/.meta/example.cairo index eed25a64..a774c432 100644 --- a/exercises/practice/protein-translation/.meta/example.cairo +++ b/exercises/practice/protein-translation/.meta/example.cairo @@ -15,7 +15,7 @@ pub enum AminoAcid { #[derive(Drop, Copy)] enum Codon { AminoAcid: AminoAcid, - Stop + Stop, } pub fn proteins(strand: ByteArray) -> Array { @@ -37,9 +37,9 @@ pub fn proteins(strand: ByteArray) -> Array { Codon::AminoAcid(amino_acid) => { result.append(amino_acid); codon_index += 3; - } + }, } - } + }, } }; diff --git a/exercises/practice/protein-translation/Scarb.toml b/exercises/practice/protein-translation/Scarb.toml index 4e3b09df..f30c7b24 100644 --- a/exercises/practice/protein-translation/Scarb.toml +++ b/exercises/practice/protein-translation/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/protein-translation/tests/protein_translation.cairo b/exercises/practice/protein-translation/tests/protein_translation.cairo index 4b1b9e2e..4c6841dc 100644 --- a/exercises/practice/protein-translation/tests/protein_translation.cairo +++ b/exercises/practice/protein-translation/tests/protein_translation.cairo @@ -124,7 +124,7 @@ fn sequence_of_two_different_protein_codons_translates_into_proteins() { fn translate_rna_strand_into_correct_protein_list() { assert_eq!( proteins("AUGUUUUGG"), - array![AminoAcid::Methionine, AminoAcid::Phenylalanine, AminoAcid::Tryptophan] + array![AminoAcid::Methionine, AminoAcid::Phenylalanine, AminoAcid::Tryptophan], ); } @@ -157,7 +157,7 @@ fn translation_stops_if_stop_codon_in_middle_of_three_codon_sequence() { fn translation_stops_if_stop_codon_in_middle_of_six_codon_sequence() { assert_eq!( proteins("UGGUGUUAUUAAUGGUUU"), - array![AminoAcid::Tryptophan, AminoAcid::Cysteine, AminoAcid::Tyrosine] + array![AminoAcid::Tryptophan, AminoAcid::Cysteine, AminoAcid::Tyrosine], ); } @@ -185,6 +185,6 @@ fn incomplete_rna_sequence_cant_translate() { #[ignore] fn incomplete_rna_sequence_can_translate_if_valid_until_a_stop_codon() { assert_eq!( - proteins("UUCUUCUAAUGGU"), array![AminoAcid::Phenylalanine, AminoAcid::Phenylalanine] + proteins("UUCUUCUAAUGGU"), array![AminoAcid::Phenylalanine, AminoAcid::Phenylalanine], ); } diff --git a/exercises/practice/proverb/.meta/example.cairo b/exercises/practice/proverb/.meta/example.cairo index 5c7300fe..7df778c5 100644 --- a/exercises/practice/proverb/.meta/example.cairo +++ b/exercises/practice/proverb/.meta/example.cairo @@ -1,16 +1,12 @@ pub fn recite(items: @Array) -> ByteArray { let mut stanzas: ByteArray = ""; - for index in 0 - ..items - .len() { - if index == items.len() - 1 { - stanzas += format!("And all for the want of a {}.", items[0]); - } else { - stanzas += - format!( - "For want of a {} the {} was lost.\n", items[index], items[index + 1] - ); - } - }; + for index in 0..items.len() { + if index == items.len() - 1 { + stanzas += format!("And all for the want of a {}.", items[0]); + } else { + stanzas += + format!("For want of a {} the {} was lost.\n", items[index], items[index + 1]); + } + }; stanzas } diff --git a/exercises/practice/proverb/Scarb.toml b/exercises/practice/proverb/Scarb.toml index dca023d5..efd57ea1 100644 --- a/exercises/practice/proverb/Scarb.toml +++ b/exercises/practice/proverb/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/raindrops/.meta/example.cairo b/exercises/practice/raindrops/.meta/example.cairo index f9fe259b..a0a1eebe 100644 --- a/exercises/practice/raindrops/.meta/example.cairo +++ b/exercises/practice/raindrops/.meta/example.cairo @@ -17,5 +17,5 @@ pub fn convert(x: u64) -> ByteArray { result = format!("{x}"); } - return result; + result } diff --git a/exercises/practice/raindrops/Scarb.toml b/exercises/practice/raindrops/Scarb.toml index 81dbd52b..c3f2ae0d 100644 --- a/exercises/practice/raindrops/Scarb.toml +++ b/exercises/practice/raindrops/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/rational-numbers/.meta/example.cairo b/exercises/practice/rational-numbers/.meta/example.cairo index f98a0b96..c6e5a4c6 100644 --- a/exercises/practice/rational-numbers/.meta/example.cairo +++ b/exercises/practice/rational-numbers/.meta/example.cairo @@ -101,9 +101,10 @@ pub impl RationalPow of RationalPowTrait { // Cairo only supports integers, so a negative rational exponent // will always return the result 0 if power.numer < 0 { - return 0; - }; - nth_root(pow(*self, to_u128(power.numer)), power.denom) + 0 + } else { + nth_root(pow(*self, to_u128(power.numer)), power.denom) + } } } diff --git a/exercises/practice/rational-numbers/Scarb.toml b/exercises/practice/rational-numbers/Scarb.toml index 7bc94cdb..267b67cb 100644 --- a/exercises/practice/rational-numbers/Scarb.toml +++ b/exercises/practice/rational-numbers/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/resistor-color-duo/Scarb.toml b/exercises/practice/resistor-color-duo/Scarb.toml index d525d170..1da067be 100644 --- a/exercises/practice/resistor-color-duo/Scarb.toml +++ b/exercises/practice/resistor-color-duo/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/resistor-color/.meta/example.cairo b/exercises/practice/resistor-color/.meta/example.cairo index 8b9a0a41..afad1950 100644 --- a/exercises/practice/resistor-color/.meta/example.cairo +++ b/exercises/practice/resistor-color/.meta/example.cairo @@ -38,6 +38,6 @@ pub fn colors() -> Array { Color::Blue, Color::Violet, Color::Grey, - Color::White + Color::White, ] } diff --git a/exercises/practice/resistor-color/tests/resistor_color.cairo b/exercises/practice/resistor-color/tests/resistor_color.cairo index 49bde126..6910c9a7 100644 --- a/exercises/practice/resistor-color/tests/resistor_color.cairo +++ b/exercises/practice/resistor-color/tests/resistor_color.cairo @@ -38,7 +38,7 @@ fn test_colors() { Color::Blue, Color::Violet, Color::Grey, - Color::White + Color::White, ]; assert_eq!(output, expected); } diff --git a/exercises/practice/reverse-string/.meta/example.cairo b/exercises/practice/reverse-string/.meta/example.cairo index 2aaa5317..ee9dcf0c 100644 --- a/exercises/practice/reverse-string/.meta/example.cairo +++ b/exercises/practice/reverse-string/.meta/example.cairo @@ -1,3 +1,3 @@ pub fn reverse(string: ByteArray) -> ByteArray { - return string.rev(); + string.rev() } diff --git a/exercises/practice/reverse-string/Scarb.toml b/exercises/practice/reverse-string/Scarb.toml index 232ad07f..95d652ee 100644 --- a/exercises/practice/reverse-string/Scarb.toml +++ b/exercises/practice/reverse-string/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/rna-transcription/.meta/example.cairo b/exercises/practice/rna-transcription/.meta/example.cairo index 8b1b5e2a..400715bb 100644 --- a/exercises/practice/rna-transcription/.meta/example.cairo +++ b/exercises/practice/rna-transcription/.meta/example.cairo @@ -16,5 +16,5 @@ pub fn to_rna(dna: ByteArray) -> ByteArray { i += 1; }; - return rna; + rna } diff --git a/exercises/practice/rna-transcription/Scarb.toml b/exercises/practice/rna-transcription/Scarb.toml index 6cd17ffe..a3116ad1 100644 --- a/exercises/practice/rna-transcription/Scarb.toml +++ b/exercises/practice/rna-transcription/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/robot-simulator/.meta/example.cairo b/exercises/practice/robot-simulator/.meta/example.cairo index 7b42f35b..3cc3270e 100644 --- a/exercises/practice/robot-simulator/.meta/example.cairo +++ b/exercises/practice/robot-simulator/.meta/example.cairo @@ -62,7 +62,7 @@ pub impl RobotImpl of RobotTrait { } fn build(position: Position, direction: Direction) -> Robot { - Robot { position, direction, } + Robot { position, direction } } #[must_use] diff --git a/exercises/practice/robot-simulator/Scarb.toml b/exercises/practice/robot-simulator/Scarb.toml index e779e4a7..09bf4686 100644 --- a/exercises/practice/robot-simulator/Scarb.toml +++ b/exercises/practice/robot-simulator/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/roman-numerals/Scarb.toml b/exercises/practice/roman-numerals/Scarb.toml index 7c85483c..e1d506f5 100644 --- a/exercises/practice/roman-numerals/Scarb.toml +++ b/exercises/practice/roman-numerals/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/rotational-cipher/.meta/example.cairo b/exercises/practice/rotational-cipher/.meta/example.cairo index a290e8ff..95ae634e 100644 --- a/exercises/practice/rotational-cipher/.meta/example.cairo +++ b/exercises/practice/rotational-cipher/.meta/example.cairo @@ -19,5 +19,5 @@ pub fn rotate(text: ByteArray, shift_key: u8) -> ByteArray { i += 1; }; - return result; + result } diff --git a/exercises/practice/rotational-cipher/Scarb.toml b/exercises/practice/rotational-cipher/Scarb.toml index 0c507359..00dc3cd5 100644 --- a/exercises/practice/rotational-cipher/Scarb.toml +++ b/exercises/practice/rotational-cipher/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/scrabble-score/Scarb.toml b/exercises/practice/scrabble-score/Scarb.toml index 48b17ebb..36c1000d 100644 --- a/exercises/practice/scrabble-score/Scarb.toml +++ b/exercises/practice/scrabble-score/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/secret-handshake/.meta/example.cairo b/exercises/practice/secret-handshake/.meta/example.cairo index 4a957a4d..fdfc2e9e 100644 --- a/exercises/practice/secret-handshake/.meta/example.cairo +++ b/exercises/practice/secret-handshake/.meta/example.cairo @@ -1,9 +1,11 @@ +use core::num::traits::Pow; + pub fn commands(number: u8) -> Array { let mut results: Array = array![]; let mut i: u32 = 0; for action in actions() { - if number.into() & (1 * pow(2, i)) != 0 { + if number.into() & 2_u32.pow(i) != 0 { results.append(action); } i += 1; @@ -20,22 +22,9 @@ pub fn commands(number: u8) -> Array { results = reversed; } - return results; + results } fn actions() -> Array { - return array!["wink", "double blink", "close your eyes", "jump"]; -} - -fn pow(base: u32, mut power: u32) -> u32 { - if base == 0 { - return base; - } - let base: u256 = base.into(); - let mut result = 1_u256; - while power != 0 { - result *= base; - power -= 1; - }; - result.try_into().expect('too large to fit output type') + array!["wink", "double blink", "close your eyes", "jump"] } diff --git a/exercises/practice/secret-handshake/Scarb.toml b/exercises/practice/secret-handshake/Scarb.toml index ed6a8609..0d7dae68 100644 --- a/exercises/practice/secret-handshake/Scarb.toml +++ b/exercises/practice/secret-handshake/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/semi-structured-logs/Scarb.toml b/exercises/practice/semi-structured-logs/Scarb.toml index 5b292323..69f8ab7b 100644 --- a/exercises/practice/semi-structured-logs/Scarb.toml +++ b/exercises/practice/semi-structured-logs/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/semi-structured-logs/src/lib.cairo b/exercises/practice/semi-structured-logs/src/lib.cairo index a07133d4..e6a98e3a 100644 --- a/exercises/practice/semi-structured-logs/src/lib.cairo +++ b/exercises/practice/semi-structured-logs/src/lib.cairo @@ -4,7 +4,7 @@ pub enum LogLevel { Info, Warning, Error, - Debug + Debug, } /// primary function for emitting logs diff --git a/exercises/practice/semi-structured-logs/tests/semi_structured_logs.cairo b/exercises/practice/semi-structured-logs/tests/semi_structured_logs.cairo index 003a3b50..f888db82 100644 --- a/exercises/practice/semi-structured-logs/tests/semi_structured_logs.cairo +++ b/exercises/practice/semi-structured-logs/tests/semi_structured_logs.cairo @@ -38,5 +38,5 @@ fn log_emits_error() { #[test] #[ignore] fn add_a_variant() { - assert_eq!(log(LogLevel::Debug, "reached line 123"), "[DEBUG]: reached line 123",); + assert_eq!(log(LogLevel::Debug, "reached line 123"), "[DEBUG]: reached line 123"); } diff --git a/exercises/practice/series/.meta/example.cairo b/exercises/practice/series/.meta/example.cairo index 602d8d29..413992ed 100644 --- a/exercises/practice/series/.meta/example.cairo +++ b/exercises/practice/series/.meta/example.cairo @@ -6,14 +6,13 @@ pub fn slices(series: ByteArray, slice_length: usize) -> Array { let max_start = series.len() - slice_length + 1; let mut all_slices = array![]; - for i in 0 - ..max_start { - let mut slice = ""; - for j in i..(i + slice_length) { - slice.append_byte(series[j]); - }; - all_slices.append(slice); + for i in 0..max_start { + let mut slice = ""; + for j in i..(i + slice_length) { + slice.append_byte(series[j]); }; + all_slices.append(slice); + }; all_slices } diff --git a/exercises/practice/series/Scarb.toml b/exercises/practice/series/Scarb.toml index 024a38a1..0a6a3abe 100644 --- a/exercises/practice/series/Scarb.toml +++ b/exercises/practice/series/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/series/tests/series.cairo b/exercises/practice/series/tests/series.cairo index 23273596..58c3b654 100644 --- a/exercises/practice/series/tests/series.cairo +++ b/exercises/practice/series/tests/series.cairo @@ -55,7 +55,7 @@ fn slices_of_a_long_series() { let input = "918493904243"; let length = 5; let output = slices(input, length); - let expected = array!["91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243",]; + let expected = array!["91849", "18493", "84939", "49390", "93904", "39042", "90424", "04243"]; assert_eq!(output, expected); } diff --git a/exercises/practice/simple-linked-list/.meta/example.cairo b/exercises/practice/simple-linked-list/.meta/example.cairo index 6f86c635..919fc1fd 100644 --- a/exercises/practice/simple-linked-list/.meta/example.cairo +++ b/exercises/practice/simple-linked-list/.meta/example.cairo @@ -40,14 +40,14 @@ pub impl SimpleLinkedListImpl, +Copy> of SimpleLinkedListTrait let node = node.unbox(); self.head = node.next; Option::Some(node.data) - } + }, } } fn peek(self: @SimpleLinkedList) -> Option<@T> { match *self.head { Option::None => Option::None, - Option::Some(node) => Option::Some(@node.unbox().data) + Option::Some(node) => Option::Some(@node.unbox().data), } } @@ -89,6 +89,6 @@ impl SimpleLinkedListIntoArray, +Copy> of Into of NodeTrait { fn new(element: T, next: List) -> Node { - Node { data: element, next, } + Node { data: element, next } } } diff --git a/exercises/practice/simple-linked-list/Scarb.toml b/exercises/practice/simple-linked-list/Scarb.toml index 4977e6ad..706fb0f8 100644 --- a/exercises/practice/simple-linked-list/Scarb.toml +++ b/exercises/practice/simple-linked-list/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/space-age/.meta/example.cairo b/exercises/practice/space-age/.meta/example.cairo index a66b9415..628f48b9 100644 --- a/exercises/practice/space-age/.meta/example.cairo +++ b/exercises/practice/space-age/.meta/example.cairo @@ -20,7 +20,7 @@ const MICROSECONDS_IN_A_SECOND: u64 = 1_000_000; pub trait Planet { const PERIOD: u256; fn age( - self: @T, seconds: u256 + self: @T, seconds: u256, ) -> u256 { let microseconds = seconds * MICROSECONDS_IN_A_SECOND.into(); // multiplying with 100 before the division makes the result diff --git a/exercises/practice/space-age/Scarb.toml b/exercises/practice/space-age/Scarb.toml index 6187f611..14c6a47d 100644 --- a/exercises/practice/space-age/Scarb.toml +++ b/exercises/practice/space-age/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/space-age/tests/space_age.cairo b/exercises/practice/space-age/tests/space_age.cairo index 596e94be..0b2fb186 100644 --- a/exercises/practice/space-age/tests/space_age.cairo +++ b/exercises/practice/space-age/tests/space_age.cairo @@ -10,7 +10,7 @@ fn assert_in_delta(expected: u256, actual: u256) { let delta: u256 = 10000; // 0.01 seconds if diff > delta { panic!( - "Your result of {actual} should be within {delta} of the expected result {expected}" + "Your result of {actual} should be within {delta} of the expected result {expected}", ); }; } diff --git a/exercises/practice/square-root/.meta/example.cairo b/exercises/practice/square-root/.meta/example.cairo index 2c0ab225..3c4e372a 100644 --- a/exercises/practice/square-root/.meta/example.cairo +++ b/exercises/practice/square-root/.meta/example.cairo @@ -5,6 +5,5 @@ pub fn sqrt(radicand: u64) -> u64 { candidate += 1; }; } - - return candidate; + candidate } diff --git a/exercises/practice/square-root/Scarb.toml b/exercises/practice/square-root/Scarb.toml index 84d7db17..78beadc3 100644 --- a/exercises/practice/square-root/Scarb.toml +++ b/exercises/practice/square-root/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/sublist/Scarb.toml b/exercises/practice/sublist/Scarb.toml index c3648c38..c108bc2f 100644 --- a/exercises/practice/sublist/Scarb.toml +++ b/exercises/practice/sublist/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/sum-of-multiples/Scarb.toml b/exercises/practice/sum-of-multiples/Scarb.toml index 9c7265c8..e78b03e5 100644 --- a/exercises/practice/sum-of-multiples/Scarb.toml +++ b/exercises/practice/sum-of-multiples/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/triangle/Scarb.toml b/exercises/practice/triangle/Scarb.toml index 4f0b4d0d..400785a7 100644 --- a/exercises/practice/triangle/Scarb.toml +++ b/exercises/practice/triangle/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/two-fer/.meta/example.cairo b/exercises/practice/two-fer/.meta/example.cairo index 1a94f5db..449d880f 100644 --- a/exercises/practice/two-fer/.meta/example.cairo +++ b/exercises/practice/two-fer/.meta/example.cairo @@ -1,6 +1,6 @@ pub fn response(name: Option) -> ByteArray { match name { Option::Some(n) => format!("One for {n}, one for me."), - Option::None => "One for you, one for me." + Option::None => "One for you, one for me.", } } diff --git a/exercises/practice/two-fer/Scarb.toml b/exercises/practice/two-fer/Scarb.toml index 8ca39840..c30020c5 100644 --- a/exercises/practice/two-fer/Scarb.toml +++ b/exercises/practice/two-fer/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/variable-length-quantity/Scarb.toml b/exercises/practice/variable-length-quantity/Scarb.toml index f835a8e7..72c972d4 100644 --- a/exercises/practice/variable-length-quantity/Scarb.toml +++ b/exercises/practice/variable-length-quantity/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/word-count/Scarb.toml b/exercises/practice/word-count/Scarb.toml index fa54cf30..8645a336 100644 --- a/exercises/practice/word-count/Scarb.toml +++ b/exercises/practice/word-count/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/word-count/tests/word_count.cairo b/exercises/practice/word-count/tests/word_count.cairo index 920a19bd..ada6a514 100644 --- a/exercises/practice/word-count/tests/word_count.cairo +++ b/exercises/practice/word-count/tests/word_count.cairo @@ -18,7 +18,7 @@ fn count_one_of_each_word() { let expected = array![ WordResult { word: "of", count: 1 }, WordResult { word: "each", count: 1 }, - WordResult { word: "one", count: 1 } + WordResult { word: "one", count: 1 }, ] .span(); assert_unordered_eq(output, expected); @@ -35,7 +35,7 @@ fn multiple_occurrences_of_a_word() { WordResult { word: "two", count: 1 }, WordResult { word: "red", count: 1 }, WordResult { word: "blue", count: 1 }, - WordResult { word: "fish", count: 4 } + WordResult { word: "fish", count: 4 }, ] .span(); assert_unordered_eq(output, expected); @@ -50,7 +50,7 @@ fn handles_cramped_lists() { let expected = array![ WordResult { word: "one", count: 1 }, WordResult { word: "two", count: 1 }, - WordResult { word: "three", count: 1 } + WordResult { word: "three", count: 1 }, ] .span(); assert_unordered_eq(output, expected); @@ -65,7 +65,7 @@ fn handles_expanded_lists() { let expected = array![ WordResult { word: "one", count: 1 }, WordResult { word: "two", count: 1 }, - WordResult { word: "three", count: 1 } + WordResult { word: "three", count: 1 }, ] .span(); assert_unordered_eq(output, expected); @@ -82,7 +82,7 @@ fn ignore_punctuation() { WordResult { word: "carpet", count: 1 }, WordResult { word: "as", count: 1 }, WordResult { word: "java", count: 1 }, - WordResult { word: "javascript", count: 1 } + WordResult { word: "javascript", count: 1 }, ] .span(); assert_unordered_eq(output, expected); @@ -111,7 +111,7 @@ fn normalize_case() { let mut output = count_words(input); let expected = array![ - WordResult { word: "go", count: 3 }, WordResult { word: "stop", count: 2 } + WordResult { word: "go", count: 3 }, WordResult { word: "stop", count: 2 }, ] .span(); assert_unordered_eq(output, expected); @@ -149,7 +149,7 @@ fn with_quotations() { WordResult { word: "tell", count: 1 }, WordResult { word: "between", count: 1 }, WordResult { word: "and", count: 1 }, - WordResult { word: "large", count: 2 } + WordResult { word: "large", count: 2 }, ] .span(); assert_unordered_eq(output, expected); @@ -169,7 +169,7 @@ fn substrings_from_the_beginning() { WordResult { word: "app", count: 1 }, WordResult { word: "apple", count: 1 }, WordResult { word: "and", count: 1 }, - WordResult { word: "a", count: 1 } + WordResult { word: "a", count: 1 }, ] .span(); assert_unordered_eq(output, expected); @@ -182,7 +182,7 @@ fn multiple_spaces_not_detected_as_a_word() { let mut output = count_words(input); let expected = array![ - WordResult { word: "multiple", count: 1 }, WordResult { word: "whitespaces", count: 1 } + WordResult { word: "multiple", count: 1 }, WordResult { word: "whitespaces", count: 1 }, ] .span(); assert_unordered_eq(output, expected); @@ -197,7 +197,7 @@ fn alternating_word_separators_not_detected_as_a_word() { let expected = array![ WordResult { word: "one", count: 1 }, WordResult { word: "two", count: 1 }, - WordResult { word: "three", count: 1 } + WordResult { word: "three", count: 1 }, ] .span(); assert_unordered_eq(output, expected); @@ -210,7 +210,7 @@ fn quotation_for_word_with_apostrophe() { let mut output = count_words(input); let expected = array![ - WordResult { word: "can", count: 1 }, WordResult { word: "can't", count: 2 } + WordResult { word: "can", count: 1 }, WordResult { word: "can't", count: 2 }, ] .span(); assert_unordered_eq(output, expected); @@ -232,7 +232,7 @@ fn assert_unordered_eq(span1: Span, span2: Span) { found, "assertion failed: `(left == right)`\n left: `{:?}`,\n right `{:?}`", span1, - span2 + span2, ); }; // and `span2` should be subset of `span1` @@ -248,7 +248,7 @@ fn assert_unordered_eq(span1: Span, span2: Span) { found, "assertion failed: `(left == right)`\n left: `{:?}`,\n right `{:?}`", span1, - span2 + span2, ); } } diff --git a/exercises/practice/word-search/.meta/example.cairo b/exercises/practice/word-search/.meta/example.cairo index 7f408bd2..5528f12d 100644 --- a/exercises/practice/word-search/.meta/example.cairo +++ b/exercises/practice/word-search/.meta/example.cairo @@ -20,119 +20,111 @@ pub fn search(grid: Span, words_to_search_for: Span) -> Sp for word in words_to_search_for { let word_len = word.len(); - for row in 0 - ..num_rows { - for col in 0 - ..num_cols { - // Horizontal (left-to-right) - if col + word_len <= num_cols && is_horizontal_match(grid, word, row, col) { - results - .append( - SearchResult { - word: word.clone(), - start: Position { col: col + 1, row: row + 1 }, - end: Position { col: col + word_len, row: row + 1 } - } - ); - } - - // Horizontal (right-to-left) - if col >= word_len - - 1 && is_horizontal_reverse_match(grid, word, row, col) { - results - .append( - SearchResult { - word: word.clone(), - start: Position { col: col + 1, row: row + 1 }, - end: Position { col: word_len - col, row: row + 1 } - } - ); - } - - // Vertical (top-to-bottom) - if row + word_len <= num_rows && is_vertical_match(grid, word, row, col) { - results - .append( - SearchResult { - word: word.clone(), - start: Position { col: col + 1, row: row + 1 }, - end: Position { col: col + 1, row: row + row + word_len } - } - ); - } - - // Vertical (bottom-to-top) - if row >= word_len - 1 && is_vertical_reverse_match(grid, word, row, col) { - results - .append( - SearchResult { - word: word.clone(), - start: Position { col: col + 1, row: row + 1 }, - end: Position { col: col + 1, row: row + 1 - word_len + 1 } - } - ); - } - - // Diagonal (top-left to bottom-right) - if row - + word_len <= num_rows && col - + word_len <= num_cols - && is_diagonal_tl_br_match(grid, word, row, col) { - results - .append( - SearchResult { - word: word.clone(), - start: Position { col: col + 1, row: row + 1 }, - end: Position { col: col + word_len, row: row + word_len } - } - ); - } - - // Diagonal (top-right to bottom-left) - if row - + word_len <= num_rows && col >= word_len - - 1 && is_diagonal_tr_bl_match(grid, word, row, col) { - results - .append( - SearchResult { - word: word.clone(), - start: Position { col: col + 1, row: row + 1 }, - end: Position { - col: col + 1 - word_len + 1, row: row + word_len - } - } - ); - } - // Diagonal Up-Right (Bottom-Left to Top-Right) - if row >= word_len && is_diagonal_bl_tr_match(grid, word, row, col) { - results - .append( - SearchResult { - word: word.clone(), - start: Position { col: col + 1, row: row + 1 }, - end: Position { - col: col + word_len, row: row + 1 - word_len + 1 - } - } - ); - } - // Diagonal Up-Left (Bottom-Right to Top-Left) - if row >= word_len - && col >= word_len - && is_diagonal_br_tl_match(grid, word, row, col) { - results - .append( - SearchResult { - word: word.clone(), - start: Position { col: col + 1, row: row + 1 }, - end: Position { - col: col + 1 - word_len + 1, row: row + 1 - word_len + 1 - } - } - ); - } - } + for row in 0..num_rows { + for col in 0..num_cols { + // Horizontal (left-to-right) + if col + word_len <= num_cols && is_horizontal_match(grid, word, row, col) { + results + .append( + SearchResult { + word: word.clone(), + start: Position { col: col + 1, row: row + 1 }, + end: Position { col: col + word_len, row: row + 1 }, + }, + ); + } + + // Horizontal (right-to-left) + if col >= word_len - 1 && is_horizontal_reverse_match(grid, word, row, col) { + results + .append( + SearchResult { + word: word.clone(), + start: Position { col: col + 1, row: row + 1 }, + end: Position { col: word_len - col, row: row + 1 }, + }, + ); + } + + // Vertical (top-to-bottom) + if row + word_len <= num_rows && is_vertical_match(grid, word, row, col) { + results + .append( + SearchResult { + word: word.clone(), + start: Position { col: col + 1, row: row + 1 }, + end: Position { col: col + 1, row: row + row + word_len }, + }, + ); + } + + // Vertical (bottom-to-top) + if row >= word_len - 1 && is_vertical_reverse_match(grid, word, row, col) { + results + .append( + SearchResult { + word: word.clone(), + start: Position { col: col + 1, row: row + 1 }, + end: Position { col: col + 1, row: row + 1 - word_len + 1 }, + }, + ); + } + + // Diagonal (top-left to bottom-right) + if row + + word_len <= num_rows && col + + word_len <= num_cols && is_diagonal_tl_br_match(grid, word, row, col) { + results + .append( + SearchResult { + word: word.clone(), + start: Position { col: col + 1, row: row + 1 }, + end: Position { col: col + word_len, row: row + word_len }, + }, + ); + } + + // Diagonal (top-right to bottom-left) + if row + + word_len <= num_rows && col >= word_len + - 1 && is_diagonal_tr_bl_match(grid, word, row, col) { + results + .append( + SearchResult { + word: word.clone(), + start: Position { col: col + 1, row: row + 1 }, + end: Position { col: col + 1 - word_len + 1, row: row + word_len }, + }, + ); + } + // Diagonal Up-Right (Bottom-Left to Top-Right) + if row >= word_len && is_diagonal_bl_tr_match(grid, word, row, col) { + results + .append( + SearchResult { + word: word.clone(), + start: Position { col: col + 1, row: row + 1 }, + end: Position { col: col + word_len, row: row + 1 - word_len + 1 }, + }, + ); + } + // Diagonal Up-Left (Bottom-Right to Top-Left) + if row >= word_len + && col >= word_len + && is_diagonal_br_tl_match(grid, word, row, col) { + results + .append( + SearchResult { + word: word.clone(), + start: Position { col: col + 1, row: row + 1 }, + end: Position { + col: col + 1 - word_len + 1, row: row + 1 - word_len + 1, + }, + }, + ); + } } + } }; results.span() @@ -150,7 +142,7 @@ fn is_horizontal_match(grid: Span, word: @ByteArray, row: usize, col: return false; } for i in 0..word_len { - if grid[row.into()][col + i] != word[i] { + if grid[row][col + i] != word[i] { result = false; break; } @@ -160,7 +152,7 @@ fn is_horizontal_match(grid: Span, word: @ByteArray, row: usize, col: // Horizontal match (right-to-left) fn is_horizontal_reverse_match( - grid: Span, word: @ByteArray, row: usize, col: usize + grid: Span, word: @ByteArray, row: usize, col: usize, ) -> bool { let mut result = true; let word_len = word.len(); @@ -170,7 +162,7 @@ fn is_horizontal_reverse_match( } for i in 0..word_len { - if grid[row.into()][col - i] != word[i] { + if grid[row][col - i] != word[i] { result = false; break; } @@ -187,7 +179,7 @@ fn is_vertical_match(grid: Span, word: @ByteArray, row: usize, col: u return false; } for i in 0..word_len { - if grid[row.into() + i][col] != word[i] { + if grid[row + i][col] != word[i] { result = false; break; } @@ -197,7 +189,7 @@ fn is_vertical_match(grid: Span, word: @ByteArray, row: usize, col: u // Vertical match (bottom-to-top) fn is_vertical_reverse_match( - grid: Span, word: @ByteArray, row: usize, col: usize + grid: Span, word: @ByteArray, row: usize, col: usize, ) -> bool { let mut result = true; let word_len = word.len(); @@ -206,7 +198,7 @@ fn is_vertical_reverse_match( return false; } for i in 0..word_len { - if grid[row.into() - i][col] != word[i] { + if grid[row - i][col] != word[i] { result = false; break; } @@ -216,7 +208,7 @@ fn is_vertical_reverse_match( // Diagonal match (top-left to bottom-right) fn is_diagonal_tl_br_match( - grid: Span, word: @ByteArray, row: usize, col: usize + grid: Span, word: @ByteArray, row: usize, col: usize, ) -> bool { let mut result = true; let word_len = word.len(); @@ -225,7 +217,7 @@ fn is_diagonal_tl_br_match( return false; } for i in 0..word_len { - if grid[row.into() + i][col + i] != word[i] { + if grid[row + i][col + i] != word[i] { result = false; break; } @@ -236,7 +228,7 @@ fn is_diagonal_tl_br_match( // Diagonal match (top-right to bottom-left) fn is_diagonal_tr_bl_match( - grid: Span, word: @ByteArray, row: usize, col: usize + grid: Span, word: @ByteArray, row: usize, col: usize, ) -> bool { let mut result = true; let word_len = word.len(); @@ -246,7 +238,7 @@ fn is_diagonal_tr_bl_match( return false; } for i in 0..word_len { - if grid[row.into() + i][col - i] != word[i] { + if grid[row + i][col - i] != word[i] { result = false; break; } @@ -256,7 +248,7 @@ fn is_diagonal_tr_bl_match( } fn is_diagonal_bl_tr_match( - grid: Span, word: @ByteArray, row: usize, col: usize + grid: Span, word: @ByteArray, row: usize, col: usize, ) -> bool { let mut result = true; @@ -268,7 +260,7 @@ fn is_diagonal_bl_tr_match( } for i in 0..word_len { - if grid[row.into() - i][col + i] != word[i] { + if grid[row - i][col + i] != word[i] { result = false; break; } @@ -277,7 +269,7 @@ fn is_diagonal_bl_tr_match( } fn is_diagonal_br_tl_match( - grid: Span, word: @ByteArray, row: usize, col: usize + grid: Span, word: @ByteArray, row: usize, col: usize, ) -> bool { let mut result = true; let word_len = word.len(); @@ -288,7 +280,7 @@ fn is_diagonal_br_tl_match( } for i in 0..word_len { - if grid[row.into() - i][col - i] != word[i] { + if grid[row - i][col - i] != word[i] { result = false; break; } diff --git a/exercises/practice/word-search/Scarb.toml b/exercises/practice/word-search/Scarb.toml index 6fc3d315..5aa51779 100644 --- a/exercises/practice/word-search/Scarb.toml +++ b/exercises/practice/word-search/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/word-search/src/lib.cairo b/exercises/practice/word-search/src/lib.cairo index 11ea4b4a..f0854bd8 100644 --- a/exercises/practice/word-search/src/lib.cairo +++ b/exercises/practice/word-search/src/lib.cairo @@ -1,5 +1,5 @@ #[derive(Drop, Debug, PartialEq)] -struct Position { +pub struct Position { pub col: usize, pub row: usize, } diff --git a/exercises/practice/word-search/tests/word_search.cairo b/exercises/practice/word-search/tests/word_search.cairo index 1a639d04..be2e460f 100644 --- a/exercises/practice/word-search/tests/word_search.cairo +++ b/exercises/practice/word-search/tests/word_search.cairo @@ -27,8 +27,8 @@ fn should_locate_one_word_written_left_to_right() { let results = search(grid, words_to_search_for); let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 1 }, end: Position { col: 7, row: 1 } - } + word: "clojure", start: Position { col: 1, row: 1 }, end: Position { col: 7, row: 1 }, + }, ] .span(); @@ -49,8 +49,8 @@ fn should_locate_the_same_word_written_left_to_right_in_a_different_position() { let expected = array![ SearchResult { - word: "clojure", start: Position { col: 3, row: 1 }, end: Position { col: 9, row: 1 } - } + word: "clojure", start: Position { col: 3, row: 1 }, end: Position { col: 9, row: 1 }, + }, ] .span(); @@ -71,8 +71,8 @@ fn should_locate_a_different_left_to_right_word() { let expected = array![ SearchResult { - word: "coffee", start: Position { col: 1, row: 1 }, end: Position { col: 6, row: 1 } - } + word: "coffee", start: Position { col: 1, row: 1 }, end: Position { col: 6, row: 1 }, + }, ] .span(); @@ -93,8 +93,8 @@ fn should_locate_that_different_left_to_right_word_in_a_different_position() { let expected = array![ SearchResult { - word: "coffee", start: Position { col: 2, row: 1 }, end: Position { col: 7, row: 1 } - } + word: "coffee", start: Position { col: 2, row: 1 }, end: Position { col: 7, row: 1 }, + }, ] .span(); @@ -116,8 +116,8 @@ fn should_locate_a_left_to_right_word_in_a_two_line_grid() { let expected = array![ SearchResult { - word: "clojure", start: Position { col: 2, row: 2 }, end: Position { col: 8, row: 2 } - } + word: "clojure", start: Position { col: 2, row: 2 }, end: Position { col: 8, row: 2 }, + }, ] .span(); @@ -140,8 +140,8 @@ fn should_locate_a_left_to_right_word_in_a_three_line_grid() { let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 3 }, end: Position { col: 7, row: 3 } - } + word: "clojure", start: Position { col: 1, row: 3 }, end: Position { col: 7, row: 3 }, + }, ] .span(); @@ -171,8 +171,8 @@ fn should_locate_a_left_to_right_word_in_a_ten_line_grid() { let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 } - } + word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 }, + }, ] .span(); @@ -203,8 +203,8 @@ fn should_locate_that_left_to_right_word_in_a_different_position_in_a_ten_line_g let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 9 }, end: Position { col: 7, row: 9 } - } + word: "clojure", start: Position { col: 1, row: 9 }, end: Position { col: 7, row: 9 }, + }, ] .span(); @@ -235,8 +235,8 @@ fn should_locate_a_different_left_to_right_word_in_a_ten_line_grid() { let expected = array![ SearchResult { - word: "fortran", start: Position { col: 1, row: 7 }, end: Position { col: 7, row: 7 } - } + word: "fortran", start: Position { col: 1, row: 7 }, end: Position { col: 7, row: 7 }, + }, ] .span(); @@ -266,11 +266,11 @@ fn should_locate_multiple_words() { let expected = array![ SearchResult { - word: "fortran", start: Position { col: 1, row: 7 }, end: Position { col: 7, row: 7 } + word: "fortran", start: Position { col: 1, row: 7 }, end: Position { col: 7, row: 7 }, }, SearchResult { - word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 } - } + word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 }, + }, ] .span(); @@ -291,8 +291,8 @@ fn should_locate_a_single_word_written_right_to_left() { let expected = array![ SearchResult { - word: "elixir", start: Position { col: 6, row: 1 }, end: Position { col: 1, row: 1 } - } + word: "elixir", start: Position { col: 6, row: 1 }, end: Position { col: 1, row: 1 }, + }, ] .span(); @@ -322,11 +322,11 @@ fn should_locate_multiple_words_written_in_different_horizontal_directions() { let expected = array![ SearchResult { - word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 } + word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 }, }, SearchResult { - word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 } - } + word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 }, + }, ] .span(); @@ -356,16 +356,16 @@ fn should_locate_words_written_top_to_bottom() { let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 } + word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 }, }, SearchResult { - word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 } + word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 }, }, SearchResult { word: "ecmascript", start: Position { col: 10, row: 1 }, - end: Position { col: 10, row: 10 } - } + end: Position { col: 10, row: 10 }, + }, ] .span(); @@ -396,19 +396,19 @@ fn should_locate_words_written_bottom_to_top() { let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 } + word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 }, }, SearchResult { - word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 } + word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 }, }, SearchResult { word: "ecmascript", start: Position { col: 10, row: 1 }, - end: Position { col: 10, row: 10 } + end: Position { col: 10, row: 10 }, }, SearchResult { - word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 } - } + word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 }, + }, ] .span(); @@ -438,22 +438,22 @@ fn should_locate_words_written_top_left_to_bottom_right() { let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 } + word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 }, }, SearchResult { - word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 } + word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 }, }, SearchResult { word: "ecmascript", start: Position { col: 10, row: 1 }, - end: Position { col: 10, row: 10 } + end: Position { col: 10, row: 10 }, }, SearchResult { - word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 } + word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 }, }, SearchResult { - word: "java", start: Position { col: 1, row: 1 }, end: Position { col: 4, row: 4 } - } + word: "java", start: Position { col: 1, row: 1 }, end: Position { col: 4, row: 4 }, + }, ] .span(); @@ -477,32 +477,32 @@ fn should_locate_words_written_bottom_right_to_top_left() { "clojurermt" ].span(); - let words_to_search_for = array!["clojure", "elixir", "ecmascript", "rust", "java", "lua",] + let words_to_search_for = array!["clojure", "elixir", "ecmascript", "rust", "java", "lua"] .span(); let results = search(grid, words_to_search_for); let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 } + word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 }, }, SearchResult { - word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 } + word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 }, }, SearchResult { word: "ecmascript", start: Position { col: 10, row: 1 }, - end: Position { col: 10, row: 10 } + end: Position { col: 10, row: 10 }, }, SearchResult { - word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 } + word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 }, }, SearchResult { - word: "java", start: Position { col: 1, row: 1 }, end: Position { col: 4, row: 4 } + word: "java", start: Position { col: 1, row: 1 }, end: Position { col: 4, row: 4 }, }, SearchResult { - word: "lua", start: Position { col: 8, row: 9 }, end: Position { col: 6, row: 7 } - } + word: "lua", start: Position { col: 8, row: 9 }, end: Position { col: 6, row: 7 }, + }, ] .span(); @@ -528,35 +528,35 @@ fn should_locate_words_written_bottom_left_to_top_right() { ].span(); let words_to_search_for = array![ - "clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp" + "clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", ] .span(); let results = search(grid, words_to_search_for); let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 } + word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 }, }, SearchResult { - word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 } + word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 }, }, SearchResult { word: "ecmascript", start: Position { col: 10, row: 1 }, - end: Position { col: 10, row: 10 } + end: Position { col: 10, row: 10 }, }, SearchResult { - word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 } + word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 }, }, SearchResult { - word: "java", start: Position { col: 1, row: 1 }, end: Position { col: 4, row: 4 } + word: "java", start: Position { col: 1, row: 1 }, end: Position { col: 4, row: 4 }, }, SearchResult { - word: "lua", start: Position { col: 8, row: 9 }, end: Position { col: 6, row: 7 } + word: "lua", start: Position { col: 8, row: 9 }, end: Position { col: 6, row: 7 }, }, SearchResult { - word: "lisp", start: Position { col: 3, row: 6 }, end: Position { col: 6, row: 3 } - } + word: "lisp", start: Position { col: 3, row: 6 }, end: Position { col: 6, row: 3 }, + }, ] .span(); @@ -581,7 +581,7 @@ fn should_locate_words_written_top_right_to_bottom_left() { ].span(); let words_to_search_for = array![ - "clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", "ruby" + "clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", "ruby", ] .span(); @@ -589,31 +589,31 @@ fn should_locate_words_written_top_right_to_bottom_left() { let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 } + word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 }, }, SearchResult { - word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 } + word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 }, }, SearchResult { word: "ecmascript", start: Position { col: 10, row: 1 }, - end: Position { col: 10, row: 10 } + end: Position { col: 10, row: 10 }, }, SearchResult { - word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 } + word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 }, }, SearchResult { - word: "java", start: Position { col: 1, row: 1 }, end: Position { col: 4, row: 4 } + word: "java", start: Position { col: 1, row: 1 }, end: Position { col: 4, row: 4 }, }, SearchResult { - word: "lua", start: Position { col: 8, row: 9 }, end: Position { col: 6, row: 7 } + word: "lua", start: Position { col: 8, row: 9 }, end: Position { col: 6, row: 7 }, }, SearchResult { - word: "lisp", start: Position { col: 3, row: 6 }, end: Position { col: 6, row: 3 } + word: "lisp", start: Position { col: 3, row: 6 }, end: Position { col: 6, row: 3 }, }, SearchResult { - word: "ruby", start: Position { col: 8, row: 6 }, end: Position { col: 5, row: 9 } - } + word: "ruby", start: Position { col: 8, row: 6 }, end: Position { col: 5, row: 9 }, + }, ] .span(); @@ -637,7 +637,7 @@ fn should_fail_to_locate_a_word_that_is_not_in_the_puzzle() { ].span(); let words_to_search_for = array![ - "clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", "ruby", "haskell" + "clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", "ruby", "haskell", ] .span(); @@ -645,31 +645,31 @@ fn should_fail_to_locate_a_word_that_is_not_in_the_puzzle() { let expected = array![ SearchResult { - word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 } + word: "clojure", start: Position { col: 1, row: 10 }, end: Position { col: 7, row: 10 }, }, SearchResult { - word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 } + word: "elixir", start: Position { col: 6, row: 5 }, end: Position { col: 1, row: 5 }, }, SearchResult { word: "ecmascript", start: Position { col: 10, row: 1 }, - end: Position { col: 10, row: 10 } + end: Position { col: 10, row: 10 }, }, SearchResult { - word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 } + word: "rust", start: Position { col: 9, row: 5 }, end: Position { col: 9, row: 2 }, }, SearchResult { - word: "java", start: Position { col: 1, row: 1 }, end: Position { col: 4, row: 4 } + word: "java", start: Position { col: 1, row: 1 }, end: Position { col: 4, row: 4 }, }, SearchResult { - word: "lua", start: Position { col: 8, row: 9 }, end: Position { col: 6, row: 7 } + word: "lua", start: Position { col: 8, row: 9 }, end: Position { col: 6, row: 7 }, }, SearchResult { - word: "lisp", start: Position { col: 3, row: 6 }, end: Position { col: 6, row: 3 } + word: "lisp", start: Position { col: 3, row: 6 }, end: Position { col: 6, row: 3 }, }, SearchResult { - word: "ruby", start: Position { col: 8, row: 6 }, end: Position { col: 5, row: 9 } - } + word: "ruby", start: Position { col: 8, row: 6 }, end: Position { col: 5, row: 9 }, + }, ] .span(); diff --git a/exercises/practice/wordy/.meta/example.cairo b/exercises/practice/wordy/.meta/example.cairo index 7d2cd24e..2840dd98 100644 --- a/exercises/practice/wordy/.meta/example.cairo +++ b/exercises/practice/wordy/.meta/example.cairo @@ -14,7 +14,7 @@ pub fn answer(question: ByteArray) -> i32 { let mut result = match parse_int(words[2]) { Option::Some(s) => s, - Option::None => panic!("syntax error") + Option::None => panic!("syntax error"), }; let mut i = 3; @@ -96,9 +96,8 @@ fn parse_int(num: @ByteArray) -> Option { i += 1; } - while i < size { - let re = char_to_digit(num[i]); - match re { + for i in i..size { + match char_to_digit(num[i]) { Option::Some(v) => { if let Option::Some(num) = result { result = Option::Some(num * 10 + v.into()); @@ -107,9 +106,8 @@ fn parse_int(num: @ByteArray) -> Option { Option::None => { result = Option::None; break; - } + }, } - i += 1; }; if let Option::Some(val) = result { diff --git a/exercises/practice/wordy/Scarb.toml b/exercises/practice/wordy/Scarb.toml index 983459d0..a0c43120 100644 --- a/exercises/practice/wordy/Scarb.toml +++ b/exercises/practice/wordy/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/yacht/.meta/example.cairo b/exercises/practice/yacht/.meta/example.cairo index fa7be79c..468c16e3 100644 --- a/exercises/practice/yacht/.meta/example.cairo +++ b/exercises/practice/yacht/.meta/example.cairo @@ -11,7 +11,7 @@ pub enum Category { LittleStraight, BigStraight, Choice, - Yacht + Yacht, } #[derive(Copy, Default, Drop, PartialEq)] @@ -103,7 +103,7 @@ fn count_dice(dice: Span) -> Counter { 4 => counter.fours += 1, 5 => counter.fives += 1, 6 => counter.sixes += 1, - _ => {} + _ => {}, } }; diff --git a/exercises/practice/yacht/Scarb.toml b/exercises/practice/yacht/Scarb.toml index 6ffac1d4..a2d255b0 100644 --- a/exercises/practice/yacht/Scarb.toml +++ b/exercises/practice/yacht/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/yacht/src/lib.cairo b/exercises/practice/yacht/src/lib.cairo index 0edc0a2a..2acc01eb 100644 --- a/exercises/practice/yacht/src/lib.cairo +++ b/exercises/practice/yacht/src/lib.cairo @@ -11,7 +11,7 @@ pub enum Category { LittleStraight, BigStraight, Choice, - Yacht + Yacht, } pub fn score(dice: [u8; 5], category: Category) -> u8 { diff --git a/exercises/practice/zipper/.meta/example.cairo b/exercises/practice/zipper/.meta/example.cairo index a9c539ce..d49c6c2e 100644 --- a/exercises/practice/zipper/.meta/example.cairo +++ b/exercises/practice/zipper/.meta/example.cairo @@ -12,7 +12,7 @@ pub impl OptionalBinaryTreeNodePartialEq of PartialEq match (lhs, rhs) { (Option::Some(lhs), Option::Some(rhs)) => (*lhs).unbox() == (*rhs).unbox(), (Option::None, Option::None) => true, - _ => false + _ => false, } } } @@ -63,14 +63,14 @@ pub impl BinaryTreeImpl of BinaryTreeTrait { fn left(self: @BinaryTree) -> @BinaryTree { @match self { Option::None => Option::None, - Option::Some(bst) => bst.left + Option::Some(bst) => bst.left, } } fn right(self: @BinaryTree) -> @BinaryTree { @match self { Option::None => Option::None, - Option::Some(bst) => bst.right + Option::Some(bst) => bst.right, } } } @@ -78,19 +78,19 @@ pub impl BinaryTreeImpl of BinaryTreeTrait { #[derive(Drop, Copy, Debug, PartialEq)] enum Path { Left, - Right + Right, } #[derive(Drop, Copy, Debug, PartialEq)] struct Ancestor { path: Path, - node: BinaryTreeNode + node: BinaryTreeNode, } #[derive(Drop, Debug, PartialEq)] struct Zipper { node: BinaryTreeNode, - ancestors: Span + ancestors: Span, } #[generate_trait] @@ -113,13 +113,13 @@ pub impl ZipperImpl of ZipperTrait { fn left(self: Zipper) -> Option { Self::new( - self.node.left, self.ancestors.append(Ancestor { path: Path::Left, node: self.node }) + self.node.left, self.ancestors.append(Ancestor { path: Path::Left, node: self.node }), ) } fn right(self: Zipper) -> Option { Self::new( - self.node.right, self.ancestors.append(Ancestor { path: Path::Right, node: self.node }) + self.node.right, self.ancestors.append(Ancestor { path: Path::Right, node: self.node }), ) } diff --git a/exercises/practice/zipper/Scarb.toml b/exercises/practice/zipper/Scarb.toml index d34df34b..64287484 100644 --- a/exercises/practice/zipper/Scarb.toml +++ b/exercises/practice/zipper/Scarb.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024_07" [dev-dependencies] -cairo_test = "2.8.2" +cairo_test = "2.9.2" diff --git a/exercises/practice/zipper/src/lib.cairo b/exercises/practice/zipper/src/lib.cairo index 8f35de8c..a2083a4b 100644 --- a/exercises/practice/zipper/src/lib.cairo +++ b/exercises/practice/zipper/src/lib.cairo @@ -12,7 +12,7 @@ pub impl OptionalBinaryTreeNodePartialEq of PartialEq match (lhs, rhs) { (Option::Some(lhs), Option::Some(rhs)) => (*lhs).unbox() == (*rhs).unbox(), (Option::None, Option::None) => true, - _ => false + _ => false, } } } @@ -63,14 +63,14 @@ pub impl BinaryTreeImpl of BinaryTreeTrait { fn left(self: @BinaryTree) -> @BinaryTree { @match self { Option::None => Option::None, - Option::Some(bst) => bst.left + Option::Some(bst) => bst.left, } } fn right(self: @BinaryTree) -> @BinaryTree { @match self { Option::None => Option::None, - Option::Some(bst) => bst.right + Option::Some(bst) => bst.right, } } } diff --git a/exercises/practice/zipper/tests/zipper.cairo b/exercises/practice/zipper/tests/zipper.cairo index 8b06fa6b..55886a24 100644 --- a/exercises/practice/zipper/tests/zipper.cairo +++ b/exercises/practice/zipper/tests/zipper.cairo @@ -3,7 +3,7 @@ use zipper::{ZipperTrait as Zipper, BinaryTreeTrait as BinaryTree, OptionalBinar #[test] fn data_is_retained() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let expected = initial_tree.clone(); let zipper = Zipper::from_tree(initial_tree)?; @@ -14,7 +14,7 @@ fn data_is_retained() -> Option<()> { #[test] fn left_right_and_value() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let zipper = Zipper::from_tree(initial_tree)?; assert_eq!(@3, zipper.left()?.right()?.value()); @@ -24,7 +24,7 @@ fn left_right_and_value() -> Option<()> { #[test] fn dead_end() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let zipper = Zipper::from_tree(initial_tree)?; assert!(zipper.left()?.left().is_none()); @@ -34,7 +34,7 @@ fn dead_end() -> Option<()> { #[test] fn tree_from_deep_focus() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let expected = initial_tree.clone(); let zipper = Zipper::from_tree(initial_tree)?; @@ -45,7 +45,7 @@ fn tree_from_deep_focus() -> Option<()> { #[test] fn traversing_up_from_top() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let zipper = Zipper::from_tree(initial_tree)?; assert!(zipper.up().is_none()); @@ -55,7 +55,7 @@ fn traversing_up_from_top() -> Option<()> { #[test] fn left_right_and_up() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let zipper = Zipper::from_tree(initial_tree)?; assert_eq!(@3, zipper.left()?.up()?.right()?.up()?.left()?.right()?.value()); @@ -65,7 +65,7 @@ fn left_right_and_up() -> Option<()> { #[test] fn test_ability_to_descend_multiple_levels_and_return() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let zipper = Zipper::from_tree(initial_tree)?; assert_eq!(@1, zipper.left()?.right()?.up()?.up()?.value()); @@ -75,10 +75,10 @@ fn test_ability_to_descend_multiple_levels_and_return() -> Option<()> { #[test] fn set_value() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let expected = BinaryTree::new( - 1, BinaryTree::new(5, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(5, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let zipper = Zipper::from_tree(initial_tree)?; assert_eq!(expected, zipper.left()?.set_value(5).to_tree()); @@ -88,10 +88,10 @@ fn set_value() -> Option<()> { #[test] fn set_value_after_traversing_up() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let expected = BinaryTree::new( - 1, BinaryTree::new(5, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(5, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let zipper = Zipper::from_tree(initial_tree)?; @@ -103,10 +103,10 @@ fn set_value_after_traversing_up() -> Option<()> { #[test] fn set_left_with_leaf() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let expected = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::leaf(5), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::leaf(5), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let zipper = Zipper::from_tree(initial_tree)?; @@ -118,7 +118,7 @@ fn set_left_with_leaf() -> Option<()> { #[test] fn set_right_with_leaf() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let expected = BinaryTree::new(1, BinaryTree::leaf(2), BinaryTree::leaf(4)); @@ -131,19 +131,19 @@ fn set_right_with_leaf() -> Option<()> { #[test] fn set_right_with_subtree() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let expected = BinaryTree::new( 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), - BinaryTree::new(6, BinaryTree::leaf(7), BinaryTree::leaf(8)) + BinaryTree::new(6, BinaryTree::leaf(7), BinaryTree::leaf(8)), ); let zipper = Zipper::from_tree(initial_tree)?; assert_eq!( expected, - zipper.set_right(BinaryTree::new(6, BinaryTree::leaf(7), BinaryTree::leaf(8))).to_tree() + zipper.set_right(BinaryTree::new(6, BinaryTree::leaf(7), BinaryTree::leaf(8))).to_tree(), ); Option::Some(()) } @@ -151,10 +151,10 @@ fn set_right_with_subtree() -> Option<()> { #[test] fn set_value_on_deep_focus() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let expected = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(5)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(5)), BinaryTree::leaf(4), ); let zipper = Zipper::from_tree(initial_tree)?; @@ -166,7 +166,7 @@ fn set_value_on_deep_focus() -> Option<()> { #[test] fn different_paths_to_same_zipper() -> Option<()> { let initial_tree = BinaryTree::new( - 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4) + 1, BinaryTree::new(2, BinaryTree::empty(), BinaryTree::leaf(3)), BinaryTree::leaf(4), ); let expected = Zipper::from_tree(initial_tree)?.right(); let actual = Zipper::from_tree(initial_tree)?.left()?.up()?.right();