public void CustomComparators() { Module A = new Module('A'); DerivedModule B9 = new DerivedModule('B', 9); DerivedModule B10 = new DerivedModule('B', 10); DerivedModule B11 = new DerivedModule('B', 11); Module C = new Module('C'); Production P = new Production(A, B10, C); P.matchCompare = GreaterThan; Assert.IsFalse(P.isMatch(A, B9, C)); Assert.IsTrue(P.isMatch(A, B11, C)); P = new Production(B10, A, C); P.leftCompare = GreaterThan; Assert.IsFalse(P.isMatch(B9, A, C)); Assert.IsTrue(P.isMatch(B11, A, C)); P = new Production(A, C, B10); P.rightCompare = GreaterThan; Assert.IsFalse(P.isMatch(A, C, B9)); Assert.IsTrue(P.isMatch(A, C, B11)); }
public void ModuleMutability() { DerivedModule A10 = new DerivedModule('A', 10); Module B = new Module('B'); // Rule 1: B -> A(10) Production P = new Production(B); P.successor.Add(A10); LSystem LS = new LSystem(); LS.addProduction(P); List<Module> axiom = new List<Module>() { B, B, B }; LS.setAxiom(axiom); // // Step one: A(10)A(10)A(10) LS.step(); List<Module> expected = new List<Module>() { new DerivedModule('A', 10), new DerivedModule('A', 10), new DerivedModule('A', 10) }; Assert.IsTrue(Utility.compareStates(expected, LS.getState())); // Change the original A10 to see if it affects the state A10.param = 15; Assert.IsTrue(Utility.compareStates(expected, LS.getState())); }
public void ModuleEquals() { Module m1 = new Module('A'); Module m2 = new Module('A'); Module m3 = new Module('B'); Assert.AreEqual(m2, m1); Assert.AreNotEqual(m3, m1); }
public bool GreaterThan(Module expected, Module actual) { DerivedModule dExp = expected as DerivedModule; DerivedModule dAct = actual as DerivedModule; if (dExp == null || dAct == null) return false; return dAct.signature == dExp.signature && dAct.param > dExp.param; }
/// <summary> /// Initialized the production to be context-free. The match module must /// not be null. /// </summary> /// <param name="m">Module to check against</param> public Production(Module m) { if (m == null) throw new System.ArgumentNullException("m", "A match module must be given"); match = m; successor = new List<Module>(); }
/// <summary> /// Initializes the production to be context-sensitive. The left, match, /// and right modules must be given during construction. Left and/or Right /// can be null, but a Match is required. /// </summary> /// <param name="left">Optional left context</param> /// <param name="m">Module to match with</param> /// <param name="right">Optional right context</param> public Production(Module left, Module m, Module right) { if (m == null) throw new System.ArgumentNullException("m", "A match module must be given"); leftContext = left; match = m; rightContext = right; successor = new List<Module>(); }
public void DefaultProduction() { Module A = new Module('A'); Module B = new Module('B'); Module C = new Module('C'); Production P = new Production(A, B, C); Assert.IsTrue(P.isMatch(A, B, C)); Assert.IsFalse(P.isMatch(B, B, C)); Assert.IsFalse(P.isMatch(A, B, B)); Assert.IsFalse(P.isMatch(B, C, A)); }
private void TrackCallback(Module lastModule) { DerivedModule m = lastModule as DerivedModule; if (m == null) return; if (m.signature == 'F') trackedPos += m.param; else if (m.signature == 'B') trackedPos -= m.param; }
/// <summary> /// Tests if the /// </summary> /// <param name="left">The module to the left of the current one</param> /// <param name="m">The current module</param> /// <param name="right">The module to the right of the current one</param> /// <returns></returns> public bool isMatch(Module left, Module m, Module right) { if (leftContext != null) { if (leftCompare != null) { if (leftCompare(leftContext, left) == false) return false; } else { if (leftContext.Equals(left) == false) return false; } } if (rightContext != null) { if (rightCompare != null) { if (rightCompare(rightContext, right) == false) return false; } else { if (rightContext.Equals(right) == false) return false; } } if (matchCompare != null) return matchCompare(match, m); else return match.Equals(m); }
/// <summary> /// INitializes a context-sensitive stochastic production with a given seed /// </summary> /// <param name="left"></param> /// <param name="m"></param> /// <param name="right"></param> /// <param name="seed">Seed value</param> public StochasticProduction(Module left, Module m, Module right, int seed) : base(left, m, right) { rand = new Random(seed); }
/// <summary> /// Initializes a context-free stochastic production with a given seed /// </summary> /// <param name="m"></param> /// <param name="seed">Seed value</param> public StochasticProduction(Module m, int seed) : base(m) { rand = new Random(seed); }
/// <summary> /// Initializes a context-free stochastic production /// </summary> /// <param name="m"></param> public StochasticProduction(Module m) : base(m) { rand = new Random(); }