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