rubyx/test/parfait/test_word.rb

93 lines
1.9 KiB
Ruby
Raw Normal View History

require_relative "../helper"
class TestEmptyWord < MiniTest::Test
def setup
2015-05-15 19:31:43 +02:00
@word = ::Parfait::Word.new_object(0)
end
def def_same
assert_equal @word , ::Parfait::Word.new_object(0)
end
def test_list_create
2015-05-15 19:31:43 +02:00
assert @word.empty?
end
def test_empty_is_zero
2015-05-15 19:31:43 +02:00
assert_equal 0 , @word.length
end
def test_index_check_get
assert_raises RuntimeError do
2015-05-15 19:31:43 +02:00
@word.get_char(1)
end
end
def test_index_check_set
assert_raises RuntimeError do
2015-05-15 19:31:43 +02:00
@word.set_char(1 , 32)
end
end
end
class TestWord < MiniTest::Test
def setup
2015-05-15 19:31:43 +02:00
@word = ::Parfait::Word.new_object(5)
end
def test_len
2015-05-15 19:31:43 +02:00
assert_equal 5 , @word.length
end
def def_same
assert_equal @word , ::Parfait::Word.new_object(5)
end
def test_index_check_get
assert_raises RuntimeError do
2015-05-15 19:31:43 +02:00
@word.get_char(-6)
end
end
def test_index_check_set
assert_raises RuntimeError do
2015-05-15 19:31:43 +02:00
@word.set_char(6 , 32)
end
end
def test_index_check_get
assert_raises RuntimeError do
2015-05-15 19:31:43 +02:00
@word.get_char(6)
end
end
def test_index_check_set
assert_raises RuntimeError do
2015-05-15 19:31:43 +02:00
@word.set_char(-6 , 32)
end
end
def pest_one_char
2015-05-15 19:31:43 +02:00
assert 32 , @word.set_char(1 , 32)
end
def pest_empty_list_doesnt_return
2015-05-15 19:31:43 +02:00
assert_equal nil , @word.get(3)
end
def pest_one_set0
2015-05-15 19:31:43 +02:00
assert_equal 1 , @word.set(0,1)
end
def pest_one_set1
2015-05-15 19:31:43 +02:00
assert_equal :some , @word.set(1,:some)
end
def pest_two_sets
2015-05-15 19:31:43 +02:00
assert_equal 1 , @word.set(0,1)
assert_equal :some , @word.set(1,:some)
end
def pest_one_get1
pest_one_set0
2015-05-15 19:31:43 +02:00
assert_equal 1 , @word.get(0)
end
def pest_one_get2
pest_one_set1
2015-05-15 19:31:43 +02:00
assert_equal :some , @word.get(1)
end
def pest_many_get
shouldda = { 1 => :one , 2 => :two , 3 => :three}
shouldda.each do |k,v|
2015-05-15 19:31:43 +02:00
@word.set(k,v)
end
shouldda.each do |k,v|
2015-05-15 19:31:43 +02:00
assert_equal v , @word.get(k)
end
end
end