From a90045737d15fd2a35fe17d03761c792fa8bffaa Mon Sep 17 00:00:00 2001 From: Mario Fernando Araya Royo Date: Wed, 7 May 2025 13:33:13 -0600 Subject: [PATCH] test: add unit tests for BeastType conversions --- .../src/tests/test_beast_type.cairo | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 backend/dojo_examples/combat_game/src/tests/test_beast_type.cairo diff --git a/backend/dojo_examples/combat_game/src/tests/test_beast_type.cairo b/backend/dojo_examples/combat_game/src/tests/test_beast_type.cairo new file mode 100644 index 0000000..d6b5388 --- /dev/null +++ b/backend/dojo_examples/combat_game/src/tests/test_beast_type.cairo @@ -0,0 +1,58 @@ +#[cfg(test)] +mod tests { + use super::BeastType; + use core::convert::Into; + use starknet::testing::assert_eq; + + #[test] + fn test_beast_type_into_felt252() { + assert_eq!(Into::::into(BeastType::Fire), 'Fire'); + assert_eq!(Into::::into(BeastType::Water), 'Water'); + assert_eq!(Into::::into(BeastType::Earth), 'Earth'); + assert_eq!(Into::::into(BeastType::Electric), 'Electric'); + assert_eq!(Into::::into(BeastType::Dragon), 'Dragon'); + assert_eq!(Into::::into(BeastType::Ice), 'Ice'); + assert_eq!(Into::::into(BeastType::Magic), 'Magic'); + assert_eq!(Into::::into(BeastType::Rock), 'Rock'); + assert_eq!(Into::::into(BeastType::Undefined), 'Undefined'); + } + + #[test] + fn test_beast_type_into_u8() { + assert_eq!(Into::::into(BeastType::Fire), 0_u8); + assert_eq!(Into::::into(BeastType::Water), 1_u8); + assert_eq!(Into::::into(BeastType::Earth), 2_u8); + assert_eq!(Into::::into(BeastType::Electric), 3_u8); + assert_eq!(Into::::into(BeastType::Dragon), 4_u8); + assert_eq!(Into::::into(BeastType::Ice), 5_u8); + assert_eq!(Into::::into(BeastType::Magic), 6_u8); + assert_eq!(Into::::into(BeastType::Rock), 7_u8); + assert_eq!(Into::::into(BeastType::Undefined), 8_u8); + } + + #[test] + fn test_u8_into_beast_type_valid() { + assert_eq!(Into::::into(0_u8), BeastType::Fire); + assert_eq!(Into::::into(1_u8), BeastType::Water); + assert_eq!(Into::::into(2_u8), BeastType::Earth); + assert_eq!(Into::::into(3_u8), BeastType::Electric); + assert_eq!(Into::::into(4_u8), BeastType::Dragon); + assert_eq!(Into::::into(5_u8), BeastType::Ice); + assert_eq!(Into::::into(6_u8), BeastType::Magic); + assert_eq!(Into::::into(7_u8), BeastType::Rock); + } + + #[test] + fn test_u8_into_beast_type_invalid() { + assert_eq!(Into::::into(8_u8), BeastType::Undefined); + assert_eq!(Into::::into(9_u8), BeastType::Undefined); + assert_eq!(Into::::into(255_u8), BeastType::Undefined); + assert_eq!(Into::::into(100_u8), BeastType::Undefined); + } + + #[test] + fn test_edge_cases() { + assert_eq!(Into::::into(0_u8), BeastType::Fire); + assert_eq!(Into::::into(255_u8), BeastType::Undefined); + } +}