Esempio n. 1
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. 2
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. 3
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>();
        }
Esempio n. 4
0
        public void NodeCountAlgorithm(string toParse, int delta, int nodeCount)
        {
            //arrange

            //act
            Algorithm sut = new Algorithm(wrapper.Parse(toParse))
            {
                Delta = delta
            };

            //assert
            sut.NodeCount.Should().Be(nodeCount);
        }
        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. 6
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. 7
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);
        }