rpl.rb/spec/language_stack_spec.rb

159 lines
6.7 KiB
Ruby
Raw Normal View History

# coding: utf-8
# frozen_string_literal: true
require 'test/unit'
require_relative '../lib/core'
2021-11-23 13:00:42 +01:00
class TestLanguageStack < Test::Unit::TestCase
def test_swap
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.swap [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }]
assert_equal [{ value: 2, type: :numeric, base: 10 },
{ value: 1, type: :numeric, base: 10 }],
stack
end
def test_drop
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.drop [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }]
assert_equal [{ value: 1, type: :numeric, base: 10 }],
stack
end
def test_drop2
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.drop2 [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }]
assert_equal [],
stack
end
def test_dropn
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.dropn [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 }]
assert_equal [{ value: 1, type: :numeric, base: 10 }],
stack
end
def test_del
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.del [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }]
assert_equal [],
stack
end
def test_rot
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.rot [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 }]
assert_equal [{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 1, type: :numeric, base: 10 }],
stack
end
def test_dup
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.dup [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }]
assert_equal [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }],
stack
end
def test_dup2
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.dup2 [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }]
assert_equal [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }],
stack
end
def test_dupn
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.dupn [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 }]
assert_equal [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 }],
stack
end
def test_pick
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.pick [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 }]
assert_equal [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }],
stack
end
def test_depth
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.depth []
assert_equal [{ value: 0, type: :numeric, base: 10 }],
stack
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.depth [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }]
assert_equal [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }],
stack
end
def test_roll
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.roll [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 }]
assert_equal [{ value: 1, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }],
stack
end
def test_rolld
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.rolld [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 }]
assert_equal [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 }],
stack
end
def test_over
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.over [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 }]
assert_equal [{ value: 1, type: :numeric, base: 10 },
{ value: 2, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 },
{ value: 3, type: :numeric, base: 10 }],
stack
end
end