Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add evolution model and comprehensive tests for evolution requirements #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 121 additions & 3 deletions src/models/evolution.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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")
}
}
}
}