From a52f38dadf6036e981460a72c06fc4823f05d535 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 4 Aug 2024 23:47:59 +0200 Subject: [PATCH] add test for find_morphism_path() --- src/morphism.rs | 6 ++-- src/test/mod.rs | 1 + src/test/morphism.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 src/test/morphism.rs diff --git a/src/morphism.rs b/src/morphism.rs index 31a8e31..6b921bf 100644 --- a/src/morphism.rs +++ b/src/morphism.rs @@ -32,12 +32,10 @@ impl MorphismType { //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\ impl MorphismBase { - pub fn new() -> Self { + pub fn new(list_typeid: TypeID) -> Self { MorphismBase { morphisms: Vec::new(), - - // FIXME: magic number - list_typeid: TypeID::Fun(10) + list_typeid } } diff --git a/src/test/mod.rs b/src/test/mod.rs index d116412..bfc9ebd 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -6,4 +6,5 @@ pub mod lnf; pub mod subtype; pub mod substitution; pub mod unification; +pub mod morphism; diff --git a/src/test/morphism.rs b/src/test/morphism.rs new file mode 100644 index 0000000..29eb5c7 --- /dev/null +++ b/src/test/morphism.rs @@ -0,0 +1,73 @@ +use { + crate::{dict::*, morphism::*} +}; + +//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\ + +#[test] +fn test_morphism_path() { + let mut dict = TypeDict::new(); + let mut base = MorphismBase::::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(" ~ Char").unwrap(), + dst_type: dict.parse(" ~ ℤ_2^64 ~ machine.UInt64").unwrap() + }, + 11 + ); + base.add_morphism( + MorphismType{ + src_type: dict.parse(" ~ ℤ_2^64 ~ machine.UInt64").unwrap(), + dst_type: dict.parse(" ~ Char").unwrap() + }, + 22 + ); + base.add_morphism( + MorphismType{ + src_type: dict.parse("ℕ ~ ~ ~ℤ_2^64~machine.UInt64>").unwrap(), + dst_type: dict.parse("ℕ ~ ~ ~ℤ_2^64~machine.UInt64>").unwrap() + }, + 333 + ); + base.add_morphism( + MorphismType{ + src_type: dict.parse("ℕ ~ ~ ~ℤ_2^64~machine.UInt64>").unwrap(), + dst_type: dict.parse("ℕ ~ ~ ~ℤ_2^64~machine.UInt64>").unwrap() + }, + 444 + ); + base.add_morphism( + MorphismType{ + src_type: dict.parse("ℕ ~ ~ ~ℤ_2^64~machine.UInt64>").unwrap(), + dst_type: dict.parse("ℕ ~ ~ ~ℤ_2^64~machine.UInt64>").unwrap() + }, + 555 + ); + + + let path = base.find_morphism_path(MorphismType { + src_type: dict.parse("ℕ ~ ~ ~ Char>").unwrap(), + dst_type: dict.parse("ℕ ~ ~ ~ Char>").unwrap() + }); + + assert_eq!( + path, + + Some( + vec![ + dict.parse("ℕ ~ ~ ~ Char>").unwrap().normalize(), + dict.parse("ℕ ~ ~ ~ ℤ_2^64 ~ machine.UInt64>").unwrap().normalize(), + dict.parse("ℕ ~ ~ ~ ℤ_2^64 ~ machine.UInt64>").unwrap().normalize(), + dict.parse("ℕ ~ ~ ~ ℤ_2^64 ~ machine.UInt64>").unwrap().normalize(), + dict.parse("ℕ ~ ~ ~ ℤ_2^64 ~ machine.UInt64>").unwrap().normalize(), + dict.parse("ℕ ~ ~ ~ Char>").unwrap().normalize(), + ] + ) + ); +} +