diff --git a/lib/parfait/word.rb b/lib/parfait/word.rb index 3df5a856..15e0e3d6 100644 --- a/lib/parfait/word.rb +++ b/lib/parfait/word.rb @@ -13,7 +13,8 @@ module Parfait # Object length is measured in non-type cells though class Word < Data8 - attr_reader :char_length , :next_word + attr_reader :char_length ,:next_word + def self.type_length 3 # 0 type , 1 char_length , next_word @@ -199,23 +200,36 @@ module Parfait str_ind=0 while ( str_ind self.length + s = other.length + i=0 + while i<=s-1 + if other.get_char(i) != self.get_char(i) + return false + end + i=i+1 + end + return true + end + private def check_length raise "Length out of bounds #{char_length}" if @char_length > 1000 diff --git a/test/parfait/test_word2.rb b/test/parfait/test_word2.rb index fc8e2e23..cddc13e0 100644 --- a/test/parfait/test_word2.rb +++ b/test/parfait/test_word2.rb @@ -6,6 +6,7 @@ module Parfait super @word = Parfait::Word.new(5) end + def test_len assert_equal 5 , @word.length end @@ -83,6 +84,28 @@ module Parfait two = Parfait.new_word("one") assert one.compare(two) end + + def test_start_with1 + one = Parfait.new_word("Hello") + two = Parfait.new_word("Hel") + assert one.start_with(two) + end + def test_start_with2 + one = Parfait.new_word("Vanilla") + two = Parfait.new_word("Va") + assert one.start_with(two) + end + def test_start_with3 + one = Parfait.new_word("hello") + two = Parfait.new_word("hellooo") + assert_equal false, one.start_with(two) + end + def test_start_with4 + one = Parfait.new_word("bajjs") + two = Parfait.new_word("bgjj") + assert_equal false, one.start_with(two) + end + def test_first_char one = Parfait.new_word("one") one.set_char(0 , "T".ord)