public void SingleRuleITest() { Log.logLevel = Log.LogLevels.DETAILED; RuleMSX rmsx = new RuleMSX(); string newRuleSetName = "SingleIterationRuleSet"; string newDataSetName = "SingleIterationDataSet"; string newRuleName = "IsBooleanTrue"; string actionMessage = "ActionMessage"; RuleSet rs = rmsx.createRuleSet(newRuleSetName); DataSet ds = rmsx.createDataSet(newDataSetName); RuleAction rai = rmsx.createAction("RuleActionIn", new GenericAction(actionMessage)); Rule r = new Rule(newRuleName, new GenericBoolRule(true), rai); rs.AddRule(r); ds.addDataPoint("TestDataPoint", new StringDataPoint("test_data_point")); rs.Execute(ds); // We have to wait for the action to take place. Under normal circumstances there // would be no interation with the data from outside the evaluators/actions. System.Threading.Thread.Sleep(100); GenericAction rao = (GenericAction)rai.getExecutor(); Assert.That(rao.getOutgoing(), Is.EqualTo(actionMessage)); }
public void CreateDataSetWithNullNameFails() { RuleMSX rmsx = new RuleMSX(); string newDataSetName = null; Assert.Throws <ArgumentException>(() => rmsx.createDataSet(newDataSetName)); }
public void CreateDataSetReturnsNewDataSet() { RuleMSX rmsx = new RuleMSX(); string newDataSetName = "NewDataSet"; DataSet dataSet = rmsx.createDataSet(newDataSetName); Assert.That(dataSet.getName(), Is.EqualTo(newDataSetName)); }
public void DataSetGetNameShouldReturnName() { RuleMSX rmsx = new RuleMSX(); string newDataSetName = "NewDataSet"; DataSet ds = rmsx.createDataSet(newDataSetName); Assert.That(ds.getName(), Is.EqualTo(newDataSetName)); }
public void GetDataSetByNameReturnsCorrectDataSet() { RuleMSX rmsx = new RuleMSX(); string newDataSetName = "NewDataSet"; rmsx.createDataSet(newDataSetName); DataSet ds = rmsx.getDataSet(newDataSetName); Assert.That(ds.getName(), Is.EqualTo(newDataSetName)); }
public void GetDataSetWithIncorrectNameReturnsNull() { RuleMSX rmsx = new RuleMSX(); string newDataSetName = "NewDataSet"; rmsx.createDataSet(newDataSetName); DataSet ds = rmsx.getDataSet("SomeOtherName"); Assert.IsNull(ds); }
public void DataSetDataPointAddReturnsNewDataPoint() { RuleMSX rmsx = new RuleMSX(); string newDataSetName = "NewDataSet"; string newDataPointName = "NewDataPointName"; DataSet ds = rmsx.createDataSet(newDataSetName); DataPoint dpo = ds.addDataPoint(newDataPointName); Assert.That(dpo.GetName(), Is.EqualTo(newDataPointName)); }
public void GetDataSetsReturnsDataSetCollection() { RuleMSX rmsx = new RuleMSX(); string newDataSetName = "NewDataSet"; rmsx.createDataSet(newDataSetName); List <DataSet> dsl = rmsx.getDataSets(); DataSet ds = dsl[0]; Assert.That(ds.getName(), Is.EqualTo(newDataSetName)); }
public void RuleGetEvaluatorReturnsCorrectEvaluator() { RuleMSX rmsx = new RuleMSX(); string newRuleSetName = "NewRuleSet"; string newDataSetName = "NewDataSet"; string newRuleName = "Rule1"; RuleSet rs = rmsx.createRuleSet(newRuleSetName); Rule r = new Rule(newRuleName, new GenericBoolRule(true)); DataSet ds = rmsx.createDataSet(newDataSetName); rs.AddRule(r); Assert.That(r.GetEvaluator().Evaluate(ds), Is.EqualTo(true)); }
public void SetDataPointSourceAtDataPointCreateCheckSource() { RuleMSX rmsx = new RuleMSX(); string newDataSetName = "NewDataSet"; string newDataPointName = "NewDataPointName"; string testDataPointValue = "TestDataPointValue"; DataSet ds = rmsx.createDataSet(newDataSetName); DataPointSource srci = new TestDataPointSource(testDataPointValue); DataPoint dpo = ds.addDataPoint(newDataPointName, srci); DataPointSource srco = dpo.GetSource(); Assert.That(srco.GetValue().ToString(), Is.EqualTo(testDataPointValue)); }
public void GetDataPointsReturnsCorrectDictOfPoints() { RuleMSX rmsx = new RuleMSX(); string newDataSetName = "NewDataSet"; string newDataPointName = "NewDataPointName"; DataSet ds = rmsx.createDataSet(newDataSetName); DataPoint dpi = ds.addDataPoint(newDataPointName); Dictionary <string, DataPoint> dpd = ds.getDataPoints(); DataPoint dpo; dpd.TryGetValue(newDataPointName, out dpo); Assert.That(dpo.GetName(), Is.EqualTo(newDataPointName)); }
public void DataPointSourceSetStaleNoError() { // Call to SetStale() on DataPointSource should return no error RuleMSX rmsx = new RuleMSX(); string newDataSetName = "NewDataSet"; string newDataPointName = "NewDataPointName"; string testDataPointValue = "TestDataPointValue"; DataSet ds = rmsx.createDataSet(newDataSetName); DataPoint dpo = ds.addDataPoint(newDataPointName); DataPointSource srci = new TestDataPointSource(testDataPointValue); dpo.SetDataPointSource(srci); Assert.DoesNotThrow(() => srci.SetStale()); }
public void RuleMSXStopShouldReturnTrueWithActiveRuleSet() { RuleMSX rmsx = new RuleMSX(); string newRuleSetName = "NewRuleSet"; string newDataSetName = "NewDataSet"; string newRuleName = "Rule1"; RuleSet rs = rmsx.createRuleSet(newRuleSetName); Rule r = new Rule(newRuleName, new GenericBoolRule(true)); DataSet ds = rmsx.createDataSet(newDataSetName); rs.AddRule(r); rs.Execute(ds); Assert.That(rmsx.Stop(), Is.EqualTo(true)); }
public void RuleMSXStopShouldReturnTrueWithUnexecutedRuleSet() { RuleMSX rmsx = new RuleMSX(); string newRuleSetName = "NewRuleSet"; string newDataSetName = "NewDataSet"; string newRuleName = "Rule1"; RuleSet rs = rmsx.createRuleSet(newRuleSetName); Rule r = new Rule(newRuleName, new GenericBoolRule(true)); DataSet ds = rmsx.createDataSet(newDataSetName); rs.AddRule(r); // We are deliberately not executing the ruleset... //rs.Execute(ds); Assert.That(rmsx.Stop(), Is.EqualTo(true)); }
public void CreateDataSetAndDumpCheckSize() { RuleMSX rmsx = new RuleMSX(); string newDataSetName = "NewDataSet"; DataSet ds = rmsx.createDataSet(newDataSetName); ds.addDataPoint("DataPoint1").SetDataPointSource(new TestDataPointSource("dp1")); ds.addDataPoint("DataPoint2").SetDataPointSource(new TestDataPointSource("dp2")); ds.addDataPoint("DataPoint3").SetDataPointSource(new TestDataPointSource("dp3")); ds.addDataPoint("DataPoint4").SetDataPointSource(new TestDataPointSource("dp4")); ds.addDataPoint("DataPoint5").SetDataPointSource(new TestDataPointSource("dp5")); string report = ds.report(); System.Console.WriteLine(report); Assert.That(report.Length, Is.EqualTo(123)); }
public void RuleSetReportingSizeCheckSingleRule() { RuleMSX rmsx = new RuleMSX(); string newRuleSetName = "TestRuleSet"; string newDataSetName = "TestDataSet"; string newRuleName = "IsBooleanTrue"; RuleSet rs = rmsx.createRuleSet(newRuleSetName); DataSet ds = rmsx.createDataSet(newDataSetName); Rule r = new Rule(newRuleName, new GenericBoolRule(true)); rs.AddRule(r); string report = rs.report(); System.Console.WriteLine(report); Assert.That(report.Length, Is.EqualTo(126)); }
public void RuleAddActionGetActionReturnsCorrectAction() { RuleMSX rmsx = new RuleMSX(); string newRuleSetName = "NewRuleSet"; string newDataSetName = "NewDataSet"; string newRuleName = "Rule1"; string actionMessage = "ActionMessage"; RuleSet rs = rmsx.createRuleSet(newRuleSetName); DataSet ds = rmsx.createDataSet(newDataSetName); Rule r = new Rule(newRuleName, new GenericBoolRule(true)); rs.AddRule(r); RuleAction rai = rmsx.createAction("RuleActionIn", new GenericAction(actionMessage)); r.AddAction(rai); ActionExecutor rae = r.GetActions()[0].getExecutor(); rae.Execute(ds); GenericAction ga = (GenericAction)rae; Assert.That(ga.getOutgoing, Is.EqualTo(actionMessage)); }
public void VariableRuleCountTest() { /* Rule: IntBetween(x,y) * * {1,10} * / \ * {1,5} {6,10} * / \ / \ * {1,3} {4,5} {6,8} {9,10} * / | \ / \ / | \ / \ * {1}{2}{3}{4}{5}{6}{7}{8}{9}{10} */ Log.logLevel = Log.LogLevels.NONE; RuleMSX rmsx = new RuleMSX(); RuleSet ruleSet = rmsx.createRuleSet("VariableRuleSet"); // Set min and max of target range int numMin = 1; int numMax = 10000; // Set value for target int target = 9999; TargetReached targetReached = new TargetReached(); RuleAction reached = rmsx.createAction("reached", targetReached); Accumulator count = new Accumulator(0); // Setup rule tree createNRules(rmsx, ruleSet, reached, count, numMin, numMax); DataSet dataSet = rmsx.createDataSet("TargetTestDataSet"); // Set datapoint for target dataSet.addDataPoint("target", new GenericIntDataPointSource(target)); // Set datapoint for result dataSet.addDataPoint("result", new GenericIntDataPointSource(0)); //System.Console.WriteLine("Report: \n\n" + ruleSet.report()); ruleSet.Execute(dataSet); int maxMS = 40000; int step = 10; while (maxMS > 0) { if (targetReached.fired) { break; } System.Threading.Thread.Sleep(step); maxMS -= step; } if (maxMS == 0) { System.Console.WriteLine("Timeout"); } ruleSet.Stop(); System.Console.WriteLine("Execution Time (ms): " + ruleSet.GetLastCycleExecutionTime()); System.Console.WriteLine("Number of Evaluations: " + count.value().ToString()); int result = (int)((GenericIntDataPointSource)dataSet.getDataPoint("result").GetSource()).GetValue(); Assert.True(target == result); }
public void VariableDataSetCountTest() { Log.logLevel = Log.LogLevels.NONE; RuleMSX rmsx = new RuleMSX(); RuleSet ruleSet = rmsx.createRuleSet("VariableRuleSet"); // Set min and max of target range int numMin = 1; int numMax = 1000; // Set value for target int target = 998; // number of datasets to run int numDataSets = 500; MultiTargetReached targetReached = new MultiTargetReached(numDataSets); RuleAction reached = rmsx.createAction("reached", targetReached); Accumulator count = new Accumulator(0); // Setup rule tree createNRules(rmsx, ruleSet, reached, count, numMin, numMax); for (int i = 0; i < numDataSets; i++) { DataSet dataSet = rmsx.createDataSet("TargetTestDataSet" + i.ToString()); // Set datapoint for target dataSet.addDataPoint("target", new GenericIntDataPointSource(target)); // Set datapoint for result dataSet.addDataPoint("result", new GenericIntDataPointSource(0)); ruleSet.Execute(dataSet); } int maxMS = 40000; int step = 10; while (maxMS > 0) { if (targetReached.fired) { break; } System.Threading.Thread.Sleep(step); maxMS -= step; } if (maxMS == 0) { System.Console.WriteLine("Timeout"); } ruleSet.Stop(); System.Console.WriteLine("Execution Time (ms): " + ruleSet.GetLastCycleExecutionTime()); System.Console.WriteLine("Number of Evaluations: " + count.value().ToString()); //int result = (int)((GenericIntDataPointSource)dataSet.getDataPoint("result").GetSource()).GetValue(); Assert.True(true); }
public void CounterTest() { Log.logLevel = Log.LogLevels.BASIC; RuleMSX rmsx = new RuleMSX(); RuleSet ruleSet = rmsx.createRuleSet("CounterTestRuleSet"); DataSet dataSet = rmsx.createDataSet("CounterTestDataSet"); dataSet.addDataPoint("counter", new GenericIntDataPointSource(0)); int maxVal = 10000; RuleAction counterSignalAndStep10 = rmsx.createAction("CounterSignalAndStep10", new CounterSignalAndStep(10)); RuleAction counterSignalAndStep100 = rmsx.createAction("CounterSignalAndStep100", new CounterSignalAndStep(100)); RuleAction counterSignalAndStep1000 = rmsx.createAction("CounterSignalAndStep1000", new CounterSignalAndStep(1000)); RuleAction counterSignalAndStepMax = rmsx.createAction("CounterSignalAndStepMax", new CounterSignalAndStep(maxVal)); EqualSignal equalSignal = new EqualSignal(); RuleAction equalSignalMax = rmsx.createAction("EqualSignalMax", equalSignal); Rule lessThan10 = new Rule("LessThan10", new IntMinMaxEvaluator(0, 9), counterSignalAndStep10); Rule greaterThanOrEqualTo10LessThan100 = new Rule("GreaterThanOrEqualTo10LessThan100", new IntMinMaxEvaluator(10, 99), counterSignalAndStep100); Rule greaterThanOrEqualTo100LessThan1000 = new Rule("GreaterThanOrEqualTo100LessThan1000", new IntMinMaxEvaluator(100, 999), counterSignalAndStep1000); Rule greaterThanOrEqualTo1000LessThanMax = new Rule("GreaterThanOrEqualTo1000LessThanMax", new IntMinMaxEvaluator(1000, maxVal - 1), counterSignalAndStepMax); Rule equalMax = new Rule("EqualMax", new EqualEvaluator(maxVal), equalSignalMax); ruleSet.AddRule(lessThan10); ruleSet.AddRule(greaterThanOrEqualTo10LessThan100); ruleSet.AddRule(greaterThanOrEqualTo100LessThan1000); ruleSet.AddRule(greaterThanOrEqualTo1000LessThanMax); ruleSet.AddRule(equalMax); System.Console.WriteLine(ruleSet.report()); ruleSet.Execute(dataSet); int maxMS = 400000; int step = 10; while (maxMS > 0) { if (equalSignal.fired) { System.Console.WriteLine("Target reached"); break; } System.Threading.Thread.Sleep(step); maxMS -= step; } if (maxMS == 0) { System.Console.WriteLine("Timeout"); } ruleSet.Stop(); System.Console.WriteLine("Execution Time (ms): " + ruleSet.GetLastCycleExecutionTime()); Assert.That(equalSignal.fired, Is.EqualTo(true)); }