Exemplo n.º 1
0
    public void LSystemAppliesParameterMatchesAndTerminatesAtCondition()
    {
        LSystemState <float> state = new DefaultLSystemState("A(2)");

        using var basicLSystem = LSystemBuilder.FloatSystem(new string[] {
            "A(x) : x < 6 -> A(x + 1)",
        });

        Assert.AreEqual("A(2)", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A(3)", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A(4)", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A(5)", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A(6)", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A(6)", state.currentSymbols.Data.ToString());
        state.currentSymbols.Dispose();
    }
Exemplo n.º 2
0
    public void LSystemAppliesBasicRules()
    {
        LSystemState <float> state = new DefaultLSystemState("B");

        using var basicLSystem = LSystemBuilder.FloatSystem(
                  new string[] {
            "A -> AB",
            "B -> A"
        });

        Assert.AreEqual("B", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("AB", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ABA", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ABAAB", state.currentSymbols.Data.ToString());
        state.currentSymbols.Dispose();
    }
Exemplo n.º 3
0
    public void LSystemAssumesIdentityReplacementWithContextRules()
    {
        LSystemState <float> state = new DefaultLSystemState("B");

        using var basicLSystem = LSystemBuilder.FloatSystem(new string[] {
            "B -> ABA",
            "A > A ->",
            "A < A -> B"
        });

        Assert.AreEqual("B", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ABA", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("AABAA", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("BABAB", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ABAAABAAABA", state.currentSymbols.Data.ToString());
        state.currentSymbols.Dispose();
    }
Exemplo n.º 4
0
    public void LSystemDoesAFibbonachi()
    {
        LSystemState <float> state = new DefaultLSystemState("A(1)B(1)");

        using var basicLSystem = LSystemBuilder.FloatSystem(new string[] {
            "       A(x) > B(y) -> A(x + y)",
            "A(x) < B(y)        -> B(x)",
        });

        Assert.AreEqual("A(1)B(1)", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A(2)B(1)", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A(3)B(2)", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A(5)B(3)", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A(8)B(5)", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A(13)B(8)", state.currentSymbols.Data.ToString());
        state.currentSymbols.Dispose();
    }
Exemplo n.º 5
0
    public void LSystemAppliesContextualRulesOfEqualComplexityInDefinitionOrder()
    {
        LSystemState <float> state = new DefaultLSystemState("AAA");

        using var basicLSystem = LSystemBuilder.FloatSystem(new string[] {
            "    A > A -> B",
            "A < A     -> C"
        });
        Assert.AreEqual("AAA", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("BBC", state.currentSymbols.Data.ToString());
        state.currentSymbols.Dispose();

        state = new DefaultLSystemState("AAA");
        using var basicLSystem2 = LSystemBuilder.FloatSystem(new string[] {
            "A < A     -> C",
            "    A > A -> B"
        });
        Assert.AreEqual("AAA", state.currentSymbols.Data.ToString());
        state = basicLSystem2.StepSystem(state);
        Assert.AreEqual("BCC", state.currentSymbols.Data.ToString());
        state.currentSymbols.Dispose();
    }
Exemplo n.º 6
0
    public void LSystemAppliesStochasticRuleDifferently()
    {
        LSystemState <float> state = new DefaultLSystemState("C");

        using var basicLSystem = LSystemBuilder.FloatSystem(new string[] {
            "A -> AC",
            "P(0.9) | C -> A",
            "P(0.1) | C -> AB"
        });

        Assert.AreEqual("C", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("A", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("AC", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ACA", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ACAAC", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ACAACACA", state.currentSymbols.Data.ToString());
        state.currentSymbols.Dispose();
    }
Exemplo n.º 7
0
    public void LSystemIgnoresIgnoredCharatchers()
    {
        LSystemState <float> state = new DefaultLSystemState("B");

        using var basicLSystem = LSystemBuilder.FloatSystem(new string[] {
            "    A     -> A1B2",
            "    B     -> 3A4",
            "    A > A -> 5",
            "A < A     -> 6B7"
        }, includedCharacters: "AB");

        Assert.AreEqual("B", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("3A4", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("3A1B24", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("3A1B213A424", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("3A1B213A4213A1B2424", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("3A1B213A4213542136B713A42424", state.currentSymbols.Data.ToString());
        state.currentSymbols.Dispose();
    }
Exemplo n.º 8
0
    public void LSystemAppliesContextualRulesWithUniqueOrigins()
    {
        LSystemState <float> state = new DefaultLSystemState("A");

        using var basicLSystem = LSystemBuilder.FloatSystem(new string[] {
            "    A     -> AB",
            "    B     -> CDC",
            "    D > C -> A",
            "D < C > D -> B"
        });

        Assert.AreEqual("A", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("AB", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ABCDC", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ABCDCCAC", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ABCDCCACCABC", state.currentSymbols.Data.ToString());
        state = basicLSystem.StepSystem(state);
        Assert.AreEqual("ABCDCCACCABCCABCDCC", state.currentSymbols.Data.ToString());
        state.currentSymbols.Dispose();
    }