From 016fb0bc9b4beccce99ddbeb79672ebfda954bc8 Mon Sep 17 00:00:00 2001 From: crabman Date: Mon, 18 Mar 2024 11:49:59 +0000 Subject: [PATCH] Removed normalized ProbabilityFile tests These tests no longer make sense, as multiple different items can now drop in one roll and the probabilities can't be normalized. These tests did not fail previously because they only checked one specific loot table, which hasn't been touched until now. --- common/src/comp/inventory/trade_pricing.rs | 50 +++------------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/common/src/comp/inventory/trade_pricing.rs b/common/src/comp/inventory/trade_pricing.rs index 4fe794bed1..f7089c805c 100644 --- a/common/src/comp/inventory/trade_pricing.rs +++ b/common/src/comp/inventory/trade_pricing.rs @@ -250,9 +250,12 @@ lazy_static! { } #[derive(Clone)] -/// A collection of items with probabilty (normalized to one), created +/// A collection of items with probabilty, created /// hierarchically from `LootSpec`s /// (probability, item id, average amount) +/// +/// This collection is NOT normalized (the sum of probabilities may not equal to +/// one, as maltiple items can drop in one roll) pub struct ProbabilityFile { pub content: Vec<(f32, ItemDefinitionIdOwned, f32)>, } @@ -1148,11 +1151,7 @@ pub fn expand_loot_table(loot_table: &str) -> Vec<(f32, ItemDefinitionIdOwned, f // cd common && cargo test trade_pricing -- --nocapture #[cfg(test)] mod tests { - use crate::{ - comp::inventory::trade_pricing::{ProbabilityFile, TradePricing}, - lottery::LootSpec, - trade::Good, - }; + use crate::{comp::inventory::trade_pricing::TradePricing, trade::Good}; use tracing::{info, Level}; use tracing_subscriber::{filter::EnvFilter, FmtSubscriber}; @@ -1192,43 +1191,4 @@ mod tests { info!("Random item {:?}*{}", i.0, i.1); } } - - fn normalized(probability: &ProbabilityFile) -> bool { - let sum = probability.content.iter().map(|(p, _, _)| p).sum::(); - (dbg!(sum) - 1.0).abs() < 1e-3 - } - - #[test] - fn test_normalizing_table1() { - let item = |asset: &str| LootSpec::Item(asset.to_owned()); - let loot_table = vec![(1.0, item("wow")), (1.0, item("nice"))]; - - let probability: ProbabilityFile = loot_table.into(); - assert!(normalized(&probability)); - } - - #[test] - fn test_normalizing_table2() { - let table = |asset: &str| LootSpec::LootTable(asset.to_owned()); - let loot_table = vec![( - 1.0, - table("common.loot_tables.creature.quad_medium.catoblepas"), - )]; - let probability: ProbabilityFile = loot_table.into(); - assert!(normalized(&probability)); - } - - #[test] - fn test_normalizing_table3() { - let table = |asset: &str| LootSpec::LootTable(asset.to_owned()); - let loot_table = vec![ - ( - 1.0, - table("common.loot_tables.creature.quad_medium.catoblepas"), - ), - (1.0, table("common.loot_tables.creature.quad_medium.gentle")), - ]; - let probability: ProbabilityFile = loot_table.into(); - assert!(normalized(&probability)); - } }