2021-12-09 09:13:17 +01:00
|
|
|
# coding: utf-8
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-02-17 15:09:29 +01:00
|
|
|
require 'minitest/autorun'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-15 17:06:19 +01:00
|
|
|
require 'rpl'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-17 15:09:29 +01:00
|
|
|
class TestLanguageTest < MiniTest::Test
|
2021-12-09 09:13:17 +01:00
|
|
|
def test_greater_than
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '0 0.1 >'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '0.1 0 >'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '1 1 >'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_greater_than_or_equal
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '0 0.1 >='
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '0.1 0 ≥'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '1 1 ≥'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_less_than
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '0 0.1 <'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '0.1 0 <'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '1 1 <'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_less_than_or_equal
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '0 0.1 <='
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '0.1 0 ≤'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '1 1 ≤'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_different
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '1 1 !='
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '1 2 ≠'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_and
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'true true and'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'false false and'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'true false and'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'false true and'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_or
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'true true or'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'false false or'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'true false or'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'false true or'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_xor
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'true true xor'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'false false xor'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'true false xor'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'false true xor'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_not
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'true not'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'false not'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_same
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '1 1 same'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '1 2 =='
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_true
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'true'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: true, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_false
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run 'false'
|
2021-12-09 09:13:17 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: false, type: :boolean }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-09 09:13:17 +01:00
|
|
|
end
|
|
|
|
end
|