protected override void Check() { var c = new C(); var m = new Model(); m.AddRootComponents(c); m.Seal(); LtlFormula actual = c.State == C.States.A; var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new FieldExpression(c.Metadata.StateMachine.StateField), new EnumerationLiteralExpression(C.States.A))); Check(actual, expected); }
protected override void Check() { var expected = new StateFormula(new BooleanLiteralExpression(true)); CtlFormula f1 = true; var f2 = (CtlFormula)(true); var f3 = (CtlFormula)true; Check(_f1, expected); Check(_f2, expected); Check(_f3, expected); Check(F1, expected); Check(F2, expected); CheckArgumentConversion(true, expected); CheckArgumentConversion((CtlFormula)true, expected); }
protected override void Check() { var intValue = 7; { var actual = ((Formula)false).EquivalentTo(intValue < 7); var expected = new BinaryFormula( new StateFormula(() => false), BinaryOperator.Equivalence, new StateFormula(() => intValue < 7)); Check(actual, expected); } { var actual = ((Formula)false).EquivalentTo(F(intValue < 7)); var expected = new BinaryFormula( new StateFormula(() => false), BinaryOperator.Equivalence, new UnaryFormula(new StateFormula(() => intValue < 7), UnaryOperator.Finally)); Check(actual, expected); } { Formula actual = false.EquivalentTo(intValue < 7); var expected = new StateFormula(() => (false && intValue < 7) || (true && intValue >= 7)); Check(actual, expected); } { var actual = false.EquivalentTo(F(intValue < 7)); var expected = new BinaryFormula( new StateFormula(() => false), BinaryOperator.Equivalence, new UnaryFormula(new StateFormula(() => intValue < 7), UnaryOperator.Finally)); Check(actual, expected); } true.EquivalentTo(true).ShouldBe(true); false.EquivalentTo(true).ShouldBe(false); true.EquivalentTo(false).ShouldBe(false); false.EquivalentTo(false).ShouldBe(true); }
protected override void Check() { var intValue = 7; { var actual = ((Formula)false).Implies(intValue < 7); var expected = new BinaryFormula( new StateFormula(() => false), BinaryOperator.Implication, new StateFormula(() => intValue < 7)); Check(actual, expected); } { var actual = ((Formula)false).Implies(F(intValue < 7)); var expected = new BinaryFormula( new StateFormula(() => false), BinaryOperator.Implication, new UnaryFormula(new StateFormula(() => intValue < 7), UnaryOperator.Finally)); Check(actual, expected); } { var actual = false.Implies(intValue < 7); var expected = new StateFormula(() => !false || intValue < 7); Check(actual, expected); } { var actual = false.Implies(F(intValue < 7)); var expected = new BinaryFormula( new StateFormula(() => false), BinaryOperator.Implication, new UnaryFormula(new StateFormula(() => intValue < 7), UnaryOperator.Finally)); Check(actual, expected); } true.Implies(true).ShouldBe(true); false.Implies(true).ShouldBe(true); true.Implies(false).ShouldBe(false); false.Implies(false).ShouldBe(true); }
protected override void Check() { var c1 = new C1(); var c2 = new C2(); var m = new Model(); m.AddRootComponents(c1, c2); m.Seal(); var actual = (LtlFormula)(c1.F && +c1.C2.F != -c2.F); var expected = new StateFormula( new BinaryExpression(BinaryOperator.And, new FieldExpression(m.Metadata.RootComponent.Subcomponents[0].Fields[0]), new BinaryExpression(BinaryOperator.NotEquals, new FieldExpression(m.Metadata.RootComponent.Subcomponents[0].Subcomponents[0].Fields[0]), new UnaryExpression(UnaryOperator.Minus, new FieldExpression(m.Metadata.RootComponent.Subcomponents[1].Fields[0]))) )); Check(actual, expected); }
protected override void Check() { var expected = new StateFormula(new BooleanLiteralExpression(true)); LtlFormula f1 = true; var f2 = (LtlFormula)(true); var f3 = (LtlFormula)true; Check(_f1, expected); Check(_f2, expected); Check(_f3, expected); Check(F1, expected); Check(F2, expected); CheckArgumentConversion(true, expected); CheckArgumentConversion((LtlFormula)true, expected); CheckArgumentConversion(!(LtlFormula)true, new UnaryFormula(expected, UnaryFormulaOperator.Not, PathQuantifier.None)); CheckArgumentConversion(!Ltl.X(true), new UnaryFormula(new UnaryFormula(expected, UnaryFormulaOperator.Next, PathQuantifier.None), UnaryFormulaOperator.Not, PathQuantifier.None)); }
protected override void Check() { var intValue = 7; var enumValue = E.B; var expected = new StateFormula( new BinaryExpression(BinaryOperator.Or, new BinaryExpression(BinaryOperator.Equals, new EnumerationLiteralExpression(E.B), new EnumerationLiteralExpression(E.C)), new BinaryExpression(BinaryOperator.Equals, new BinaryExpression(BinaryOperator.Greater, new BinaryExpression(BinaryOperator.Multiply, new BinaryExpression(BinaryOperator.Divide, new IntegerLiteralExpression(7), new IntegerLiteralExpression(2)), new IntegerLiteralExpression(3)), new IntegerLiteralExpression(45)), new BooleanLiteralExpression(false)) )); { var actual = (CtlFormula)(enumValue == E.C || ((intValue / 2) * 3) > 45 == false); Check(actual, expected); } { var actual = (CtlFormula)(enumValue == E.C || ((intValue / 2) * 3) > 45 == false); Check(actual, expected); } { // ReSharper disable once JoinDeclarationAndInitializer CtlFormula actual; actual = enumValue == E.C || ((intValue / 2) * 3) > 45 == false; Check(actual, expected); } { CtlFormula actual = enumValue == E.C || ((intValue / 2) * 3) > 45 == false; Check(actual, expected); } }
protected override void Check() { var i = new int[1]; i[0] = 33; var c = new C[2]; c[0] = new C(); c[1] = new C(); var m = new Model(); m.AddRootComponents(c); m.Seal(); { CtlFormula actual = c[0].F == i[0]; var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new FieldExpression(c[0].Metadata.Fields[0]), new IntegerLiteralExpression(33))); Check(actual, expected); } { CtlFormula actual = c[0].State == c[1].State; var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new FieldExpression(c[0].Metadata.StateMachine.StateField), new FieldExpression(c[1].Metadata.StateMachine.StateField))); Check(actual, expected); } { var actual = Ctl.IsOccurring<C.Failure>(c[1]); var expected = new FaultOccurrenceFormula(c[1].Metadata.Faults[0]); Check(actual, expected); } }
protected override void Check() { var c = new C(); var m = new Model(); m.AddRootComponents(c); m.Seal(); { var actual = (CtlFormula)(0 == c.M(17) - 2); var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new IntegerLiteralExpression(0), new BinaryExpression(BinaryOperator.Subtract, new MethodInvocationExpression( m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[0], new ArgumentExpression(new IntegerLiteralExpression(17), RefKind.None)), new IntegerLiteralExpression(2)) )); Check(actual, expected); } { var actual = c.F; var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[1]), new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[2], new ArgumentExpression( new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[0], new ArgumentExpression(new IntegerLiteralExpression(33), RefKind.None)), RefKind.None), new ArgumentExpression(new BooleanLiteralExpression(true), RefKind.None)))); Check(actual, expected); } { var actual = ((CtlFormula)(0 == c.M(17) - 2)).Formula.InlineMethodInvocations(); var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new IntegerLiteralExpression(0), new BinaryExpression(BinaryOperator.Subtract, new BinaryExpression(BinaryOperator.Add, new IntegerLiteralExpression(17), new IntegerLiteralExpression(3)), new IntegerLiteralExpression(2)) )); Check(actual, expected); } { var actual = c.F.Formula.InlineMethodInvocations(); var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new UnaryExpression(UnaryOperator.Minus, new IntegerLiteralExpression(1)), new BinaryExpression(BinaryOperator.Multiply, new BinaryExpression(BinaryOperator.Add, new IntegerLiteralExpression(33), new IntegerLiteralExpression(3)), new IntegerLiteralExpression(7)))); Check(actual, expected); } }
protected override void Check() { { var actual = (LtlFormula)(_f + _f == 0); var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new BinaryExpression(BinaryOperator.Add, new IntegerLiteralExpression(_f), new IntegerLiteralExpression(_f)), new IntegerLiteralExpression(0))); Check(actual, expected); } { var actual = (LtlFormula)(_f - _f != 0); var expected = new StateFormula( new BinaryExpression(BinaryOperator.NotEquals, new BinaryExpression(BinaryOperator.Subtract, new IntegerLiteralExpression(_f), new IntegerLiteralExpression(_f)), new IntegerLiteralExpression(0))); Check(actual, expected); } { var actual = (LtlFormula)(_f / _f > 0); var expected = new StateFormula( new BinaryExpression(BinaryOperator.Greater, new BinaryExpression(BinaryOperator.Divide, new IntegerLiteralExpression(_f), new IntegerLiteralExpression(_f)), new IntegerLiteralExpression(0))); Check(actual, expected); } { var actual = (LtlFormula)(_f * _f >= 0); var expected = new StateFormula( new BinaryExpression(BinaryOperator.GreaterEqual, new BinaryExpression(BinaryOperator.Multiply, new IntegerLiteralExpression(_f), new IntegerLiteralExpression(_f)), new IntegerLiteralExpression(0))); Check(actual, expected); } { var actual = (LtlFormula)(_f % _f < 0); var expected = new StateFormula( new BinaryExpression(BinaryOperator.Less, new BinaryExpression(BinaryOperator.Modulo, new IntegerLiteralExpression(_f), new IntegerLiteralExpression(_f)), new IntegerLiteralExpression(0))); Check(actual, expected); } { var actual = (LtlFormula)(_f % _f <= 0); var expected = new StateFormula( new BinaryExpression(BinaryOperator.LessEqual, new BinaryExpression(BinaryOperator.Modulo, new IntegerLiteralExpression(_f), new IntegerLiteralExpression(_f)), new IntegerLiteralExpression(0))); Check(actual, expected); } { var actual = (LtlFormula)(_g && true); var expected = new StateFormula( new BinaryExpression(BinaryOperator.And, new BooleanLiteralExpression(_g), new BooleanLiteralExpression(true))); Check(actual, expected); } { var actual = (LtlFormula)(_g & true); var expected = new StateFormula( new BinaryExpression(BinaryOperator.And, new BooleanLiteralExpression(_g), new BooleanLiteralExpression(true))); Check(actual, expected); } { var actual = (LtlFormula)(_g || true); var expected = new StateFormula( new BinaryExpression(BinaryOperator.Or, new BooleanLiteralExpression(_g), new BooleanLiteralExpression(true))); Check(actual, expected); } { var actual = (LtlFormula)(_g | true); var expected = new StateFormula( new BinaryExpression(BinaryOperator.Or, new BooleanLiteralExpression(_g), new BooleanLiteralExpression(true))); Check(actual, expected); } }
protected override void Check() { var c1 = new C1(); var c2 = new C2(); var m = new Model(); m.AddRootComponents(c1, c2); m.Seal(); { var actual = (LtlFormula)(0 == c1.M(17) - 2); var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new IntegerLiteralExpression(0), new BinaryExpression(BinaryOperator.Subtract, new MethodInvocationExpression( m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[1], new ArgumentExpression(new IntegerLiteralExpression(17), RefKind.None)), new IntegerLiteralExpression(2)) )); Check(actual, expected); } { var actual = c1.F; var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[2]), new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[3], new ArgumentExpression(new IntegerLiteralExpression(1), RefKind.None), new ArgumentExpression(new BooleanLiteralExpression(true), RefKind.None)))); Check(actual, expected); } { var actual = (LtlFormula)(c2.M3()); var expected = new StateFormula(new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[1].ProvidedPorts[6])); Check(actual, expected); } { var ic = c2; var actual = (LtlFormula)(ic.M3()); var expected = new StateFormula(new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[1].ProvidedPorts[6])); Check(actual, expected); } { var ic = c2; var actual = ((LtlFormula)(ic.M3())).Formula.InlineMethodInvocations(); var expected = new StateFormula(new BooleanLiteralExpression(false)); Check(actual, expected); } { var actual = (LtlFormula)(c2.M(1) == 1); var expected = new StateFormula( new BinaryExpression(BinaryOperator.Equals, new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[1].ProvidedPorts[5], new ArgumentExpression(new IntegerLiteralExpression(1), RefKind.None)), new IntegerLiteralExpression(1))); Check(actual, expected); } Tests.Raises<InvalidOperationException>(() => ((LtlFormula)(c2.M4(111) == 81)).Formula.InlineMethodInvocations()); }