diff --git a/src/models/evolution.cairo b/src/models/evolution.cairo index c9a6241..4b9d8db 100644 --- a/src/models/evolution.cairo +++ b/src/models/evolution.cairo @@ -12,15 +12,12 @@ struct Evolution { } mod rules { - /// Minimum rules for beast evolution - /// Minimum level required before evolution is possible const LEVEL_REQUIREMENT: u32 = 10; /// Minimum number of battles required before evolution const REQUIRED_BATTLES: u32 = 5; /// Item ID required for evolution (special evolution stone) const REQUIRED_ITEM: u32 = 1001; - } #[generate_trait] @@ -49,3 +46,124 @@ impl EvolutionImpl of EvolutionTrait { } } } + + +#[cfg(test)] +mod tests { + use super::{Evolution, EvolutionTrait}; + use core::result::Result; + + #[test] + fn test_evolution_with_valid_requirements() { + + let mut evolution = Evolution { + base_beast_id: 1_u32, + evolved_beast_id: 0_u32, + level_requirement: 15_u32, + required_battles: 10_u32, + required_item: Option::Some(1001_u32) + }; + + let result = evolution.evolve(); + + match result { + Result::Ok(evolved_id) => { + assert(evolved_id == 10_u32, 'Incorrect evolution ID'); + assert(evolution.evolved_beast_id == 10_u32, 'Beast not evolved correctly'); + }, + Result::Err(_) => { + panic!("Evolution should have succeeded") + } + } + } + + #[test] + fn test_evolution_with_invalid_level() { + + let mut evolution = Evolution { + base_beast_id: 1_u32, + evolved_beast_id: 0_u32, + level_requirement: 5_u32, + required_battles: 10_u32, + required_item: Option::Some(1001_u32) + }; + + let result = evolution.evolve(); + + match result { + Result::Ok(_) => { + panic!("Evolution should have failed due to low level") + }, + Result::Err(e) => { + assert(e == 'Evolution requirements not met', 'Unexpected error message'); + } + } + } + + #[test] + fn test_evolution_with_invalid_battles() { + + let mut evolution = Evolution { + base_beast_id: 1_u32, + evolved_beast_id: 0_u32, + level_requirement: 15_u32, + required_battles: 3_u32, + required_item: Option::Some(1001_u32) + }; + + let result = evolution.evolve(); + match result { + Result::Ok(_) => { + panic!("Evolution should have failed due to insufficient battles") + }, + Result::Err(e) => { + assert(e == 'Evolution requirements not met', 'Unexpected error message'); + } + } + } + + #[test] + fn test_evolution_with_invalid_item() { + + let mut evolution = Evolution { + base_beast_id: 1_u32, + evolved_beast_id: 0_u32, + level_requirement: 15_u32, + required_battles: 10_u32, + required_item: Option::Some(999_u32) + }; + + let result = evolution.evolve(); + match result { + Result::Ok(_) => { + panic!("Evolution should have failed due to wrong item") + }, + Result::Err(e) => { + assert(e == 'Evolution requirements not met', 'Unexpected error message'); + } + } + } + + #[test] + fn test_evolution_with_no_item_requirement() { + + let mut evolution = Evolution { + base_beast_id: 1_u32, + evolved_beast_id: 0_u32, + level_requirement: 15_u32, + required_battles: 10_u32, + required_item: Option::None + }; + + let result = evolution.evolve(); + + match result { + Result::Ok(evolved_id) => { + assert(evolved_id == 10_u32, 'Incorrect evolution ID'); + }, + Result::Err(_) => { + panic!("Evolution should have succeeded without item requirement") + } + } + } +} \ No newline at end of file