Example #1
0
        public void ConditionalMath_SubtractRight()
        {
            var src     = @"A Nifty Rule
 dispLaYaS 
conditions
x - 5 is y
dialogs
:plr
hello world
outcomes
set a to b
";
            var program = new WordLangResults(src);

            Assert.AreEqual(false, program.ParserErrors.AnyErrors);
            var v         = new ProgramToTree();
            var firstExpr = program.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(- x 5)", output);
        }
Example #2
0
        public void ConditionalMath_AddLotsOfSpaces()
        {
            var src     = @"A Nifty Rule
 dispLaYaS 
conditions
x  + 25  + z +  1205 is y   +  12
dialogs
:plr
hello world
outcomes
set a to b
";
            var program = new WordLangResults(src);

            Assert.AreEqual(false, program.ParserErrors.AnyErrors);
            var v         = new ProgramToTree();
            var firstExpr = program.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(+ x (+ 25 (+ z 1205)))", output);
        }
Example #3
0
        public void ConditionalMath_PEMDAS_ParensNested()
        {
            var srcA = @"A Nifty Rule
 dispLaYaS 
conditions
2 * (  ((3 + 4) - (5 - 2)) + 4) is y 
dialogs
:plr
hello world
outcomes
set a to b
";

            var progA = new WordLangResults(srcA);

            Assert.AreEqual(false, progA.ParserErrors.AnyErrors);
            var firstExpr = progA.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var v         = new ProgramToTree();
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(* 2 (+ (- (+ 3 4) (- 5 2)) 4))", output);
        }
Example #4
0
        public void ConditionalMath_PEMDAS_MultDivide()
        {
            var srcA = @"A Nifty Rule
 dispLaYaS 
conditions
a / b * c is y 
dialogs
:plr
hello world
outcomes
set a to b
";

            var progA = new WordLangResults(srcA);

            Assert.AreEqual(false, progA.ParserErrors.AnyErrors);
            var firstExpr = progA.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var v         = new ProgramToTree();
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(/ a (* b c))", output);
        }
Example #5
0
        public void ConditionalMath_Complicated()
        {
            var srcA = @"A Nifty Rule
 dispLaYaS 
conditions
x * y + z * w * a + 1 is y 
dialogs
:plr
hello world
outcomes
set a to b
";

            var progA = new WordLangResults(srcA);

            Assert.AreEqual(false, progA.ParserErrors.AnyErrors);
            var firstExpr = progA.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var v         = new ProgramToTree();
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(+ (* x y) (+ (* z (* w a)) 1))", output);
        }
Example #6
0
        public void ConditionalMath_PEMDAS_MultThenAdd()
        {
            var srcB  = @"A Nifty Rule
 dispLaYaS 
conditions
x * a + 5 is y
dialogs
:plr
hello world
outcomes
set a to b
";
            var progB = new WordLangResults(srcB);

            Assert.AreEqual(false, progB.ParserErrors.AnyErrors);

            var v = new ProgramToTree();

            var firstExpr = progB.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(+ (* x a) 5)", output);
        }