Initial work on outlining the dynamic side of the library.

This commit is contained in:
2021-01-31 17:31:22 +01:00
parent 2a08fb2645
commit c194c5d209
24 changed files with 321 additions and 39 deletions

View File

@@ -33,12 +33,11 @@ impl Debug for GrowthRateLibrary {
}
#[cfg(test)]
mod tests {
pub mod tests {
use crate::static_data::growth_rates::lookup_growth_rate::LookupGrowthRate;
use crate::static_data::libraries::growth_rate_library::GrowthRateLibrary;
#[test]
fn add_growth_rate_to_library_and_calculate_level() {
pub fn build() -> GrowthRateLibrary {
let mut lib = GrowthRateLibrary::new(1);
// Borrow as mut so we can insert
@@ -46,24 +45,20 @@ mod tests {
w.add_growth_rate("foo", Box::new(LookupGrowthRate::new(vec![0, 5, 10, 100])));
// Drops borrow as mut
// Borrow as read so we can read
let r = &lib;
assert_eq!(r.calculate_level("foo", 3), 1);
assert_eq!(r.calculate_level("foo", 50), 3);
lib
}
#[test]
fn add_growth_rate_to_library_and_calculate_level() {
let lib = build();
assert_eq!(lib.calculate_level("foo", 3), 1);
assert_eq!(lib.calculate_level("foo", 50), 3);
}
#[test]
fn add_growth_rate_to_library_and_calculate_experience() {
let mut lib = GrowthRateLibrary::new(1);
// Borrow as mut so we can insert
let w = &mut lib;
w.add_growth_rate("foo", Box::new(LookupGrowthRate::new(vec![0, 5, 10, 100])));
// Drops borrow as mut
// Borrow as read so we can read
let r = &lib;
assert_eq!(r.calculate_experience("foo", 1), 0);
assert_eq!(r.calculate_experience("foo", 3), 10);
let lib = build();
assert_eq!(lib.calculate_experience("foo", 1), 0);
assert_eq!(lib.calculate_experience("foo", 3), 10);
}
}