validator: rename AtLeastOneMatchingAndNoExtraCheck to SetDifferenceCheck

This commit is contained in:
Quaternions 2025-04-11 20:37:37 -07:00
parent 6efab4f411
commit ccf07c5931
Signed by: Quaternions
GPG Key ID: D0DF5964F79AC131

@ -169,7 +169,7 @@ pub fn get_model_info(dom:&rbx_dom_weak::WeakDom)->Result<ModelInfo,GetRootInsta
})
}
// check if an observed string matches and expected string
// check if an observed string matches an expected string
pub struct StringCheck<'a,T,Str>(Result<T,StringCheckContext<'a,Str>>);
pub struct StringCheckContext<'a,Str>{
observed:&'a str,
@ -219,13 +219,13 @@ impl<ID> DuplicateCheckContext<ID>{
}
}
// check that there is at least one
pub struct AtLeastOneMatchingAndNoExtraCheckContext<ID>{
// check that there is at least one matching item for each item in a reference set, and no extra items
pub struct SetDifferenceCheckContext<ID>{
extra:HashMap<ID,u64>,
missing:HashSet<ID>,
}
pub struct AtLeastOneMatchingAndNoExtraCheck<ID>(Result<(),AtLeastOneMatchingAndNoExtraCheckContext<ID>>);
impl<ID> AtLeastOneMatchingAndNoExtraCheckContext<ID>{
pub struct SetDifferenceCheck<ID>(Result<(),SetDifferenceCheckContext<ID>>);
impl<ID> SetDifferenceCheckContext<ID>{
fn new(initial_set:HashMap<ID,u64>)->Self{
Self{
extra:initial_set,
@ -233,8 +233,8 @@ impl<ID> AtLeastOneMatchingAndNoExtraCheckContext<ID>{
}
}
}
impl<ID:Copy+Eq+std::hash::Hash> AtLeastOneMatchingAndNoExtraCheckContext<ID>{
fn check<T>(self,reference_set:&HashMap<ID,T>)->AtLeastOneMatchingAndNoExtraCheck<ID>{
impl<ID:Copy+Eq+std::hash::Hash> SetDifferenceCheckContext<ID>{
fn check<T>(self,reference_set:&HashMap<ID,T>)->SetDifferenceCheck<ID>{
let Self{mut extra,mut missing}=self;
// remove correct entries
for (id,_) in reference_set{
@ -245,9 +245,9 @@ impl<ID:Copy+Eq+std::hash::Hash> AtLeastOneMatchingAndNoExtraCheckContext<ID>{
}
// if any entries remain, they are incorrect
if extra.is_empty()&&missing.is_empty(){
AtLeastOneMatchingAndNoExtraCheck(Ok(()))
SetDifferenceCheck(Ok(()))
}else{
AtLeastOneMatchingAndNoExtraCheck(Err(Self{extra,missing}))
SetDifferenceCheck(Err(Self{extra,missing}))
}
}
}
@ -281,7 +281,7 @@ pub struct MapCheck<'a>{
// No duplicate map starts (including bonuses)
mode_start_counts:DuplicateCheck<ModeID>,
// At least one finish zone for each start zone, and no finishes with no start
mode_finish_counts:AtLeastOneMatchingAndNoExtraCheck<ModeID>,
mode_finish_counts:SetDifferenceCheck<ModeID>,
// Spawn1 must exist
spawn1:Result<(),()>,
// No duplicate Spawn#
@ -341,7 +341,7 @@ impl<'a> ModelInfo<'a>{
};
// check that at least one end zone exists for each start zone.
let mode_finish_counts=AtLeastOneMatchingAndNoExtraCheckContext::new(self.counts.mode_finish_counts)
let mode_finish_counts=SetDifferenceCheckContext::new(self.counts.mode_finish_counts)
.check(&self.counts.mode_start_counts);
// there must be exactly one start zone for every mode in the map.
@ -380,7 +380,7 @@ impl<'a> MapCheck<'a>{
game_id:Ok(game_id),
mapstart:Ok(()),
mode_start_counts:DuplicateCheck(Ok(())),
mode_finish_counts:AtLeastOneMatchingAndNoExtraCheck(Ok(())),
mode_finish_counts:SetDifferenceCheck(Ok(())),
spawn1:Ok(()),
spawn_counts:DuplicateCheck(Ok(())),
wormhole_out_counts:DuplicateCheck(Ok(())),
@ -448,7 +448,7 @@ impl<'a> std::fmt::Display for MapCheck<'a>{
})?;
writeln!(f,"")?;
}
if let AtLeastOneMatchingAndNoExtraCheck(Err(context))=&self.mode_finish_counts{
if let SetDifferenceCheck(Err(context))=&self.mode_finish_counts{
// perhaps there are extra end zones (context.extra)
if !context.extra.is_empty(){
write!(f,"Extra finish zones with no matching start zone: ")?;