2021-11-10 16:20:47 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-02-17 15:09:29 +01:00
|
|
|
require 'minitest/autorun'
|
2021-11-10 16:20:47 +01:00
|
|
|
|
2022-02-15 17:06:19 +01:00
|
|
|
require 'rpl'
|
2021-11-10 16:20:47 +01:00
|
|
|
|
2024-03-27 08:08:43 +01:00
|
|
|
class TestLanguageStack < Minitest::Test
|
2022-02-26 18:53:39 +01:00
|
|
|
include Types
|
|
|
|
|
2021-11-10 16:20:47 +01:00
|
|
|
def test_swap
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 swap'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 2 ),
|
|
|
|
Types.new_object( RplNumeric, 1 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_drop
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 drop'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 1 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_drop2
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 drop2'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2021-11-10 16:20:47 +01:00
|
|
|
assert_equal [],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dropn
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 3 4 3 dropn'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 1 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_del
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 del'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-09 13:38:32 +01:00
|
|
|
assert_empty interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rot
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 3 rot'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 2 ),
|
|
|
|
Types.new_object( RplNumeric, 3 ),
|
|
|
|
Types.new_object( RplNumeric, 1 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dup
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 dup'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 1 ),
|
|
|
|
Types.new_object( RplNumeric, 2 ),
|
|
|
|
Types.new_object( RplNumeric, 2 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dup2
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 dup2'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 1 ),
|
|
|
|
Types.new_object( RplNumeric, 2 ),
|
|
|
|
Types.new_object( RplNumeric, 1 ),
|
|
|
|
Types.new_object( RplNumeric, 2 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dupn
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 3 4 3 dupn'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 1 ),
|
|
|
|
Types.new_object( RplNumeric, 2 ),
|
|
|
|
Types.new_object( RplNumeric, 3 ),
|
|
|
|
Types.new_object( RplNumeric, 4 ),
|
|
|
|
Types.new_object( RplNumeric, 2 ),
|
|
|
|
Types.new_object( RplNumeric, 3 ),
|
|
|
|
Types.new_object( RplNumeric, 4 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_pick
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 3 4 3 pick'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 1 ),
|
|
|
|
Types.new_object( RplNumeric, 2 ),
|
|
|
|
Types.new_object( RplNumeric, 3 ),
|
|
|
|
Types.new_object( RplNumeric, 4 ),
|
|
|
|
Types.new_object( RplNumeric, 2 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_depth
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! 'depth'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 0 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 depth'
|
2021-11-10 16:20:47 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 1 ),
|
|
|
|
Types.new_object( RplNumeric, 2 ),
|
|
|
|
Types.new_object( RplNumeric, 2 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_roll
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 3 4 3 roll'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 1 ),
|
|
|
|
Types.new_object( RplNumeric, 3 ),
|
|
|
|
Types.new_object( RplNumeric, 4 ),
|
|
|
|
Types.new_object( RplNumeric, 2 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rolld
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 4 3 2 rolld'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 1 ),
|
|
|
|
Types.new_object( RplNumeric, 2 ),
|
|
|
|
Types.new_object( RplNumeric, 3 ),
|
|
|
|
Types.new_object( RplNumeric, 4 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_over
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '1 2 3 4 over'
|
2021-12-08 16:08:49 +01:00
|
|
|
|
2022-02-28 11:40:47 +01:00
|
|
|
assert_equal [Types.new_object( RplNumeric, 1 ),
|
|
|
|
Types.new_object( RplNumeric, 2 ),
|
|
|
|
Types.new_object( RplNumeric, 3 ),
|
|
|
|
Types.new_object( RplNumeric, 4 ),
|
|
|
|
Types.new_object( RplNumeric, 3 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
end
|