Esempio n. 1
0
        public Algorithm(Node rootNode)
        {
            _wrapper = new AstWrapper();

            _rootNode = rootNode;
            _delta    = 0;

            _nodeCount = _wrapper.NodeCount(RootNode);
        }
Esempio n. 2
0
        public void Ast_compute_withIdentifier(string toCompute, double x, double y, double result)
        {
            //arrange
            AstWrapper sut = new AstWrapper();
            //act
            var n = sut.Parse(toCompute);

            //assert
            sut.Compute(n, x, y).Should().Be(result);
        }
Esempio n. 3
0
        public void Ast_compute(string toCompute, double result)
        {
            //arrange
            AstWrapper sut = new AstWrapper();
            //act
            var n = sut.Parse(toCompute);

            //assert
            sut.Compute(n, 0, 0).Should().Be(result);
        }
Esempio n. 4
0
        public void Ast_getRandom_tree()
        {
            //arrange
            AstWrapper sut = new AstWrapper();
            //act
            var n1 = sut.GetRandomGraph(randomsource);
            var n2 = sut.GetRandomGraph(randomsource);

            //assert
            sut.Print(n1).Should().NotBe(sut.Print(n2));
        }
Esempio n. 5
0
        public void Ast_compute_with_wrong_Identifier(string toCompute, double x, double y, double result)
        {
            //arrange
            AstWrapper sut = new AstWrapper();
            //act
            var n = sut.Parse(toCompute);

            //assert
            sut.Invoking(a => a.Compute(n, x, y))
            .Should().Throw <ArgumentException>();
        }
        public void Mutator_parse(string toParse)
        {
            //arrange
            AstWrapper sut   = new AstWrapper();
            var        n     = sut.Parse(toParse);
            string     print = sut.Print(n);
            //act
            var nut = sut.MutateGraph(n, 1.0, out int mutationratio);

            //assert
            sut.Print(nut).Should().NotBe(print);
            Console.WriteLine(sut.Print(nut));
        }
Esempio n. 7
0
        public void Ast_parse()
        {
            //arrange
            AstWrapper sut = new AstWrapper();
            //act
            var n = sut.Parse("x+1");

            //assert
            n.Should().BeOfType <BinaryNode>();

            (n as BinaryNode).Type.Should().Be(TokenType.Plus);
            (n as BinaryNode).Left.Should().BeOfType <IdentifierNode>();
            (n as BinaryNode).Right.Should().BeOfType <ConstantNode>();

            ((n as BinaryNode).Left as IdentifierNode).Identifier.Should().Be("x");
            ((n as BinaryNode).Right as ConstantNode).Value.Should().Be(1);
        }
Esempio n. 8
0
        public static double[,] CreatePictureFromGraph(int width, int height, Ast.Node root)
        {
            AstWrapper astWrapper = new AstWrapper();


            double[,] matrix = new double[width, height];

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    double x = (i - width / 2) * 0.1;
                    double y = -(j - height / 2) * 0.1;
                    matrix[i, j] = astWrapper.Compute(root, x, y);//COMPUTE AST Here
                }
            }
            return(matrix);
        }
Esempio n. 9
0
        public static double[,] CreatePictureFromEquation(int width, int height, string equation)
        {
            //throw new NotImplementedException("ready for the ast !");
            AstWrapper astWrapper = new AstWrapper();

            Node computeGraphRoot = astWrapper.Parse(equation);

            double[,] matrix = new double[width, height];

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    double x = (i - width / 2) * 0.1;
                    double y = -(j - height / 2) * 0.1;
                    matrix[i, j] = astWrapper.Compute(computeGraphRoot, x, y); //COMPUTE AST Here
                }
            }
            return(matrix);
        }
Esempio n. 10
0
        public void Ast_getRandom_tree_stress()
        {
            //arrange
            AstWrapper sut = new AstWrapper();

            int population   = 1000;
            int equalCounter = 0;

            //act
            for (int i = 0; i < population; i++)
            {
                var n1 = sut.GetRandomGraph(randomsource);
                var n2 = sut.GetRandomGraph(randomsource);
                //assert
                if (sut.Print(n1) == sut.Print(n2))
                {
                    equalCounter++;
                }
                n1 = null;
                n2 = null;
            }
            ((double)(equalCounter / population)).Should().BeLessOrEqualTo(0.1);
            Console.WriteLine((double)(equalCounter / population));
        }