Example #1
0
		/// <summary>
		///     Initializes a new instance.
		/// </summary>
		/// <param name="model">The model that should be simulated.</param>
		public Simulator(Model model)
		{
			Requires.NotNull(model, () => model);

			_model = model;
			_model.Seal();
		}
Example #2
0
		protected override void Check()
		{
			var c = new C1();
			var m = new Model();
			m.AddRootComponent(c);
			m.Seal();

			m.Metadata.RootComponent.Subcomponents.ShouldBe(new[] { c.Metadata });
			m.Metadata.Components.ShouldBe(new[] { m.Metadata.RootComponent, c.Metadata });
			m.Metadata.RootComponent.Subcomponents[0].Name.ShouldBe("c");

			m.Seal(); // Second call should have no effect

			m.Metadata.RootComponent.Subcomponents.ShouldBe(new[] { c.Metadata });
			m.Metadata.Components.ShouldBe(new[] { m.Metadata.RootComponent, c.Metadata });
		}
Example #3
0
		protected override void Check()
		{
			var c = new C9();
			var m = new Model();
			m.AddRootComponents(c);

			Tests.RaisesWith<InvalidHierarchyStructureException>(() => m.Seal(), e => e.Component.ShouldBe(c.Metadata));
		}
		protected override void Check()
		{
			var m = new Model();
			m.AddRootComponents(new C(1, 2, 3));
			m.Seal();

			m.Metadata.RootComponent.Subcomponents[0].Fields[0].InitialValues.ShouldBe(new object[] { 1, 2, 3 });
		}
Example #5
0
		protected override void Check()
		{
			var m = new Model();
			m.AddRootComponent(new C2());

			Tests.RaisesWith<UnboundRequiredPortException>(() => m.Seal(),
				e => e.RequiredPort.ShouldBe(m.Metadata.RootComponent.Subcomponents[0].Subcomponents[1].RequiredPorts[0]));
		}
		protected override void Check()
		{
			var m = new Model();
			m.Seal();

			Tests.RaisesWith<MetadataException>(() => AddRootComponent(m, new X()), e => e.Object.ShouldBe(m));
			Tests.RaisesWith<MetadataException>(() => AddRootComponents(m, new X()), e => e.Object.ShouldBe(m));
		}
		protected override void Check()
		{
			var x = new X();
			var m = new Model();
			m.Seal();

			Tests.RaisesWith<MetadataException>(() => Bind(m, x), e => e.Object.ShouldBe(m));
		}
Example #8
0
		protected override void Check()
		{
			var z = new Z();
			var m = new Model();
			m.AddRootComponents(new X(z), new Y(z));

			Tests.RaisesWith<InvalidBindingException>(() => m.Seal(),
				e => e.Binding.ShouldBe(m.Metadata.RootComponent.Subcomponents[1].Bindings[0]));
		}
		protected override void Check()
		{
			var c = new C4();
			var m = new Model();
			m.AddRootComponent(c);
			m.Bind(c.RequiredPorts.M = c.ProvidedPorts.A);

			Tests.RaisesWith<AmbiguousBindingsException>(() => m.Seal(),
				e => e.RequiredPort.ShouldBe(m.Metadata.RootComponent.Subcomponents[0].RequiredPorts[0]));
		}
Example #10
0
		protected override void Check()
		{
			var x = new X();
			var y = new Y();
			var m = new Model();

			m.AddRootComponents(x, y);
			m.Bind(y.RequiredPorts.M = x.ProvidedPorts.N);
			m.Seal();

			m.Metadata.Bindings.Length.ShouldBe(1);
		}
Example #11
0
		protected override void Check()
		{
			var c1 = new C1();
			var c2 = new C2();
			var m = new Model();
			m.AddRootComponents(c1);
			m.Seal();

			//{
			//	var actual = (CtlFormula)(!c1.M == false);
			//	var expected = new StateFormula(
			//		new BinaryExpression(BinaryOperator.Equals,
			//			new UnaryExpression(UnaryOperator.Not,
			//				new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[0])),
			//			new BooleanLiteralExpression(false)));

			//	// TODO: Support properties
			//	//Check(actual, expected);
			//}

			//{
			//	var actual = (CtlFormula)(c1.M2);
			//	var expected = new StateFormula(new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[1]));

			//	// TODO: Support properties
			//	//Check(actual, expected);
			//}

			//{
			//	var actual = (CtlFormula)(c2.M2);
			//	var expected = new StateFormula(new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[3]));

			//	// TODO: Support properties
			//	//Check(actual, expected);
			//}

			//{
			//	var ic = c2;
			//	var actual = (CtlFormula)(ic.M2);
			//	var expected = new StateFormula(new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[3]));

			//	// TODO: Support properties
			//	//Check(actual, expected);
			//}

			//{
			//	var actual = (CtlFormula)(c2.M);
			//	var expected = new StateFormula(new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[2]));

			//	// TODO: Support properties
			//	//Check(actual, expected);
			//}
		}
