public static void CanBuildDouble()
        {
            var val    = Math.PI;
            var result = SymbolTokens.Number(val);

            Assert.AreEqual(SymbolType.Number, result.Type);
            Assert.AreEqual(val.ToString(), result.Token);
        }
        public static void RedundantParenthesesAreRemovedFromNumbers()
        {
            var expected = new List <SymbolToken> {
                SymbolTokens.Number(3)
            };
            var result = StringTokenizer.Parse("((3))");

            Assert.AreEqual(expected, result);
        }
        public static void CanTokenizeSimpleAddition()
        {
            var expected = new List <SymbolToken> {
                SymbolTokens.Number(23),
                SymbolTokens.Addition,
                SymbolTokens.Number(41)
            };

            var result = StringTokenizer.Parse("23+41");

            Assert.AreEqual(expected, result);
        }
        public static void CanTokenizeSimpleExponentiation()
        {
            var expectedResult = new List <SymbolToken> {
                SymbolTokens.Number(23),
                SymbolTokens.Exponentiation,
                SymbolTokens.Number(41)
            };

            var result = StringTokenizer.Parse("23^41");

            Assert.AreEqual(expectedResult, result);
        }
        public static void CanTokenizeSimpleSine()
        {
            var expected = new List <SymbolToken> {
                SymbolTokens.Sine,
                SymbolTokens.LeftParen,
                SymbolTokens.Number(123),
                SymbolTokens.RightParen
            };

            var result = StringTokenizer.Parse("sin(123)");

            Assert.AreEqual(expected, result);
        }
        public static void CanTokenizeSimpleNegation()
        {
            var expected = new List <SymbolToken> {
                SymbolToken.NegationToken,
                SymbolTokens.LeftParen,
                SymbolTokens.Number(123),
                SymbolTokens.RightParen
            };

            var result1 = StringTokenizer.Parse("-123");
            var result2 = StringTokenizer.Parse("-(123)");

            Assert.AreEqual(expected, result1);
            Assert.AreEqual(expected, result2);
        }
        public static void MissingParenthesesAreAutomaticallyAdded()
        {
            var expected = new List <SymbolToken> {
                SymbolTokens.Number(4),
                SymbolTokens.Multiplication,
                SymbolToken.OpenBracket,
                SymbolTokens.Number(3),
                SymbolTokens.Addition,
                SymbolTokens.Number(5),
                SymbolToken.CloseBracket
            };
            var result = StringTokenizer.Parse("4 * ((3 + 5)  ");

            Assert.AreEqual(expected, result);
        }
        public static void RedundantParenthesesAreRemovedFromExpressions()
        {
            var expected = new List <SymbolToken> {
                SymbolTokens.Number(4),
                SymbolTokens.Multiplication,
                SymbolToken.OpenBracket,
                SymbolTokens.Number(3),
                SymbolTokens.Addition,
                SymbolTokens.Number(5),
                SymbolToken.CloseBracket
            };
            var result = StringTokenizer.Parse("4 * ((3 + 5) )  ");

            Assert.AreEqual(expected, result);
        }
        public static void CanTokenizeMultipleAdditions()
        {
            var expected = new List <SymbolToken> {
                SymbolTokens.Number(23),
                SymbolTokens.Addition,
                SymbolTokens.Number(41),
                SymbolTokens.Addition,
                SymbolToken.NegationToken,
                SymbolToken.OpenBracket,
                SymbolTokens.Number(100.5),
                SymbolToken.CloseBracket,
            };

            var result = StringTokenizer.Parse("23 +41 +-100.5");

            Assert.AreEqual(expected, result);
        }
        public static void CanTokenizeWithNegatedUnary()
        {
            var expected = new List <SymbolToken> {
                SymbolTokens.Number(20),
                SymbolTokens.Multiplication,
                SymbolToken.NegationToken,
                SymbolToken.OpenBracket,
                SymbolTokens.Sine,
                SymbolToken.OpenBracket,
                SymbolTokens.Number(123.45),
                SymbolToken.CloseBracket,
                SymbolToken.CloseBracket
            };

            var result = StringTokenizer.Parse("20 * -sin(123.45)");

            Assert.AreEqual(expected, result);
        }
        public static void CanTokenizeNegatedParenthesizedExpression()
        {
            var expected = new List <SymbolToken> {
                SymbolTokens.Number(20),
                SymbolTokens.Subtraction,
                SymbolToken.NegationToken,
                SymbolToken.OpenBracket,
                SymbolTokens.Number(3),
                SymbolTokens.Addition,
                SymbolTokens.Number(3),
                SymbolTokens.Multiplication,
                SymbolTokens.Number(3),
                SymbolToken.CloseBracket
            };

            var result = StringTokenizer.Parse("20 --(3 + 3 * 3)");

            Assert.AreEqual(expected, result);
        }
        public static void CanTokenizeMultipleNegationSymbols()
        {
            var expected = new List <SymbolToken> {
                SymbolToken.NegationToken,
                SymbolToken.OpenBracket,
                SymbolToken.NegationToken,
                SymbolToken.OpenBracket,
                SymbolToken.NegationToken,
                SymbolToken.OpenBracket,
                SymbolTokens.Number(3),
                SymbolToken.CloseBracket,
                SymbolToken.CloseBracket,
                SymbolToken.CloseBracket
            };

            var result1 = StringTokenizer.Parse("---3");
            var result2 = StringTokenizer.Parse("-(--3)");

            Assert.AreEqual(expected, result1);
            Assert.AreEqual(expected, result2);
        }