add test for find_morphism_path()
This commit is contained in:
parent
b835cddcf1
commit
42286bcadc
3 changed files with 73 additions and 4 deletions
|
@ -32,12 +32,10 @@ impl MorphismType {
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
|
||||||
|
|
||||||
impl<Morphism: Clone> MorphismBase<Morphism> {
|
impl<Morphism: Clone> MorphismBase<Morphism> {
|
||||||
pub fn new() -> Self {
|
pub fn new(list_typeid: TypeID) -> Self {
|
||||||
MorphismBase {
|
MorphismBase {
|
||||||
morphisms: Vec::new(),
|
morphisms: Vec::new(),
|
||||||
|
list_typeid
|
||||||
// FIXME: magic number
|
|
||||||
list_typeid: TypeID::Fun(10)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,4 +7,5 @@ pub mod pnf;
|
||||||
pub mod subtype;
|
pub mod subtype;
|
||||||
pub mod substitution;
|
pub mod substitution;
|
||||||
pub mod unification;
|
pub mod unification;
|
||||||
|
pub mod morphism;
|
||||||
|
|
||||||
|
|
70
src/test/morphism.rs
Normal file
70
src/test/morphism.rs
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
use {
|
||||||
|
crate::{dict::*, morphism::*}
|
||||||
|
};
|
||||||
|
|
||||||
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_morphism_path() {
|
||||||
|
let mut dict = TypeDict::new();
|
||||||
|
let mut base = MorphismBase::<u64>::new( dict.add_typename("Seq".into()) );
|
||||||
|
|
||||||
|
dict.add_varname("Radix".into());
|
||||||
|
dict.add_varname("SrcRadix".into());
|
||||||
|
dict.add_varname("DstRadix".into());
|
||||||
|
|
||||||
|
base.add_morphism(
|
||||||
|
MorphismType{
|
||||||
|
src_type: dict.parse("<Digit Radix> ~ Char").unwrap(),
|
||||||
|
dst_type: dict.parse("<Digit Radix> ~ ℤ_2^64 ~ machine.UInt64").unwrap()
|
||||||
|
},
|
||||||
|
11
|
||||||
|
);
|
||||||
|
base.add_morphism(
|
||||||
|
MorphismType{
|
||||||
|
src_type: dict.parse("<Digit Radix> ~ ℤ_2^64 ~ machine.UInt64").unwrap(),
|
||||||
|
dst_type: dict.parse("<Digit Radix> ~ Char").unwrap()
|
||||||
|
},
|
||||||
|
22
|
||||||
|
);
|
||||||
|
base.add_morphism(
|
||||||
|
MorphismType{
|
||||||
|
src_type: dict.parse("ℕ ~ <PosInt Radix BigEndian> ~ <Seq <Digit Radix>~ℤ_2^64~machine.UInt64>").unwrap(),
|
||||||
|
dst_type: dict.parse("ℕ ~ <PosInt Radix LittleEndian> ~ <Seq <Digit Radix>~ℤ_2^64~machine.UInt64>").unwrap()
|
||||||
|
},
|
||||||
|
333
|
||||||
|
);
|
||||||
|
base.add_morphism(
|
||||||
|
MorphismType{
|
||||||
|
src_type: dict.parse("ℕ ~ <PosInt Radix LittleEndian> ~ <Seq <Digit Radix>~ℤ_2^64~machine.UInt64>").unwrap(),
|
||||||
|
dst_type: dict.parse("ℕ ~ <PosInt Radix BigEndian> ~ <Seq <Digit Radix>~ℤ_2^64~machine.UInt64>").unwrap()
|
||||||
|
},
|
||||||
|
444
|
||||||
|
);
|
||||||
|
base.add_morphism(
|
||||||
|
MorphismType{
|
||||||
|
src_type: dict.parse("ℕ ~ <PosInt SrcRadix LittleEndian> ~ <Seq <Digit SrcRadix>~ℤ_2^64~machine.UInt64>").unwrap(),
|
||||||
|
dst_type: dict.parse("ℕ ~ <PosInt DstRadix LittleEndian> ~ <Seq <Digit DstRadix>~ℤ_2^64~machine.UInt64>").unwrap()
|
||||||
|
},
|
||||||
|
555
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
base.find_morphism_path(MorphismType {
|
||||||
|
src_type: dict.parse("ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10> ~ Char>").unwrap(),
|
||||||
|
dst_type: dict.parse("ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16> ~ Char>").unwrap()
|
||||||
|
}),
|
||||||
|
Some(
|
||||||
|
vec![
|
||||||
|
dict.parse("ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10> ~ Char>").unwrap().normalize(),
|
||||||
|
dict.parse("ℕ ~ <PosInt 10 BigEndian> ~ <Seq <Digit 10> ~ ℤ_2^64 ~ machine.UInt64>").unwrap().normalize(),
|
||||||
|
dict.parse("ℕ ~ <PosInt 10 LittleEndian> ~ <Seq <Digit 10> ~ ℤ_2^64 ~ machine.UInt64>").unwrap().normalize(),
|
||||||
|
dict.parse("ℕ ~ <PosInt 16 LittleEndian> ~ <Seq <Digit 16> ~ ℤ_2^64 ~ machine.UInt64>").unwrap().normalize(),
|
||||||
|
dict.parse("ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16> ~ ℤ_2^64 ~ machine.UInt64>").unwrap().normalize(),
|
||||||
|
dict.parse("ℕ ~ <PosInt 16 BigEndian> ~ <Seq <Digit 16> ~ Char>").unwrap().normalize(),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue