2021-11-10 16:20:47 +01:00
|
|
|
# coding: utf-8
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
|
2021-12-07 16:46:33 +01:00
|
|
|
require_relative '../language'
|
2021-11-10 16:20:47 +01:00
|
|
|
|
2021-11-23 13:00:42 +01:00
|
|
|
class TestLanguageStack < Test::Unit::TestCase
|
2021-11-10 16:20:47 +01:00
|
|
|
def test_swap
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 swap'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
assert_equal [{ value: 2, type: :numeric, base: 10 },
|
|
|
|
{ value: 1, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_drop
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 drop'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_drop2
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 drop2'
|
|
|
|
|
2021-11-10 16:20:47 +01:00
|
|
|
assert_equal [],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dropn
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 3 4 3 dropn'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
assert_equal [{ value: 1, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_del
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 del'
|
|
|
|
|
|
|
|
assert_empty lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rot
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 3 rot'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
assert_equal [{ value: 2, type: :numeric, base: 10 },
|
|
|
|
{ value: 3, type: :numeric, base: 10 },
|
|
|
|
{ value: 1, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dup
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 dup'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
assert_equal [{ value: 1, type: :numeric, base: 10 },
|
|
|
|
{ value: 2, type: :numeric, base: 10 },
|
|
|
|
{ value: 2, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dup2
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 dup2'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
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 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dupn
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 3 4 3 dupn'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
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 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_pick
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 3 4 3 pick'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
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 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_depth
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run 'depth'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
assert_equal [{ value: 0, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
|
|
|
|
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 depth'
|
2021-11-10 16:20:47 +01:00
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
assert_equal [{ value: 1, type: :numeric, base: 10 },
|
|
|
|
{ value: 2, type: :numeric, base: 10 },
|
|
|
|
{ value: 2, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_roll
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 3 4 3 roll'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
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 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rolld
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 4 3 2 rolld'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
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 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_over
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '1 2 3 4 over'
|
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
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 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-10 16:20:47 +01:00
|
|
|
end
|
|
|
|
end
|