Example #1
0
 def test_for_var_step(self):
     test = 'y = []; for "_i" from 1 to 10 step 2 do {y pushBack _i;};'
     interpreter, outcome = interpret(test)
     self.assertEqual(Array([N(1), N(3), N(5), N(7),
                             N(9)]), interpreter['y'])
Example #2
0
 def test_foreach(self):
     test = 'y = 0; {y = y + _x + _foreachindex} forEach [1,2]'
     interpreter, _ = interpret(test)
     self.assertEqual(N(1 + 0 + 2 + 1), interpreter['y'])
Example #3
0
 def test_forspec(self):
     interpreter, outcome = interpret(
         '_y = 0; for [{_x = 1},{_x <= 10},{_x = _x + 1}] do {_y = _y + 2}')
     self.assertEqual(N(20), interpreter['_y'])
     self.assertEqual(N(11), interpreter['_x'])
     self.assertEqual(N(20), outcome)
Example #4
0
 def test_for_var(self):
     test = 'y = []; for "_i" from 1 to 10 do {y pushBack _i;};'
     interpreter, outcome = interpret(test)
     self.assertEqual(Array([N(i) for i in range(1, 11)]), interpreter['y'])
Example #5
0
 def test_find(self):
     _, outcome = interpret('"Hello world!" find "world!"')
     self.assertEqual(N(6), outcome)
Example #6
0
 def test_while(self):
     interpreter, outcome = interpret(
         '_x = 0; while {_x != 10} do {_x = _x + 1};')
     self.assertEqual(N(10), interpreter['_x'])
Example #7
0
 def test_pushBack(self):
     interpreter, outcome = interpret('_x = [1]; _x pushBack 2')
     self.assertEqual(Array([N(1), N(2)]), interpreter['_x'])
     self.assertEqual(N(1), outcome)
Example #8
0
 def test_reverse(self):
     interpreter, outcome = interpret('_x = [1, 2]; reverse _x')
     self.assertEqual(Nothing(), outcome)
     self.assertEqual(Array([N(2), N(1)]), interpreter['_x'])
Example #9
0
    def test_find(self):
        _, outcome = interpret('[1, 2] find 2')
        self.assertEqual(N(1), outcome)

        _, outcome = interpret('[1, 2] find 3')
        self.assertEqual(N(-1), outcome)
Example #10
0
    def test_subtract(self):
        test = '_x = [1, 2, 3, 2, 4]; _y = [2, 3]; _z = _x - _y'
        _, outcome = interpret(test)

        self.assertEqual(Array([N(1), N(4)]), outcome)
Example #11
0
 def test_append(self):
     interpreter, outcome = interpret('_x = [1,2]; _x append [3,4]')
     self.assertEqual(Nothing(), outcome)
     self.assertEqual(Array([N(1), N(2), N(3), N(4)]), interpreter['_x'])
Example #12
0
    def test_add(self):
        test = '_x = [1, 2]; _y = [3, 4]; _z = _x + _y'
        _, outcome = interpret(test)

        self.assertEqual(Array([N(1), N(2), N(3), N(4)]), outcome)
Example #13
0
 def test_assign(self):
     interpreter, outcome = interpret('_x = [1, 2];')
     self.assertEqual(Array([N(1), N(2)]), interpreter['_x'])