Example #12
0
		protected override void Check()
		{
			var x1 = new X1();
			var x2 = new X2();
			var m = new Model();

			m.AddRootComponents(new X3(x1, x2));
			m.Bind(x1.RequiredPorts.M = x2.ProvidedPorts.M);
			m.Seal();

			m.Metadata.Bindings.Length.ShouldBe(1);
		}
Example #13
0
		protected override void Check()
		{
			var x1 = new X1();
			var x2 = new X2();
			var m = new Model();

			m.AddRootComponents(new X3(x1, x2));
			m.Bind(x1.RequiredPorts.M = x2.ProvidedPorts.M);
			m.Seal();

			m.Metadata.Bindings[0].DeclaringComponent.ShouldBe(m.Metadata.RootComponent);
			m.Metadata.Bindings[0].ProvidedPort.ShouldBe(x2.Metadata.ProvidedPorts[0]);
			m.Metadata.Bindings[0].RequiredPort.ShouldBe(x1.Metadata.RequiredPorts[0]);
		}
		protected override void Check()
		{
			var c1 = new C5();
			var c2 = new C6();
			var c3 = new C6();
			var m = new Model();

			m.AddRootComponents(c2, c1, c3);
			m.Bind(c1.RequiredPorts.M = c2.ProvidedPorts.N);
			m.Bind(c1.RequiredPorts.M = c3.ProvidedPorts.N);

			Tests.RaisesWith<AmbiguousBindingsException>(() => m.Seal(),
				e => e.RequiredPort.ShouldBe(m.Metadata.RootComponent.Subcomponents[1].RequiredPorts[0]));
		}
Example #15
0
		protected override void Check()
		{
			var c = new C();
			var m = new Model();
			m.AddRootComponents(c);
			m.Seal();

			var actual = Ltl.IsOccurring<C.F1>(c) | Ltl.IsOccurring<C.F2>(c);
			var expected = new BinaryFormula(
				new FaultOccurrenceFormula(c.Metadata.Faults[0]),
				BinaryFormulaOperator.Or, PathQuantifier.None,
				new FaultOccurrenceFormula(c.Metadata.Faults[1]));

			Check(actual, expected);
		}
Example #16
0
		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);
		}
Example #17
0
		protected override void Check()
		{
			var c = new C();
			var m = new Model();
			m.AddRootComponents(c);
			m.Seal();

			//var actual = (LtlFormula)(!c.M == false);
			//var expected = new StateFormula(
			//	new BinaryExpression(BinaryOperator.Equals,
			//		new UnaryExpression(UnaryOperator.Not,
			//			new MethodInvocationExpression(m.Metadata.RootComponent.Subcomponents[0].ProvidedPorts[0])),
			//		new BooleanLiteralExpression(false)));

			// TODO: Support properties
			//Check(actual, expected);
		}
Example #18
0
		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);
		}
Example #19
0
		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);
			}
		}
Example #20
0
		protected override void Check()
		{
			var c1 = new C2();
			var c2 = new C2();
			var c3 = new C3("name");
			var c4 = new C2();

			var m = new Model();
			m.AddRootComponent(c1);
			m.AddRootComponents(c2, c3);
			m.AddRootComponents(c4);
			m.AddRootComponents(); // should have no effect
			m.Seal();

			m.Metadata.RootComponent.Subcomponents.ShouldBe(new[] { c1.Metadata, c2.Metadata, c3.Metadata, c4.Metadata });
			m.Metadata.Components.ShouldBe(new[] { m.Metadata.RootComponent, c1.Metadata, c2.Metadata, c3.Metadata, c4.Metadata });

			m.Metadata.RootComponent.Subcomponents[0].Name.ShouldBe("c1");
			m.Metadata.RootComponent.Subcomponents[1].Name.ShouldBe("c2");
			m.Metadata.RootComponent.Subcomponents[2].Name.ShouldBe("name");
			m.Metadata.RootComponent.Subcomponents[3].Name.ShouldBe("c4");
		}
Example #21
0
		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);
			}
		}
Example #22
0
		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());
		}