Ejemplo n.º 1
0
        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()));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        public void Goals()
        {
            // Rule 1: A -> B(10)
            Production P1 = new Production(new Module('A'));
            P1.successor.Add(new DerivedModule('B', 10));
            P1.SuccessorCallback = GoalsTest;

            LSystem LS = new LSystem();
            LS.addProduction(P1);

            List<Module> axiom = new List<Module>() {
                new Module('A'),
                new Module('A'),
                new Module('A')
            };

            LS.setAxiom(axiom);

            LS.step();
            List<Module> expected = new List<Module>() {
                new DerivedModule('B', 21),
                new DerivedModule('B', 22),
                new DerivedModule('B', 23)
            };
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        public void Tracking()
        {
            // Rule 1: B(5) -> B(5)F(10)
            Production P1 = new Production(new DerivedModule('B', 5));
            P1.successor.Add(new DerivedModule('B', 5));
            P1.successor.Add(new DerivedModule('F', 10));

            LSystem LS = new LSystem();
            LS.addProduction(P1);
            LS.TrackCallback = TrackCallback;

            List<Module> axiom = new List<Module>() {
                new DerivedModule('B', 5),
                new DerivedModule('B', 5),
                new DerivedModule('B', 5)
            };
            LS.setAxiom(axiom);

            LS.step();

            Assert.AreEqual(15, trackedPos);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Adds a production to this system
 /// </summary>
 /// <param name="p">Production to add</param>
 public void addProduction(Production p)
 {
     // TODO: Should duplicate insertion be allowed?
     P.Add(p);
 }
Ejemplo n.º 7
0
        public void CF1()
        {
            LSystem LS = new LSystem();

            // Rule 1: A -> AB
            Production P1 = new Production(null, new Module('A'), null);
            P1.successor.Add(new Module('A'));
            P1.successor.Add(new Module('B'));

            // Rule 2: B -> A
            Production P2 = new Production(null, new Module('B'), null);
            P2.successor.Add(new Module('A'));

            LS.addProduction(P1);
            LS.addProduction(P2);

            //
            // Axiom: A
            List<Module> axiom = new List<Module>();
            axiom.Add(new Module('A'));

            LS.setAxiom(axiom);

            Assert.IsTrue(Utility.compareStates(axiom, LS.getState()));

            List<Module> expected = null;

            //
            // First step: AB
            LS.step();
            expected = new List<Module>() {
                new Module('A'),
                new Module('B')
            };
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Second step: ABA
            LS.step();
            expected.Add(new Module('A'));
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Third step:ABAAB
            LS.step();
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Fourth step: ABAABABA
            LS.step();
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            expected.Add(new Module('A'));
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Fifth step: ABAABABAABAAB
            LS.step();
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            expected.Add(new Module('A'));
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Sixth step: ABAABABAABAABABAABABA
            //             ABAABABAABAABABAABABAABAABABAABAAB
            LS.step();
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            expected.Add(new Module('A'));
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            expected.Add(new Module('A'));
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Seventh step: ABAABABAABAABABAABABAABAABABAABAAB
            LS.step();
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            expected.Add(new Module('A'));
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            expected.Add(new Module('A'));
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            expected.Add(new Module('A'));
            expected.Add(new Module('A'));
            expected.Add(new Module('B'));
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));
        }
Ejemplo n.º 8
0
        public void CF2()
        {
            LSystem LS = new LSystem();

            // Rule 1: A(0) -> A(1)
            Production P1 = new Production(null, new DerivedModule('A', 0), null);
            P1.successor.Add(new DerivedModule('A', 1));

            // Rule 2: A(1) -> A(0)B
            Production P2 = new Production(null, new DerivedModule('A', 1), null);
            P2.successor.Add(new DerivedModule('A', 0));
            P2.successor.Add(new Module('B'));

            // Rule 3: B -> A(0)
            Production P3 = new Production(null, new Module('B'), null);
            P3.successor.Add(new DerivedModule('A', 0));

            LS.addProduction(P1);
            LS.addProduction(P2);
            LS.addProduction(P3);

            //
            // Axiom: A(0)
            List<Module> axiom = new List<Module>();
            axiom.Add(new DerivedModule('A', 0));

            LS.setAxiom(axiom);

            Assert.IsTrue(Utility.compareStates(axiom, LS.getState()));

            List<Module> expected = null;

            //
            // Step one: A(1)
            LS.step();
            expected = new List<Module>() {
                new DerivedModule('A', 1)
            };
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Step two: A(0)B
            LS.step();
            expected = new List<Module>() {
                new DerivedModule('A', 0),
                new Module('B')
            };
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Step three: A(1)A(0)
            LS.step();
            expected = new List<Module>() {
                new DerivedModule('A', 1),
                new DerivedModule('A', 0)
            };
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Step four: A(0)BA(1)
            LS.step();
            expected = new List<Module>() {
                new DerivedModule('A', 0),
                new Module('B'),
                new DerivedModule('A', 1)
            };
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Step five: A(1)A(0)A(0)B
            LS.step();
            expected = new List<Module>() {
                new DerivedModule('A', 1),
                new DerivedModule('A', 0),
                new DerivedModule('A', 0),
                new Module('B')
            };
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Step six: A(0)BA(1)A(1)A(0)
            LS.step();
            expected = new List<Module>() {
                new DerivedModule('A', 0),
                new Module('B'),
                new DerivedModule('A', 1),
                new DerivedModule('A', 1),
                new DerivedModule('A', 0)
            };
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));

            //
            // Step seven: A(1)A(0)A(0)BA(0)BA(1)
            LS.step();
            expected = new List<Module>() {
                new DerivedModule('A', 1),
                new DerivedModule('A', 0),
                new DerivedModule('A', 0),
                new Module('B'),
                new DerivedModule('A', 0),
                new Module('B'),
                new DerivedModule('A', 1)
            };
            Assert.IsTrue(Utility.compareStates(expected, LS.getState()));
        }