Relocate all files into separate module

This commit is contained in:
elvis
2025-08-17 01:25:35 +02:00
parent 4816c8af25
commit c27610877d
7 changed files with 209 additions and 215 deletions

View File

@ -1,6 +1,10 @@
// If changing IntegerType in assert.rs, also change from Num to another
// similar parser with different return type in grammar.lalrpop in
// AssertExpression
use std::collections::HashMap;
use super::super::{structure, translator, graph};
/// If changing IntegerType in assert.rs, also change from Num to another
/// similar parser with different return type in grammar.lalrpop in
/// AssertExpression
type IntegerType = i64;
#[derive(Debug, Clone)]
@ -24,16 +28,15 @@ pub enum Variable<S> {
Special(S)
}
trait SpecialVariables<G>: Display + std::fmt::Debug + Sized + Eq + Copy
+ std::hash::Hash
/// Trait needed for special variables.
trait SpecialVariables<G>: std::fmt::Display + std::fmt::Debug + Sized + Eq
+ Copy + std::hash::Hash
{
fn type_of(&self) -> AssertionTypes;
fn type_qualified(&self, q: &Qualifier) -> Result<AssertionTypes, String>;
fn new_context(input: HashMap<Self, G>)
-> HashMap<Self, AssertReturnValue>;
fn correct_type(&self, other: &AssertReturnValue) -> bool;
// fn correct_type_qualified(&self, q: &Qualifier, other: &AssertReturnValue)
// -> bool;
}
#[derive(Debug, Clone)]
@ -41,9 +44,9 @@ pub enum Expression<S> {
True,
False,
Integer(IntegerType),
Label(Box<super::structure::RSlabel>),
Set(super::structure::RSset),
Element(super::translator::IdType),
Label(Box<structure::RSlabel>),
Set(structure::RSset),
Element(translator::IdType),
String(String),
Var(Variable<S>),
@ -153,35 +156,16 @@ pub enum AssertReturnValue {
Boolean(bool),
Integer(IntegerType),
String(String),
Label(super::structure::RSlabel),
Set(super::structure::RSset),
Element(super::translator::IdType),
Label(structure::RSlabel),
Set(structure::RSset),
Element(translator::IdType),
Node(petgraph::graph::NodeIndex),
Edge(petgraph::graph::EdgeIndex),
Neighbours(petgraph::graph::NodeIndex),
System(super::structure::RSsystem),
Context(super::structure::RSprocess),
System(structure::RSsystem),
Context(structure::RSprocess),
}
impl AssertReturnValue {
pub fn assign_qualified(&mut self, q: Qualifier, val: AssertReturnValue)
-> Result<(), String> {
match (self, q, val) {
(Self::Label(l),
Qualifier::Restricted(q),
AssertReturnValue::Set(set)) => {
*q.referenced_mut(l) = set;
Ok(())
},
(s, q, val) => {
Err(format!("Cannot assign {val} to {s} with qualifier {q}"))
}
}
}
}
// -----------------------------------------------------------------------------
// Implementations for types
// -----------------------------------------------------------------------------
@ -189,8 +173,8 @@ impl AssertReturnValue {
impl QualifierRestricted {
pub(super) fn referenced_mut<'a>(
&self,
label: &'a mut super::structure::RSlabel,
) -> &'a mut super::structure::RSset {
label: &'a mut structure::RSlabel,
) -> &'a mut structure::RSset {
match self {
Self::Entities => {&mut label.available_entities},
Self::Context => {&mut label.context},
@ -204,8 +188,8 @@ impl QualifierRestricted {
pub(super) fn referenced<'a>(
&self,
label: &'a super::structure::RSlabel,
) -> &'a super::structure::RSset {
label: &'a structure::RSlabel,
) -> &'a structure::RSset {
match self {
Self::Entities => {&label.available_entities},
Self::Context => {&label.context},
@ -219,7 +203,7 @@ impl QualifierRestricted {
pub(super) fn get(
&self,
label: &super::structure::RSlabel,
label: &structure::RSlabel,
) -> AssertReturnValue {
AssertReturnValue::Set(self.referenced(label).clone())
}
@ -228,7 +212,7 @@ impl QualifierRestricted {
impl QualifierLabel {
pub(super) fn get(
&self,
l: &super::structure::RSlabel,
l: &structure::RSlabel,
) -> AssertReturnValue {
match self {
QualifierLabel::AvailableEntities => {
@ -248,7 +232,7 @@ impl QualifierLabel {
impl QualifierSystem {
pub(super) fn get(
&self,
l: &super::structure::RSsystem,
l: &structure::RSsystem,
) -> AssertReturnValue {
match self {
Self::Context => {
@ -484,13 +468,28 @@ impl Binary {
}
}
impl AssertReturnValue {
pub fn assign_qualified(&mut self, q: Qualifier, val: AssertReturnValue)
-> Result<(), String> {
match (self, q, val) {
(Self::Label(l),
Qualifier::Restricted(q),
AssertReturnValue::Set(set)) => {
*q.referenced_mut(l) = set;
Ok(())
},
(s, q, val) => {
Err(format!("Cannot assign {val} to {s} with qualifier {q}"))
}
}
}
}
// -----------------------------------------------------------------------------
use std::collections::HashMap;
use std::fmt::{self, Display};
use petgraph::visit::EdgeRef;
// Typechecking and Evaluation
// -----------------------------------------------------------------------------
struct TypeContext {
data: HashMap<String, AssertionTypes>,
@ -728,8 +727,8 @@ impl AssertReturnValue {
fn unary(
self,
u: &Unary,
translator: &mut super::translator::Translator,
graph: &super::graph::RSgraph,
translator: &mut translator::Translator,
graph: &graph::RSgraph,
) -> Result<AssertReturnValue, String> {
match (self, u) {
(AssertReturnValue::Boolean(b), Unary::Not) => {
@ -804,7 +803,7 @@ impl AssertReturnValue {
self,
b: &Binary,
other: AssertReturnValue,
_translator: &mut super::translator::Translator
_translator: &mut translator::Translator
) -> Result<AssertReturnValue, String> {
use AssertReturnValue::*;
Ok(match (b, self, other) {
@ -1002,8 +1001,8 @@ where S: SpecialVariables<G> {
fn execute<S, G>(
tree: &Tree<S>,
c: &mut Context<S>,
translator: &mut super::translator::Translator,
graph: &super::graph::RSgraph,
translator: &mut translator::Translator,
graph: &graph::RSgraph,
) -> Result<Option<AssertReturnValue>, String>
where S: SpecialVariables<G> {
match tree {
@ -1056,10 +1055,12 @@ type RangeIterator = std::vec::IntoIter<AssertReturnValue>;
fn range_into_iter<S, G>(
range: &Range<S>,
c: &mut Context<S>,
translator: &mut super::translator::Translator,
graph: &super::graph::RSgraph,
translator: &mut translator::Translator,
graph: &graph::RSgraph,
) -> Result<RangeIterator, String>
where S: SpecialVariables<G> {
use petgraph::visit::EdgeRef;
match range {
Range::IterateOverSet(exp) => {
let val = execute_exp(exp, c, translator, graph)?;
@ -1100,8 +1101,8 @@ where S: SpecialVariables<G> {
fn execute_exp<S, G>(
exp: &Expression<S>,
c: &Context<S>,
translator: &mut super::translator::Translator,
graph: &super::graph::RSgraph,
translator: &mut translator::Translator,
graph: &graph::RSgraph,
) -> Result<AssertReturnValue, String>
where S: SpecialVariables<G> {
match exp {
@ -1143,7 +1144,7 @@ pub enum EdgeRelablerInput {
#[derive(Debug, Clone)]
pub enum EdgeRelablerInputValues {
Label(super::structure::RSlabel),
Label(structure::RSlabel),
Edge(petgraph::graph::EdgeIndex),
}
@ -1184,20 +1185,10 @@ impl SpecialVariables<EdgeRelablerInputValues> for EdgeRelablerInput {
(_, _) => false
}
}
// fn correct_type_qualified(&self, q: &Qualifier, other: &AssertReturnValue)
// -> bool {
// match (self, q, other) {
// (Self::Label, Qualifier::Label(_), AssertReturnValue::Set(_)) |
// (Self::Label, Qualifier::Restricted(_), AssertReturnValue::Set(_))
// => true,
// (_, _, _) => false
// }
// }
}
impl Display for EdgeRelablerInput {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl std::fmt::Display for EdgeRelablerInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Label => write!(f, "label"),
Self::Edge => write!(f, "edge"),
@ -1206,9 +1197,6 @@ impl Display for EdgeRelablerInput {
}
impl RSassert<EdgeRelablerInput> {
pub fn typecheck(&self) -> Result<(), String> {
let mut context = TypeContext::new();
@ -1236,9 +1224,9 @@ impl RSassert<EdgeRelablerInput> {
pub fn execute(
&self,
graph: &super::graph::RSgraph,
edge: &<super::graph::RSgraph as petgraph::visit::GraphBase>::EdgeId,
translator: &mut super::translator::Translator,
graph: &graph::RSgraph,
edge: &<graph::RSgraph as petgraph::visit::GraphBase>::EdgeId,
translator: &mut translator::Translator,
) -> Result<AssertReturnValue, String> {
let label = graph.edge_weight(*edge).unwrap();
@ -1257,6 +1245,4 @@ impl RSassert<EdgeRelablerInput> {
}
}
include!("assert_fmt.rs");
include!("assert_tests.rs");
include!("fmt.rs");

View File

@ -1,14 +1,15 @@
// -----------------------------------------------------------------------------
// Display Implementation for all types
// -----------------------------------------------------------------------------
use std::fmt;
impl<S> fmt::Display for RSassert<S> where S: Display {
impl<S> fmt::Display for RSassert<S> where S: fmt::Display {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "label {{\n{}\n}}", self.tree)
}
}
impl<S> fmt::Display for Tree<S> where S: Display {
impl<S> fmt::Display for Tree<S> where S: fmt::Display {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Concat(t1, t2) => {write!(f, "{t1};\n{t2}")},
@ -29,7 +30,7 @@ impl<S> fmt::Display for Tree<S> where S: Display {
}
}
impl<S> fmt::Display for Variable<S> where S: Display {
impl<S> fmt::Display for Variable<S> where S: fmt::Display {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Special(s) => {write!(f, "{s}")},
@ -38,7 +39,7 @@ impl<S> fmt::Display for Variable<S> where S: Display {
}
}
impl<S> fmt::Display for Expression<S> where S: Display {
impl<S> fmt::Display for Expression<S> where S: fmt::Display {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::True => {write!(f, "True")},
@ -73,7 +74,7 @@ impl<S> fmt::Display for Expression<S> where S: Display {
}
}
impl<S> fmt::Display for Range<S> where S: Display {
impl<S> fmt::Display for Range<S> where S: fmt::Display {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::IterateOverSet(exp) => {write!(f, "{{{exp}}}")},

View File

@ -0,0 +1,4 @@
pub mod dsl;
#[cfg(test)]
mod tests;

View File

@ -2,30 +2,33 @@
// Testing
// -----------------------------------------------------------------------------
use super::dsl::*;
use super::super::{translator, structure};
#[test]
fn assert_tycheck_true() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {tree: Tree::Return(Box::new(Expression::True))};
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}
#[test]
fn assert_tycheck_concat_1() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -39,21 +42,21 @@ fn assert_tycheck_concat_1() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}
#[test]
fn assert_tycheck_concat_2() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -67,21 +70,21 @@ fn assert_tycheck_concat_2() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}
#[test]
fn assert_tycheck_return_1() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -92,14 +95,14 @@ fn assert_tycheck_return_1() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}
@ -136,8 +139,8 @@ fn assert_tycheck_return_incompatible_2() {
#[test]
fn assert_tycheck_return_2() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -157,22 +160,22 @@ fn assert_tycheck_return_2() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}
#[test]
fn assert_tycheck_return_3() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -192,21 +195,21 @@ fn assert_tycheck_return_3() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(false))));
}
#[test]
fn assert_tycheck_if_1() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -228,21 +231,21 @@ fn assert_tycheck_if_1() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}
#[test]
fn assert_tycheck_if_2() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -263,21 +266,21 @@ fn assert_tycheck_if_2() {
};
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(false))));
}
#[test]
fn assert_tycheck_if_3() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -299,14 +302,14 @@ fn assert_tycheck_if_3() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}
@ -334,8 +337,8 @@ fn assert_tycheck_if_4() {
#[test]
fn assert_tycheck_if_else_1() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -360,21 +363,21 @@ fn assert_tycheck_if_else_1() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}
#[test]
fn assert_tycheck_if_else_2() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -399,14 +402,14 @@ fn assert_tycheck_if_else_2() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(false))));
}
@ -474,8 +477,8 @@ fn assert_tycheck_assignment_1() {
#[test]
fn assert_tycheck_assignment_2() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -498,21 +501,21 @@ fn assert_tycheck_assignment_2() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}
#[test]
fn assert_tycheck_assignment_3() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -537,14 +540,14 @@ fn assert_tycheck_assignment_3() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(false))));
}
@ -575,8 +578,8 @@ fn assert_tycheck_assignment_4() {
#[test]
fn assert_tycheck_assignment_5() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -602,21 +605,21 @@ fn assert_tycheck_assignment_5() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Integer(10))));
}
#[test]
fn assert_tycheck_assignment_6() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -649,21 +652,21 @@ fn assert_tycheck_assignment_6() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Integer(10))));
}
#[test]
fn assert_tycheck_assignment_7() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -694,21 +697,21 @@ fn assert_tycheck_assignment_7() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}
#[test]
fn assert_tycheck_assignment_8() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -743,21 +746,21 @@ fn assert_tycheck_assignment_8() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Integer(10))));
}
#[test]
fn assert_tycheck_assignment_9() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -790,21 +793,21 @@ fn assert_tycheck_assignment_9() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Integer(10))));
}
#[test]
fn assert_tycheck_assignment_10() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -839,22 +842,22 @@ fn assert_tycheck_assignment_10() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Integer(10))));
}
#[test]
fn assert_tycheck_for_1() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel, RSset};
use translator::Translator;
use structure::{RSsystem, RSlabel, RSset};
let tree = RSassert {
tree: Tree::Concat(
@ -888,21 +891,21 @@ fn assert_tycheck_for_1() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(tree.execute(&graph, &edge, &mut translator).is_err());
assert!(tree.execute(&graph, &edge, &mut tr).is_err());
}
#[test]
fn assert_tycheck_for_2() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel, RSset};
use translator::Translator;
use structure::{RSsystem, RSlabel, RSset};
let tree = RSassert {
tree: Tree::Concat(
@ -938,23 +941,23 @@ fn assert_tycheck_for_2() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
translator.encode("one");
translator.encode("two");
let mut tr = Translator::new();
tr.encode("one");
tr.encode("two");
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Set(_))));
}
#[test]
fn assert_tycheck_for_3() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel, RSset};
use translator::Translator;
use structure::{RSsystem, RSlabel, RSset};
let tree = RSassert {
tree: Tree::Concat(
@ -1004,23 +1007,23 @@ fn assert_tycheck_for_3() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
translator.encode("one");
translator.encode("two");
let mut tr = Translator::new();
tr.encode("one");
tr.encode("two");
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Set(_))));
}
#[test]
fn assert_tycheck_for_4() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel, RSset};
use translator::Translator;
use structure::{RSsystem, RSlabel, RSset};
let tree = RSassert {
tree: Tree::Concat(
@ -1070,24 +1073,24 @@ fn assert_tycheck_for_4() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
translator.encode("one");
translator.encode("two");
translator.encode("three");
let mut tr = Translator::new();
tr.encode("one");
tr.encode("two");
tr.encode("three");
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Element(_))));
}
#[test]
fn assert_tycheck_for_5() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel, RSset};
use translator::Translator;
use structure::{RSsystem, RSlabel, RSset};
let tree = RSassert {
tree: Tree::Concat(
@ -1150,24 +1153,24 @@ fn assert_tycheck_for_5() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
translator.encode("one");
translator.encode("two");
translator.encode("three");
let mut tr = Translator::new();
tr.encode("one");
tr.encode("two");
tr.encode("three");
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Integer(3))));
}
#[test]
fn assert_tycheck_for_6() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel, RSset};
use translator::Translator;
use structure::{RSsystem, RSlabel, RSset};
let tree = RSassert {
tree: Tree::Concat(
@ -1240,10 +1243,10 @@ fn assert_tycheck_for_6() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
translator.encode("one");
translator.encode("two");
translator.encode("three");
let mut tr = Translator::new();
tr.encode("one");
tr.encode("two");
tr.encode("three");
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
@ -1251,14 +1254,14 @@ fn assert_tycheck_for_6() {
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Integer(2))));
}
#[test]
fn assert_tycheck_for_7() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -1295,7 +1298,7 @@ fn assert_tycheck_for_7() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
@ -1303,14 +1306,14 @@ fn assert_tycheck_for_7() {
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Integer(0))));
}
#[test]
fn assert_tycheck_for_8() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel};
use translator::Translator;
use structure::{RSsystem, RSlabel};
let tree = RSassert {
tree: Tree::Concat(
@ -1361,18 +1364,18 @@ fn assert_tycheck_for_8() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
let node_2 = graph.add_node(RSsystem::new());
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Integer(1))));
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
@ -1381,14 +1384,14 @@ fn assert_tycheck_for_8() {
let node_3 = graph.add_node(RSsystem::new());
graph.add_edge(node_1, node_3, RSlabel::new());
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Integer(2))));
}
#[test]
fn assert_tycheck_system() {
use super::translator::Translator;
use super::structure::{RSsystem, RSlabel, RSset, RSenvironment, RSprocess};
use translator::Translator;
use structure::{RSsystem, RSlabel, RSset, RSenvironment, RSprocess};
use std::rc::Rc;
let tree = RSassert {
@ -1425,7 +1428,7 @@ fn assert_tycheck_system() {
assert!(tree.typecheck().is_ok());
let mut translator = Translator::new();
let mut tr = Translator::new();
let mut graph = petgraph::Graph::new();
let node_1 = graph.add_node(RSsystem::new());
@ -1439,8 +1442,8 @@ fn assert_tycheck_system() {
);
let edge = graph.add_edge(node_1, node_2, RSlabel::new());
println!("{:?}", tree.execute(&graph, &edge, &mut translator));
println!("{:?}", tree.execute(&graph, &edge, &mut tr));
assert!(matches!(tree.execute(&graph, &edge, &mut translator),
assert!(matches!(tree.execute(&graph, &edge, &mut tr),
Ok(AssertReturnValue::Boolean(true))));
}

View File

@ -130,7 +130,7 @@ where
&self,
edge_map: &super::structure::RSassert,
translator: &mut super::translator::Translator
) -> Result<Graph<RSsystem, super::assert::AssertReturnValue, Ty, Ix>, String>;
) -> Result<Graph<RSsystem, super::structure::assert::AssertReturnValue, Ty, Ix>, String>;
}
impl<'a> MapEdges<'a, RSsystem, RSlabel, Directed, u32>
@ -140,7 +140,7 @@ impl<'a> MapEdges<'a, RSsystem, RSlabel, Directed, u32>
&self,
edge_map: &super::structure::RSassert,
translator: &mut super::translator::Translator
)-> Result<Graph<RSsystem, super::assert::AssertReturnValue, Directed, u32>, String> {
)-> Result<Graph<RSsystem, super::structure::assert::AssertReturnValue, Directed, u32>, String> {
use petgraph::graph::EdgeIndex;
let mut g = Graph::with_capacity(self.node_count(), self.edge_count());

View File

@ -503,7 +503,7 @@ pub fn bisimilar(
system_b: String
) -> Result<String, String>
{
use super::assert::AssertReturnValue;
use super::structure::assert::AssertReturnValue;
let system_b = read_file(system_a.get_translator(),
system_b.to_string(),

View File

@ -620,11 +620,11 @@ impl Hash for RSlabel {
// -----------------------------------------------------------------------------
pub type RSassert =
crate::rsprocess::assert::RSassert<
crate::rsprocess::assert::EdgeRelablerInput>;
crate::rsprocess::assert::dsl::RSassert<
crate::rsprocess::assert::dsl::EdgeRelablerInput>;
pub mod assert {
pub use crate::rsprocess::assert::*;
pub use crate::rsprocess::assert::dsl::*;
}