Adds massive testing and coverage
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2025-12-13 05:01:56 +01:00
parent e109918280
commit 9cc59b21b9
8 changed files with 318 additions and 156 deletions

View File

@ -1,8 +1,8 @@
[last_run_clean]
run_status = "Success"
lines_parsed = 76
coverage = 38.61
lines_parsed = 83
coverage = 51.17
[last_run_clean.run_duration]
secs = 24
nanos = 391618885
nanos = 975426411

View File

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 39%"><title>test-coverage: 39%</title><linearGradient id="bms-59b9855e9d3baaa7" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-59b9855e9d3baaa7"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-59b9855e9d3baaa7)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-59b9855e9d3baaa7)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">39%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">39%</text></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 51%"><title>test-coverage: 51%</title><linearGradient id="bms-4635e915b4180cf4" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-4635e915b4180cf4"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-4635e915b4180cf4)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-4635e915b4180cf4)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">51%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">51%</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,8 @@
---
source: lib_efo/src/stats/implementations/test.rs
expression: out
---
⟳:⟳
⥯:⥯
☈:☈
✓:✓

View File

@ -0,0 +1,7 @@
---
source: lib_efo/src/stats/implementations/test.rs
expression: out
---
∞
⧗42
✔

View File

@ -0,0 +1,10 @@
---
source: lib_efo/src/stats/implementations/test.rs
expression: out
---
:[C]
 :[P]
󱡵 :[T]
 :[M]
 :[B]
:[E]

View File

@ -0,0 +1,67 @@
---
source: lib_efo/src/stats/implementations/test.rs
expression: output
---
demographics: :Dem:34
demographics: :Dem:34
demographics: :Dem:34
demographics: :Dem:34
population: :Pop:35
population: :Pop:35
population: :Pop:35
growthrate: :Gro:36
growthrate: :Gro:36
growthrate: :Gro:36
crime:󱀣:Cri:37
crime:󱀣:Cri:37
crime:󱀣:Cri:37
happiness: :Hap:38
happiness: :Hap:38
happiness: :Hap:38
economy:💰:Eco:39
economy:💰:Eco:39
economy:💰:Eco:39
food:󰔬:Foo:40
food:󰔬:Foo:40
food:󰔬:Foo:40
food:󰔬:Foo:40
food:󰔬:Foo:40
industry:🏭:Ind:41
industry:🏭:Ind:41
industry:🏭:Ind:41
science:󰧑 :Sci:42
science:󰧑 :Sci:42
science:󰧑 :Sci:42
trade: :Tra:43
trade: :Tra:43
trade: :Tra:43
military:🪖:Mil:44
military:🪖:Mil:44
military:🪖:Mil:44
army: :Arm:45
army: :Arm:45
army: :Arm:45
strength:󰞇 :Str:46
strength:󰞇 :Str:46
strength:󰞇 :Str:46
fortification:🔒:For:47
fortification:🔒:For:47
fortification:🔒:For:47
threat:⚡:Thr:48
threat:⚡:Thr:48
threat:⚡:Thr:48
infrastructure:🏗️ :Inf:49
infrastructure:🏗️ :Inf:49
infrastructure:🏗️ :Inf:49
bureaucracy:🏛️ :Bur:50
bureaucracy:🏛️ :Bur:50
bureaucracy:🏛️ :Bur:50
transportation:󰔬 :Tra:51
transportation:󰔬 :Tra:51
transportation:󰔬 :Tra:51
sprawl:🏙️:Spr:52
sprawl:🏙️:Spr:52
sprawl:🏙️:Spr:52
health::Hea:53
health::Hea:53
health::Hea:53

View File

@ -0,0 +1,6 @@
---
source: lib_efo/src/stats/implementations/test.rs
expression: out
---
12,34( 12, 34)⚓
0,0( 0, 0)⚓

View File

