2018-04-26 11:31:37 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
2016-12-31 14:17:45 +01:00
|
|
|
module Parfait
|
2018-04-26 11:31:37 +02:00
|
|
|
class TestEmptyWord < ParfaitTest
|
2015-05-15 15:45:36 +02:00
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
def setup
|
2018-07-01 13:12:42 +02:00
|
|
|
Parfait.boot!
|
2018-04-26 11:31:37 +02:00
|
|
|
@word = Parfait::Word.new(0)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_word_create
|
|
|
|
assert @word.empty?
|
|
|
|
end
|
|
|
|
def test_empty_is_zero
|
|
|
|
assert_equal 0 , @word.length
|
|
|
|
end
|
|
|
|
def test_empty_is_zero_internal
|
|
|
|
assert_equal 0 , @word.char_length
|
|
|
|
end
|
|
|
|
def test_index_check_get
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
@word.get_char(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_index_check_set
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
@word.set_char(1 , 32)
|
|
|
|
end
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-26 11:31:37 +02:00
|
|
|
class TestWord < ParfaitTest
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@word = Parfait::Word.new(5)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_len
|
|
|
|
assert_equal 5 , @word.length
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_len_internal
|
|
|
|
assert_equal 5 , @word.char_length
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_first_char
|
|
|
|
assert_equal 32 , @word.get_char(1)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_equals_copy
|
|
|
|
assert_equal @word.copy , @word
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2018-04-26 11:31:37 +02:00
|
|
|
def test_equals_copy2
|
2018-05-14 10:55:01 +02:00
|
|
|
@word.set_char(0 , 2)
|
|
|
|
@word.set_char(4 , 6)
|
2018-04-26 11:31:37 +02:00
|
|
|
assert_equal @word.copy , @word
|
|
|
|
end
|
|
|
|
def test_equals_same
|
|
|
|
assert_equal ::Parfait::Word.new(5) , @word
|
|
|
|
end
|
|
|
|
def test_index_check_get
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
@word.get_char(-6)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_index_check_set
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
@word.set_char(6 , 32)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_index_check_get
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
@word.get_char(6)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_index_check_set
|
|
|
|
assert_raises RuntimeError do
|
|
|
|
@word.set_char(-6 , 32)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_one_char
|
|
|
|
assert_equal 32 , @word.set_char(1 , 32)
|
|
|
|
end
|
|
|
|
def test_one_char_doesnt_cause_problems
|
|
|
|
@word.set_char(1 , 32)
|
|
|
|
assert_equal 32 , @word.get_char(1)
|
|
|
|
end
|
|
|
|
def test_one_set1
|
|
|
|
assert_equal 44 , @word.set_char(1, 44 )
|
|
|
|
end
|
|
|
|
def test_two_sets
|
|
|
|
assert_equal 1 , @word.set_char(1,1)
|
|
|
|
assert_equal 44 , @word.set_char(1,44)
|
|
|
|
end
|
|
|
|
def test_one_get1
|
|
|
|
test_one_set1
|
|
|
|
assert_equal 44 , @word.get_char(1)
|
|
|
|
end
|
|
|
|
def test_many_get
|
|
|
|
shouldda = { 1 => 11 , 2 => 22 , 3 => 33}
|
|
|
|
shouldda.each do |k,v|
|
|
|
|
@word.set_char(k,v)
|
|
|
|
end
|
|
|
|
shouldda.each do |k,v|
|
|
|
|
assert_equal v , @word.get_char(k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_not_same
|
|
|
|
one = Parfait.new_word("one")
|
|
|
|
two = Parfait.new_word("two")
|
|
|
|
assert !one.compare(two)
|
|
|
|
end
|
|
|
|
def test_is_same
|
|
|
|
one = Parfait.new_word("one")
|
|
|
|
two = Parfait.new_word("one")
|
|
|
|
assert one.compare(two)
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
2018-05-15 15:25:55 +02:00
|
|
|
def test_first_char
|
|
|
|
one = Parfait.new_word("one")
|
|
|
|
one.set_char(0 , "T".ord)
|
|
|
|
assert_equal "Tne" , one.to_string
|
|
|
|
end
|
|
|
|
def test_sec_char
|
|
|
|
one = Parfait.new_word("one")
|
|
|
|
one.set_char(1 , "m".ord)
|
|
|
|
assert_equal "ome" , one.to_string
|
|
|
|
end
|
|
|
|
def test_more_char
|
|
|
|
one = Parfait.new_word("one")
|
|
|
|
assert_raises {one.set_char(3 , "s".ord)}
|
|
|
|
end
|
2015-05-15 15:45:36 +02:00
|
|
|
end
|
|
|
|
end
|