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'])
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'])
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)
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'])
def test_find(self): _, outcome = interpret('"Hello world!" find "world!"') self.assertEqual(N(6), outcome)
def test_while(self): interpreter, outcome = interpret( '_x = 0; while {_x != 10} do {_x = _x + 1};') self.assertEqual(N(10), interpreter['_x'])
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)
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'])
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)
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)
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'])
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)
def test_assign(self): interpreter, outcome = interpret('_x = [1, 2];') self.assertEqual(Array([N(1), N(2)]), interpreter['_x'])