mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
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.
This commit is contained in:
parent
78cd928069
commit
016fb0bc9b
@ -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::<f32>();
|
||||
(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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user