Example #1
0
        public void Do_DoNotHoldLastValueBetweenCalls()
        {
            using var lisp = new SoltysLispVM();

            var result = lisp.Do(@"(+ 10 1)");

            Assert.Equal(11, (int)result);
            var newResult = lisp.Do(@"()");

            Assert.Equal("nil", (string)newResult);
        }
Example #2
0
        public void TwoDo_DefineFunctionWithConstantValue_ReturnConstantValue()
        {
            using var lisp = new SoltysLispVM();
            lisp.Initialize();
            var result = lisp.Do(@"(def! x 42)");

            result = lisp.Do(@"(+ 8 x)");
            Assert.IsType <int>(result);
            var intValue = (int)result;

            Assert.Equal(50, intValue);
        }
Example #3
0
        public void TwoDo_RedefineMethod()
        {
            using var lisp = new SoltysLispVM();
            lisp.Initialize();
            var result = lisp.Do(
                @"(def! x (* 5 5))
                  (def! y (* 10 x))");

            result = lisp.Do(
                @"(def! x (* 6 6))
                  (y)");
            Assert.IsType <int>(result);
            var intValue = (int)result;

            Assert.Equal(360, intValue);
        }
Example #4
0
        public void Do_Println_ResultIsNil()
        {
            using var lisp = new SoltysLispVM();
            lisp.Initialize();

            var result = lisp.Do(@"(println ""Hello, World!"")");

            Assert.Equal("nil", result);
        }
Example #5
0
        public void Do_MathOnDoubles_ExpectDoubleResult(string input, double expectedResult)
        {
            using var lisp = new SoltysLispVM();
            lisp.Initialize();
            var result = lisp.Do(input);

            Assert.IsType <double>(result);
            var doubleValue = (double)result;

            Assert.Equal(expectedResult, doubleValue, 5);
        }
Example #6
0
        public void Do_MathOnIntegers_ExpectIntegerResult(string input, int expectedResult)
        {
            using var lisp = new SoltysLispVM();
            lisp.Initialize();
            var result = lisp.Do(input);

            Assert.IsType <int>(result);
            var intValue = (int)result;

            Assert.Equal(expectedResult, intValue);
        }
Example #7
0
        public void Do_QuoteFunction_ResultIsListItself(string input)
        {
            using var lisp = new SoltysLispVM();
            lisp.Initialize();

            var result = lisp.Do(input);

            Assert.IsType <List <object> >(result);
            var theList = (List <object>)result;

            Assert.Equal(3, theList.Count);
            Assert.Equal(new object[] { 1, 2, 3 }, theList);
        }
Example #8
0
        public void Do_MultipleFunctionsCall()
        {
            using var lisp = new SoltysLispVM();
            lisp.Initialize();
            var result = lisp.Do(
                @"(def! x (* 4 10))
                  (+ x (/ x x))");

            Assert.IsType <int>(result);
            var intValue = (int)result;

            Assert.Equal(41, intValue);
        }
Example #9
0
        public void Do_DefineFunctionWithMathOperation_ReturnMathResult()
        {
            using var lisp = new SoltysLispVM();
            lisp.Initialize();
            var result = lisp.Do(
                @"(def! x (* 4 10))
                  (+ x 8)");

            Assert.IsType <int>(result);
            var intValue = (int)result;

            Assert.Equal(48, intValue);
        }