public void TestGetRuleByName() { RuleCollection rc = new RuleCollection((IRandom)m_Random.MockInstance); Rule rule1 = new Rule(); rule1.Name = "r"; rule1.Probability = 1.0; rc.Add(rule1); m_Random.ExpectAndReturn("NextDouble", 0.0); Assert.AreSame(rule1, rc.GetRuleByName("r")); Rule rule2 = new Rule(); rule2.Name = "r"; rule2.Probability = 1.0; rc.Add(rule2); m_Random.ExpectAndReturn("NextDouble", 0.2); Assert.AreSame(rule1, rc.GetRuleByName("r"), "rule 1 expected"); m_Random.ExpectAndReturn("NextDouble", 0.6); Assert.AreSame(rule2, rc.GetRuleByName("r"), "rule 2 expected"); m_Random.Verify(); }
public Context GetWord(string startRule) { Context c = new Context(); try { Rule r = _Rules.GetRuleByName(startRule); if (r != null) { r.Execute(c); } } catch (Exception ex) { Warnings.Add(ex.Message); } return(c); }