diff --git a/exercises/concept/the-realm-of-echoes/.docs/hints.md b/exercises/concept/the-realm-of-echoes/.docs/hints.md index 9e5c7101..e69de29b 100644 --- a/exercises/concept/the-realm-of-echoes/.docs/hints.md +++ b/exercises/concept/the-realm-of-echoes/.docs/hints.md @@ -1,27 +0,0 @@ -# Hints - -## General - -- [The Cairo Book: ByteArrays][book-bytearrays] -- [Starknet By Example: Strings & ByteArrays][sbe-strings] - -### 1. Format a magical chant - -- Use the `format!` macro to combine multiple `ByteArray` inputs into a single string. -- Separate the chants with a delimiter such as `"-"` to match the expected output. -- Ensure the output is returned as a `ByteArray`. - -### 2. Implement a `Display` trait for `EchoStone` - -- The `Display` trait allows you to define how the `EchoStone` should appear when printed with `{}`. -- Use the `write!` macro within the `fmt` function to format the output string. -- Include both `power` and `duration` fields in a clear and concise format, e.g., `EchoStone [power: X, duration: Y]`. - -### 3. Implement a `Debug` trait for `EchoStone` - -- The `Debug` trait is used for debugging purposes, allowing for more detailed or structured output when printed with `{:?}`. -- Follow a clear debugging format, such as `Debugging EchoStone: { power: X, duration: Y }`. -- Use the `write!` macro to create the debug output. - -[book-bytearrays]: https://book.cairo-lang.org/ch02-02-data-types.html#string-types -[sbe-strings]: https://starknet-by-example.voyager.online/getting-started/basics/bytearrays-strings diff --git a/exercises/concept/the-realm-of-echoes/.docs/introduction.md b/exercises/concept/the-realm-of-echoes/.docs/introduction.md index defc29ef..e69de29b 100644 --- a/exercises/concept/the-realm-of-echoes/.docs/introduction.md +++ b/exercises/concept/the-realm-of-echoes/.docs/introduction.md @@ -1,46 +0,0 @@ -# Introduction - -Printing in Cairo allows you to display messages or debug information during program execution. - -## Basics - -Cairo provides two macros for printing: - -- `println!`: Outputs a message followed by a newline. -- `print!`: Outputs a message without a newline. - -```rust -println!("Hello, Cairo!"); -println!("x = {}, y = {}", 10, 20); -``` - -Placeholders `{}` are replaced with provided values. - -## Formatting Strings - -Use `format!` to create a `ByteArray` without immediately printing: - -```rust -let result = format!("{}-{}-{}", "tic", "tac", "toe"); -println!("{}", result); // Output: tic-tac-toe -``` - -## Custom Data Types - -For custom types, implement `Display` or derive `Debug` for printing: - -```rust -#[derive(Debug)] -struct Point { x: u8, y: u8 } - -let p = Point { x: 3, y: 4 }; -println!("{:?}", p); // Debug output: Point { x: 3, y: 4 } -``` - -## Hexadecimal Printing - -Use `{:x}` to print integers as hexadecimal: - -```rust -println!("{:x}", 255); // Output: ff -``` diff --git a/exercises/concept/the-realm-of-echoes/.meta/config.json b/exercises/concept/the-realm-of-echoes/.meta/config.json index 83352bc6..8af744c3 100644 --- a/exercises/concept/the-realm-of-echoes/.meta/config.json +++ b/exercises/concept/the-realm-of-echoes/.meta/config.json @@ -16,5 +16,5 @@ "Scarb.toml" ] }, - "blurb": "Learn printing and formatting values with the art of EchoSpeak." + "blurb": "" } diff --git a/exercises/concept/the-realm-of-echoes/.meta/design.md b/exercises/concept/the-realm-of-echoes/.meta/design.md index 4737e9f1..e69de29b 100644 --- a/exercises/concept/the-realm-of-echoes/.meta/design.md +++ b/exercises/concept/the-realm-of-echoes/.meta/design.md @@ -1,36 +0,0 @@ -# Design - -## Goal - -Introduce students to the use of formatting traits like `Display` and `Debug` and how to concatenate strings effectively using the `format!` macro. - -## Learning Objectives - -- Understand and implement the `Display` trait for custom types. -- Understand and implement the `Debug` trait for custom types. -- Learn how to use the `format!` macro to concatenate strings and format output. -- Explore the differences between the `Display` and `Debug` traits in formatting. - -## Out of Scope - -- Advanced string manipulation techniques. -- Error handling mechanisms beyond basic usage. -- Interaction with non-primitive custom types within formatting. - -## Concepts - -- printing - -## Prerequisites - -- traits -- strings -- structs - -## Resources to Refer To - -- [Cairo Book - Printing][printing] -- [Cairo Book - Macros][macros] - -[printing]: https://book.cairo-lang.org/ch11-08-printing.html -[macros]: https://book.cairo-lang.org/ch11-05-macros.html diff --git a/exercises/concept/the-realm-of-echoes/tests/the_realm_of_echoes.cairo b/exercises/concept/the-realm-of-echoes/tests/the_realm_of_echoes.cairo index 95601ebc..69e31eab 100644 --- a/exercises/concept/the-realm-of-echoes/tests/the_realm_of_echoes.cairo +++ b/exercises/concept/the-realm-of-echoes/tests/the_realm_of_echoes.cairo @@ -1,86 +1,21 @@ use the_realm_of_echoes::{EchoStone, format_magical_chant}; -const U32_MAX: u32 = 0xFFFFFFFF; - -#[test] -fn format_magical_chant_basic() { - let chant1 = "abra"; - let chant2 = "cadabra"; - let chant3 = "alakazam"; - assert_eq!(format_magical_chant(chant1, chant2, chant3), "abra-cadabra-alakazam"); -} - -#[test] -#[ignore] -fn format_magical_chant_empty_strings() { - let chant1 = ""; - let chant2 = ""; - let chant3 = ""; - assert_eq!(format_magical_chant(chant1, chant2, chant3), "--"); -} - -#[test] -#[ignore] -fn format_magical_chant_mixed_empty_and_non_empty() { - let chant1 = "abra"; - let chant2 = ""; - let chant3 = "alakazam"; - assert_eq!(format_magical_chant(chant1, chant2, chant3), "abra--alakazam"); -} - -#[test] -#[ignore] -fn format_magical_chant_with_special_characters() { - let chant1 = "ab@ra"; - let chant2 = "ca!dabra"; - let chant3 = "ala#kazam"; - assert_eq!(format_magical_chant(chant1, chant2, chant3), "ab@ra-ca!dabra-ala#kazam"); -} - -#[test] -#[ignore] -fn echo_stone_display_basic() { - let stone = EchoStone { power: 100, duration: 50 }; - assert_eq!(format!("{stone}"), "EchoStone [power: 100, duration: 50]"); -} - #[test] -#[ignore] -fn echo_stone_display_zero_values() { - let stone = EchoStone { power: 0, duration: 0 }; - assert_eq!(format!("{stone}"), "EchoStone [power: 0, duration: 0]"); -} - - -#[test] -#[ignore] -fn echo_stone_display_large_values() { - let stone = EchoStone { power: U32_MAX, duration: U32_MAX }; - assert_eq!( - format!("{stone}"), format!("EchoStone [power: {}, duration: {}]", U32_MAX, U32_MAX), - ); -} - -#[test] -#[ignore] -fn echo_stone_debug_basic() { - let stone = EchoStone { power: 100, duration: 50 }; - assert_eq!(format!("{stone:?}"), "Debugging EchoStone: { power: 100, duration: 50 }"); +fn test_format_magical_chant() { + let result = format_magical_chant("Spark", "Shine", "Glow"); + assert_eq!(result, "Spark-Shine-Glow"); } #[test] #[ignore] -fn echo_stone_debug_zero_values() { - let stone = EchoStone { power: 0, duration: 0 }; - assert_eq!(format!("{stone:?}"), "Debugging EchoStone: { power: 0, duration: 0 }"); +fn test_stringify_echo_stone() { + let stone = EchoStone { power: 100, duration: 300 }; + assert_eq!(format!("{stone}"), "EchoStone [power: 100, duration: 300]"); } #[test] #[ignore] -fn echo_stone_debug_large_values() { - let stone = EchoStone { power: U32_MAX, duration: U32_MAX }; - assert_eq!( - format!("{stone:?}"), - format!("Debugging EchoStone: {{ power: {}, duration: {} }}", U32_MAX, U32_MAX), - ); +fn test_debug_echo_stone() { + let stone = EchoStone { power: 100, duration: 300 }; + assert_eq!(format!("{:?}", stone), "Debugging EchoStone: { power: 100, duration: 300 }"); }