2015-05-15 15:45:36 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
class TestEmptyWord < MiniTest::Test
|
|
|
|
|
|
|
|
def setup
|
2015-05-15 19:31:43 +02:00
|
|
|
@word = ::Parfait::Word.new_object(0)
|
|
|
|
end
|
2015-05-17 14:34:45 +02:00
|
|
|
def test_word_create
|
2015-05-15 19:31:43 +02:00
|
|
|
assert @word.empty?
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
def test_empty_is_zero
|
2015-05-15 19:31:43 +02:00
|
|
|
assert_equal 0 , @word.length
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
def test_index_check_get
|
|
|
|
assert_raises RuntimeError do
|
2015-05-18 09:10:31 +02:00
|
|
|
@word.get_char(0)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_index_check_set
|
|
|
|
assert_raises RuntimeError do
|
2015-05-15 19:31:43 +02:00
|
|
|
@word.set_char(1 , 32)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class TestWord < MiniTest::Test
|
|
|
|
|
|
|
|
def setup
|
2015-05-15 19:31:43 +02:00
|
|
|
@word = ::Parfait::Word.new_object(5)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
def test_len
|
2015-05-15 19:31:43 +02:00
|
|
|
assert_equal 5 , @word.length
|
|
|
|
end
|
2015-05-20 12:50:25 +02:00
|
|
|
def test_first_char
|
|
|
|
assert_equal 32 , @word.get_char(1)
|
|
|
|
end
|
|
|
|
def test_equals_copy
|
|
|
|
assert_equal @word.copy , @word
|
|
|
|
end
|
|
|
|
def test_equals_copy2
|
|
|
|
@word.set_char(1 , 2)
|
|
|
|
@word.set_char(5 , 6)
|
|
|
|
assert_equal @word.copy , @word
|
|
|
|
end
|
|
|
|
def test_equals_same
|
|
|
|
assert_equal ::Parfait::Word.new_object(5) , @word
|
|
|
|
end
|
2015-05-15 15:45:36 +02:00
|
|
|
def test_index_check_get
|
|
|
|
assert_raises RuntimeError do
|
2015-05-15 19:31:43 +02:00
|
|
|
@word.get_char(-6)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_index_check_set
|
|
|
|
assert_raises RuntimeError do
|
2015-05-15 19:31:43 +02:00
|
|
|
@word.set_char(6 , 32)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_index_check_get
|
|
|
|
assert_raises RuntimeError do
|
2015-05-15 19:31:43 +02:00
|
|
|
@word.get_char(6)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_index_check_set
|
|
|
|
assert_raises RuntimeError do
|
2015-05-15 19:31:43 +02:00
|
|
|
@word.set_char(-6 , 32)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
end
|
2015-05-18 09:10:31 +02:00
|
|
|
def test_one_char
|
|
|
|
assert_equal 32 , @word.set_char(1 , 32)
|
|
|
|
end
|
2015-05-20 12:50:25 +02:00
|
|
|
def test_one_char_doesnt_cause_problems
|
2015-05-18 09:10:31 +02:00
|
|
|
@word.set_char(1 , 32)
|
|
|
|
assert_equal 32 , @word.get_char(1)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2015-05-20 12:50:25 +02:00
|
|
|
def test_one_set1
|
|
|
|
assert_equal 44 , @word.set_char(1, 44 )
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2015-05-20 12:50:25 +02:00
|
|
|
def test_two_sets
|
|
|
|
assert_equal 1 , @word.set_char(1,1)
|
|
|
|
assert_equal 44 , @word.set_char(1,44)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2015-05-20 12:50:25 +02:00
|
|
|
def test_one_get1
|
|
|
|
test_one_set1
|
|
|
|
assert_equal 44 , @word.get_char(1)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2015-05-20 12:50:25 +02:00
|
|
|
def test_many_get
|
|
|
|
shouldda = { 1 => 11 , 2 => 22 , 3 => 33}
|
2015-05-15 15:45:36 +02:00
|
|
|
shouldda.each do |k,v|
|
2015-05-20 12:50:25 +02:00
|
|
|
@word.set_char(k,v)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
shouldda.each do |k,v|
|
2015-05-20 12:50:25 +02:00
|
|
|
assert_equal v , @word.get_char(k)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|