@ -1,5 +1,9 @@
#![allow(clippy::unwrap_used)]
use insta::assert_debug_snapshot;
use insta::assert_snapshot;
use super::*;
use crate::entity::Entity;
use crate::stats::GameStat;
use crate::stats::GenericStat;
use crate::stats::StatPair;
@ -54,157 +58,217 @@ fn test_stat_pair_parsing() {
assert_pair_ok("Pop -5", ListStats::Population, -5);
assert_pair_ok("grow 0", ListStats::Growthrate, 0);
}
#[test]
fn test_list_stats_all_aliases() {
let stats = OverallStats::default();
// Demographics
assert_stat_ok("dem", ListStats::Demographics);
assert_stat_ok("Demog", ListStats::Demographics);
assert_stat_ok("DEMOGRAPHICS", ListStats::Demographics);
assert_stat_ok("Demo", ListStats::Demographics);
stats.get_field_from_str(ListStats::Demographics.into());
// Population
assert_stat_ok("pop", ListStats::Population);
assert_stat_ok("Popul", ListStats::Population);
assert_stat_ok("POPULATIONS", ListStats::Population);
stats.get_field_from_str((ListStats::Population).into());
// Growthrate
assert_stat_ok("grow", ListStats::Growthrate);
assert_stat_ok("GRW", ListStats::Growthrate);
assert_stat_ok("Growth", ListStats::Growthrate);
stats.get_field_from_str(ListStats::Growthrate.into());
// Crime
assert_stat_ok("cri", ListStats::Crime);
assert_stat_ok("CRIM", ListStats::Crime);
assert_stat_ok("Crimes", ListStats::Crime);
stats.get_field_from_str(ListStats::Crime.into());
// Happiness
assert_stat_ok("hapn", ListStats::Happiness);
assert_stat_ok("HAPPINES", ListStats::Happiness);
assert_stat_ok("hap", ListStats::Happiness);
stats.get_field_from_str(ListStats::Happiness.into());
// Economy
assert_stat_ok("eco", ListStats::Economy);
assert_stat_ok("Economy", ListStats::Economy);
assert_stat_ok("econ", ListStats::Economy);
stats.get_field_from_str(ListStats::Economy.into());
// Food
assert_stat_ok("food", ListStats::Food);
assert_stat_ok("fo", ListStats::Food);
assert_stat_ok("agr", ListStats::Food);
assert_stat_ok("agri", ListStats::Food);
stats.get_field_from_str(ListStats::Food.into());
// Industry
assert_stat_ok("industry", ListStats::Industry);
assert_stat_ok("Indus", ListStats::Industry);
assert_stat_ok("ind", ListStats::Industry);
stats.get_field_from_str(ListStats::Industry.into());
// Science
assert_stat_ok("science", ListStats::Science);
assert_stat_ok("sci", ListStats::Science);
assert_stat_ok("sc", ListStats::Science);
stats.get_field_from_str(ListStats::Science.into());
// Trade
assert_stat_ok("trade", ListStats::Trade);
assert_stat_ok("trd", ListStats::Trade);
assert_stat_ok("tr", ListStats::Trade);
stats.get_field_from_str(ListStats::Trade.into());
// Social
assert_stat_ok("social", ListStats::Social);
assert_stat_ok("soc", ListStats::Social);
assert_stat_ok("sl", ListStats::Social);
stats.get_field_from_str(ListStats::Social.into());
// Culture
assert_stat_ok("culture", ListStats::Culture);
assert_stat_ok("cul", ListStats::Culture);
assert_stat_ok("cl", ListStats::Culture);
stats.get_field_from_str(ListStats::Culture.into());
// Education
assert_stat_ok("education", ListStats::Education);
assert_stat_ok("edu", ListStats::Education);
assert_stat_ok("ed", ListStats::Education);
stats.get_field_from_str(ListStats::Education.into());
// Tourism
assert_stat_ok("tourism", ListStats::Tourism);
assert_stat_ok("tour", ListStats::Tourism);
assert_stat_ok("tm", ListStats::Tourism);
stats.get_field_from_str(ListStats::Tourism.into());
// Influence
assert_stat_ok("influence", ListStats::Influence);
assert_stat_ok("infl", ListStats::Influence);
assert_stat_ok("influ", ListStats::Influence);
stats.get_field_from_str(ListStats::Influence.into());
// Military
assert_stat_ok("military", ListStats::Military);
assert_stat_ok("mil", ListStats::Military);
assert_stat_ok("mt", ListStats::Military);
stats.get_field_from_str(ListStats::Military.into());
// Army
assert_stat_ok("army", ListStats::Army);
assert_stat_ok("arm", ListStats::Army);
assert_stat_ok("ar", ListStats::Army);
stats.get_field_from_str(ListStats::Army.into());
// Strength
assert_stat_ok("strength", ListStats::Strength);
assert_stat_ok("str", ListStats::Strength);
assert_stat_ok("st", ListStats::Strength);
stats.get_field_from_str(ListStats::Strength.into());
// Fortification
assert_stat_ok("fortification", ListStats::Fortification);
assert_stat_ok("fort", ListStats::Fortification);
assert_stat_ok("ft", ListStats::Fortification);
stats.get_field_from_str(ListStats::Fortification.into());
// Threat
assert_stat_ok("threat", ListStats::Threat);
assert_stat_ok("thr", ListStats::Threat);
assert_stat_ok("th", ListStats::Threat);
stats.get_field_from_str(ListStats::Threat.into());
// Infrastructure
assert_stat_ok("infrastructure", ListStats::Infrastructure);
assert_stat_ok("infra", ListStats::Infrastructure);
assert_stat_ok("infr", ListStats::Infrastructure);
stats.get_field_from_str(ListStats::Infrastructure.into());
// Bureaucracy
assert_stat_ok("bureaucracy", ListStats::Bureaucracy);
assert_stat_ok("bureau", ListStats::Bureaucracy);
assert_stat_ok("bur", ListStats::Bureaucracy);
stats.get_field_from_str(ListStats::Bureaucracy.into());
// Transportation
assert_stat_ok("transportation", ListStats::Transportation);
assert_stat_ok("trans", ListStats::Transportation);
assert_stat_ok("trns", ListStats::Transportation);
stats.get_field_from_str(ListStats::Transportation.into());
// Sprawl
assert_stat_ok("sprawl", ListStats::Sprawl);
assert_stat_ok("spr", ListStats::Sprawl);
assert_stat_ok("spra", ListStats::Sprawl);
stats.get_field_from_str(ListStats::Sprawl.into());
// Health
assert_stat_ok("health", ListStats::Health);
assert_stat_ok("hlth", ListStats::Health);
assert_stat_ok("hlt", ListStats::Health);
stats.get_field_from_str(ListStats::Health.into());
fn test_liststats_aliases() {
// Each tuple: (alias, expected enum variant)
let cases = vec![
// Demographics
("dem", ListStats::Demographics),
("DEMOg", ListStats::Demographics),
("demoGRAphicS", ListStats::Demographics),
("demo", ListStats::Demographics),
// Population
("Pop", ListStats::Population),
("POPUl", ListStats::Population),
("populations", ListStats::Population),
// Growth rate
("grow", ListStats::Growthrate),
("grW", ListStats::Growthrate),
("Growth", ListStats::Growthrate),
// Crime
("CRI", ListStats::Crime),
("crim", ListStats::Crime),
("Crimes", ListStats::Crime),
// Happiness
("hapN", ListStats::Happiness),
("HAPPiNeS", ListStats::Happiness),
("hap", ListStats::Happiness),
// Economy
("eco", ListStats::Economy),
("EconomY", ListStats::Economy),
("econ", ListStats::Economy),
// Food
("Food", ListStats::Food),
("fo", ListStats::Food),
("agr", ListStats::Food),
("Agri", ListStats::Food),
("Fod", ListStats::Food),
// Industry
("industry", ListStats::Industry),
("IndUs", ListStats::Industry),
("ind", ListStats::Industry),
// Science
("science", ListStats::Science),
("SCI", ListStats::Science),
("Sc", ListStats::Science),
// Trade
("trade", ListStats::Trade),
("TrD", ListStats::Trade),
("tr", ListStats::Trade),
// // Social
// ("social", ListStats::Social),
// ("soc", ListStats::Social),
// ("sl", ListStats::Social),
// // Culture
// ("culture", ListStats::Culture),
// ("CUL", ListStats::Culture),
// ("cl", ListStats::Culture),
// // Education
// ("education", ListStats::Education),
// ("edu", ListStats::Education),
// ("ed", ListStats::Education),
// // Tourism
// ("tourism", ListStats::Tourism),
// ("tour", ListStats::Tourism),
// ("tm", ListStats::Tourism),
// // Influence
// ("influence", ListStats::Influence),
// ("infl", ListStats::Influence),
// ("influ", ListStats::Influence),
// Military
("military", ListStats::Military),
("mil", ListStats::Military),
("mt", ListStats::Military),
// Army
("army", ListStats::Army),
("arm", ListStats::Army),
("ar", ListStats::Army),
// Strength
("strength", ListStats::Strength),
("str", ListStats::Strength),
("st", ListStats::Strength),
// Fortification
("fortification", ListStats::Fortification),
("fort", ListStats::Fortification),
("ft", ListStats::Fortification),
// Threat
("threat", ListStats::Threat),
("thr", ListStats::Threat),
("th", ListStats::Threat),
// Infrastructure
("infrastructure", ListStats::Infrastructure),
("infra", ListStats::Infrastructure),
("infr", ListStats::Infrastructure),
// Bureaucracy
("bureaucracy", ListStats::Bureaucracy),
("bureau", ListStats::Bureaucracy),
("bur", ListStats::Bureaucracy),
// Transportation
("transportation", ListStats::Transportation),
("trans", ListStats::Transportation),
("trns", ListStats::Transportation),
// Sprawl
("sprawl", ListStats::Sprawl),
("spr", ListStats::Sprawl),
("spra", ListStats::Sprawl),
// Health
("health", ListStats::Health),
("hlth", ListStats::Health),
("hlt", ListStats::Health),
];
let mut s = OverallStats::linear(33);
let mut output = String::new();
for (alias, expected_variant) in cases {
let val = alias.parse::<ListStats>().unwrap();
s.get_field_mut_from_str(val.into());
assert_eq!(
val, expected_variant,
"parsing `{}` should yield {:?}",
alias, expected_variant
);
output.push_str(&format!(
"{}:{}:{}:{}\n",
std::convert::Into::<&str>::into(val),
val.to_symbol(),
val.to_shortest(),
s.get_field(&val)
));
{
s.get_field_mut(&val);
}
}
assert_snapshot!(output);
}
#[test]
fn test_liststats_unknown_alias() {
// Pick a string that is not in the list of known aliases.
let unknown = "unknown_stat_123";
// Verify the error type and payload directly.
let err = unknown.parse::<ListStats>().unwrap_err();
match err {
EpochError::UnknownStatAcronim(msg) => {
assert_eq!(msg, unknown);
}
other => panic!("Expected UnknownStatAcronim, got {:?}", other),
}
}
#[test]
fn test_entity_type_to_shortest() {
let out = [
EntityType::Character,
EntityType::Player,
EntityType::Town,
EntityType::Monster,
EntityType::Blocker,
EntityType::Event,
]
.iter()
.map(|v| format!("{}:{}", v.to_symbol(), v.to_shortest()))
.collect::<Vec<String>>()
.join("\n");
assert_snapshot!(out);
}
// ---------------------------------------------------------------------------
// EntityType – already tested by your existing example
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// EffectApplication – one line per variant
// ---------------------------------------------------------------------------
#[test]
fn test_effect_application_to_symbol() {
let out = [
EffectApplication::Recurring,
EffectApplication::WhenPresent,
EffectApplication::PermanentEffectToApply,
EffectApplication::PermanentEffectApplied,
]
.iter()
.map(|v| format!("{}:{}", v.to_symbol(), v.to_shortest()))
.collect::<Vec<String>>()
.join("\n");
assert_snapshot!(out);
}
// ---------------------------------------------------------------------------
// Position – two variants, tested for both `to_symbol` and `to_shortest`
// ---------------------------------------------------------------------------
#[test]
fn test_position_to_symbol() {
let out = [Position(12, 34), Position(0, 0)]
.iter()
.map(|p| format!("{}{}", p.to_shortest(), p.to_symbol()))
.collect::<Vec<String>>()
.join("\n");
assert_snapshot!(out);
}
// ---------------------------------------------------------------------------
// EntityDuration – one line per variant
// ---------------------------------------------------------------------------
#[test]
fn test_entity_duration_to_symbol() {
let out = [
EntityDuration::Permanent,
EntityDuration::Duration(42),
EntityDuration::Done,
]
.map(|v| v.to_symbol())
.join("\n");
assert_snapshot!(out);
}