rpl.rb/spec/language_test_spec.rb

225 lines
5.1 KiB
Ruby
Raw Normal View History

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
interpreter.run '0 0.1 >'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '0.1 0 >'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '1 1 >'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
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
interpreter.run '0 0.1 >='
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '0.1 0 ≥'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '1 1 ≥'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
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
interpreter.run '0 0.1 <'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '0.1 0 <'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '1 1 <'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
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
interpreter.run '0 0.1 <='
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '0.1 0 ≤'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '1 1 ≤'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
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
interpreter.run '1 1 !='
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '1 2 ≠'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
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
interpreter.run 'true true and'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run 'false false and'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run 'true false and'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run 'false true and'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
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
interpreter.run 'true true or'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run 'false false or'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run 'true false or'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run 'false true or'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
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
interpreter.run 'true true xor'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run 'false false xor'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run 'true false xor'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run 'false true xor'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
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
interpreter.run 'true not'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run 'false not'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
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
interpreter.run '1 1 same'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '1 2 =='
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
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
interpreter.run 'true'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: true, type: :boolean }],
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
interpreter.run 'false'
2021-12-09 09:13:17 +01:00
assert_equal [{ value: false, type: :boolean }],
interpreter.stack
2021-12-09 09:13:17 +01:00
end
end