Exemplo n.º 1
0
        public void NestedCalls()
        {
            var source = "void main()  { jump1(); }  void jump1()  { jump2(); }  void jump2()  { jump3(); }  void jump3()  { jump4(); } void jump4() { jump5(); } void jump5() { }";

            var fixture = new MachineFixture();

            fixture.Run(source);
        }
Exemplo n.º 2
0
        public void Assignments()
        {
            var source = "void main() { a = 123; b=80; }";

            var fixture = new MachineFixture();

            fixture.Run(source);
            fixture.GetReferenceValue("a").Should().Be(123);
            fixture.GetReferenceValue("b").Should().Be(80);
        }
Exemplo n.º 3
0
        public void OrOperation2()
        {
            var source = "void main()\n{\n\ta=5;\n\tif (a==12 || a==5) \n\t{\n\t\tb=3;\n\t}\n}";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.GetReferenceValue("b").Should().Be(3);
        }
Exemplo n.º 4
0
        public void AddWithParams()
        {
            var source = "int main() { return add(3, 4); } int add(int a, int b) { return a+b; }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.ReturnedValue.Should().Be(7);
        }
Exemplo n.º 5
0
        public void Recursive()
        {
            var source = "int main() { return rec(1); } int rec(int n) { if (n > 10) { return 0; } return n+rec(n+1); }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.ReturnedValue.Should().Be(55);
        }
Exemplo n.º 6
0
        public void Simpler()
        {
            var source = "int main() { return 85; }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.ReturnedValue.Should().Be(85);
        }
Exemplo n.º 7
0
        public void TwoFuncsAdded()
        {
            var source = "int main() { return first() + second(); } int first() { return 3; } int second() { return 5; } }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.ReturnedValue.Should().Be(8);
        }
Exemplo n.º 8
0
        public void Pointer()
        {
            var source = "int main() { int a=14; int* b=&a; return *b; }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.ReturnedValue.Should().Be(14);
        }
Exemplo n.º 9
0
        public void SimpleWithAddition()
        {
            var source = "void main() { return simple() + 5; } int simple() { return 85; }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.ReturnedValue.Should().Be(90);
        }
Exemplo n.º 10
0
        public void NestedCallsCombined()
        {
            var source = "int func5()  {  return 2; }  int func4()  {  return 5; }  int func3()  {  return 3+4; }   int func2()  {  return func3() + func4() + func5(); }   int func1()  {  return 1; }   int main()  {  return func1() + func2(); } ";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.ReturnedValue.Should().Be(15);
        }
Exemplo n.º 11
0
        public void NestedCallsToReturn()
        {
            var source = "void main()  { a = func1(); }  int func1()  { return func2(); } int func2() { return func3(); } int func3()  { return 1234; }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.GetReferenceValue("a").Should().Be(1234);
        }
Exemplo n.º 12
0
        public void FibonacciRecursive()
        {
            var source = "int main() { return fib(10); } int fib(int n)  { if (n == 0) return n; if (n == 1) return n; return (fib(n-1) + fib(n-2)); }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.ReturnedValue.Should().Be(55);
        }
Exemplo n.º 13
0
        public void FuncWithParams()
        {
            var source = "int main() { return add(123); } int add(int a) { return a+555; }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.ReturnedValue.Should().Be(678);
        }
Exemplo n.º 14
0
        public void TwoReturns()
        {
            var source = "int main() { a=3; if (a==3) { return 5; } else { return 2; } }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.ReturnedValue.Should().Be(5);
        }
Exemplo n.º 15
0
        public void WhileStatement_WhenConditionIsMet_BlockIsExecuted()
        {
            var source = "void main() { int a=0; while (a==0) { b = 123; a=a+1; } }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.GetReferenceValue("b").Should().Be(123);
        }
Exemplo n.º 16
0
        public void DoWhile()
        {
            var source = "void main() { int a=0; do { b = 123; a=a+1; } while (a < 2); }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.GetReferenceValue("a").Should().Be(2);
            fixture.GetReferenceValue("b").Should().Be(123);
        }
Exemplo n.º 17
0
        public void Fibonacci()
        {
            var n      = 12;
            var result = 89;

            var source  = $"void main()  {{int first;int second;int next;int c; int n; n = {n}; first = 0; second = 1;   for (c = 0; c<n ;c=c+1) {{  if ( c < 2 )  {{      next = c;  }}      if ( c > 1)     {{   next = first + second;         first = second;   second = next;  }}       }} }}";
            var fixture = new MachineFixture();

            fixture.Run(source);
            fixture.GetReferenceValue("next").Should().Be(result);
        }
Exemplo n.º 18
0
        public void DoWhile_SentenceIsExecutedOnce()
        {
            var source = "void main() { int a=0; do { b = 123; } while (a < 0); }";

            var fixture = new MachineFixture();

            fixture.Run(source);

            fixture.GetReferenceValue("a").Should().Be(0);
            fixture.GetReferenceValue("b").Should().Be(123);
        }