Initial work on outlining the dynamic side of the library.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,3 +30,33 @@ impl DataLibrary<'_, Item> for ItemLibrary {
|
||||
(&mut self.map, &mut self.list)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use crate::static_data::items::item::Item;
|
||||
use crate::static_data::items::item_category::{BattleItemCategory, ItemCategory};
|
||||
use crate::static_data::libraries::data_library::DataLibrary;
|
||||
use crate::static_data::libraries::item_library::ItemLibrary;
|
||||
use std::collections::HashSet;
|
||||
|
||||
fn build_item() -> Item {
|
||||
Item::new(
|
||||
"foo",
|
||||
ItemCategory::MiscItem,
|
||||
BattleItemCategory::MiscBattleItem,
|
||||
100,
|
||||
HashSet::new(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn build() -> ItemLibrary {
|
||||
let mut lib = ItemLibrary::new(1);
|
||||
let m = build_item();
|
||||
// Borrow as mut so we can insert
|
||||
let w = &mut lib;
|
||||
w.add("foo", m);
|
||||
// Drops borrow as mut
|
||||
|
||||
lib
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@ use derive_getters::Getters;
|
||||
|
||||
#[derive(Getters, Debug)]
|
||||
pub struct LibrarySettings {
|
||||
maximum_level: LevelInt,
|
||||
maximum_move_count: u8,
|
||||
pub(crate) maximum_level: LevelInt,
|
||||
}
|
||||
|
||||
@@ -30,3 +30,38 @@ impl DataLibrary<'_, MoveData> for MoveLibrary {
|
||||
(&mut self.map, &mut self.list)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use crate::static_data::libraries::data_library::DataLibrary;
|
||||
use crate::static_data::libraries::move_library::MoveLibrary;
|
||||
use crate::static_data::moves::move_data::{MoveCategory, MoveData, MoveTarget};
|
||||
use crate::static_data::moves::secondary_effect::SecondaryEffect;
|
||||
use std::collections::HashSet;
|
||||
|
||||
fn build_move() -> MoveData {
|
||||
MoveData::new(
|
||||
"foo",
|
||||
0,
|
||||
MoveCategory::Physical,
|
||||
100,
|
||||
100,
|
||||
30,
|
||||
MoveTarget::Any,
|
||||
0,
|
||||
SecondaryEffect::empty(),
|
||||
HashSet::new(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn build() -> MoveLibrary {
|
||||
let mut lib = MoveLibrary::new(1);
|
||||
let m = build_move();
|
||||
// Borrow as mut so we can insert
|
||||
let w = &mut lib;
|
||||
w.add("foo", m);
|
||||
// Drops borrow as mut
|
||||
|
||||
lib
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<'a> DataLibrary<'a, Species<'a>> for SpeciesLibrary<'a> {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub mod tests {
|
||||
use crate::static_data::libraries::data_library::DataLibrary;
|
||||
use crate::static_data::libraries::species_library::SpeciesLibrary;
|
||||
use crate::static_data::species_data::form::Form;
|
||||
@@ -64,16 +64,21 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_species_to_library_and_fetch() {
|
||||
pub fn build<'a>() -> SpeciesLibrary<'a> {
|
||||
let mut lib = SpeciesLibrary::new(1);
|
||||
let species = build_species();
|
||||
|
||||
// Borrow as mut so we can insert
|
||||
let w = &mut lib;
|
||||
w.add("foo", species);
|
||||
// Drops borrow as mut
|
||||
|
||||
lib
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_species_to_library_and_fetch() {
|
||||
let lib = build();
|
||||
|
||||
// Borrow as read so we can read
|
||||
let r = &lib;
|
||||
let mon = r.get("foo");
|
||||
@@ -85,14 +90,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn add_species_to_library_then_remove() {
|
||||
let mut lib = SpeciesLibrary::new(1);
|
||||
let species = build_species();
|
||||
let mut lib = build();
|
||||
|
||||
// Borrow as mut so we can insert
|
||||
let w = &mut lib;
|
||||
w.add("foo", species);
|
||||
w.remove("foo");
|
||||
// Drops borrow as mut
|
||||
lib.remove("foo");
|
||||
|
||||
// Borrow as read so we can read
|
||||
let r = &lib;
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::static_data::libraries::type_library::TypeLibrary;
|
||||
use derive_getters::Getters;
|
||||
|
||||
#[derive(Getters, Debug)]
|
||||
struct StaticData<'a> {
|
||||
pub struct StaticData<'a> {
|
||||
settings: LibrarySettings,
|
||||
species: SpeciesLibrary<'a>,
|
||||
moves: MoveLibrary,
|
||||
@@ -15,3 +15,23 @@ struct StaticData<'a> {
|
||||
growth_rates: GrowthRateLibrary,
|
||||
types: TypeLibrary,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod test {
|
||||
use crate::static_data::libraries::library_settings::LibrarySettings;
|
||||
use crate::static_data::libraries::static_data::StaticData;
|
||||
use crate::static_data::libraries::{
|
||||
growth_rate_library, item_library, move_library, species_library, type_library,
|
||||
};
|
||||
|
||||
pub fn build<'a>() -> StaticData<'a> {
|
||||
StaticData {
|
||||
settings: LibrarySettings { maximum_level: 100 },
|
||||
species: species_library::tests::build(),
|
||||
moves: move_library::tests::build(),
|
||||
items: item_library::tests::build(),
|
||||
growth_rates: growth_rate_library::tests::build(),
|
||||
types: type_library::tests::build(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +46,25 @@ impl TypeLibrary {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub mod tests {
|
||||
use crate::static_data::libraries::type_library::TypeLibrary;
|
||||
use assert_approx_eq::assert_approx_eq;
|
||||
|
||||
pub fn build() -> TypeLibrary {
|
||||
let mut lib = TypeLibrary::new(2);
|
||||
|
||||
// Borrow as mut so we can insert
|
||||
let w = &mut lib;
|
||||
w.register_type("foo");
|
||||
w.register_type("bar");
|
||||
// Drops borrow as mut
|
||||
|
||||
w.set_effectiveness(0, 1, 0.5);
|
||||
w.set_effectiveness(1, 0, 2.0);
|
||||
|
||||
lib
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_two_types_retrieve_them() {
|
||||
let mut lib = TypeLibrary::new(2);
|
||||
|
||||
@@ -44,7 +44,7 @@ pub struct MoveData {
|
||||
|
||||
impl MoveData {
|
||||
pub fn new(
|
||||
name: String,
|
||||
name: &str,
|
||||
move_type: u8,
|
||||
category: MoveCategory,
|
||||
base_power: u8,
|
||||
@@ -56,7 +56,7 @@ impl MoveData {
|
||||
flags: HashSet<String>,
|
||||
) -> MoveData {
|
||||
MoveData {
|
||||
name,
|
||||
name: name.to_string(),
|
||||
move_type,
|
||||
category,
|
||||
base_power,
|
||||
|
||||
@@ -47,7 +47,7 @@ mod tests {
|
||||
fn adds_level_moves() {
|
||||
let mut moves = LearnableMoves::new();
|
||||
let move1 = MoveData::new(
|
||||
"foo".to_string(),
|
||||
"foo",
|
||||
0,
|
||||
MoveCategory::Physical,
|
||||
0,
|
||||
@@ -59,7 +59,7 @@ mod tests {
|
||||
Default::default(),
|
||||
);
|
||||
let move2 = MoveData::new(
|
||||
"bar".to_string(),
|
||||
"bar",
|
||||
0,
|
||||
MoveCategory::Physical,
|
||||
0,
|
||||
@@ -83,7 +83,7 @@ mod tests {
|
||||
fn adds_two_same_moves_at_different_level() {
|
||||
let mut moves = LearnableMoves::new();
|
||||
let move1 = MoveData::new(
|
||||
"foo".to_string(),
|
||||
"foo",
|
||||
0,
|
||||
MoveCategory::Physical,
|
||||
0,
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::statistics::Statistic;
|
||||
use derive_getters::Getters;
|
||||
use num_traits::PrimInt;
|
||||
|
||||
#[derive(Default, Eq, PartialEq, Debug, Getters)]
|
||||
#[derive(Default, Eq, PartialEq, Copy, Clone, Debug, Getters)]
|
||||
pub struct StatisticSet<T>
|
||||
where
|
||||
T: PrimInt,
|
||||
|
||||
Reference in New Issue
Block a user