From 2e3b614c927f34fddfb82a768897559dd1e94966 Mon Sep 17 00:00:00 2001 From: chhavikirtani2000 <55941961+chhavikirtani2000@users.noreply.github.com> Date: Sat, 28 Mar 2020 18:57:29 +0530 Subject: [PATCH] review comments incorporated --- lib/parfait/word.rb | 12 ++++++------ test/parfait/test_word2.rb | 18 ++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/parfait/word.rb b/lib/parfait/word.rb index 1dd123c6..ecb4f5a6 100644 --- a/lib/parfait/word.rb +++ b/lib/parfait/word.rb @@ -13,7 +13,7 @@ module Parfait # Object length is measured in non-type cells though class Word < Data8 - attr_reader :char_length , :str, :prefix ,:next_word + attr_reader :char_length ,:next_word def self.type_length @@ -194,14 +194,14 @@ module Parfait end def start_with(other) return false if other.length > self.length - @str=self.to_string - @prefix=other.to_string - s = @str.size() + str=self.to_string + prefix=other.to_string + s = str.size() temp="" i=0 while i<=s-1 - temp=temp+@str[i] - if temp==@prefix + temp=temp+str[i] + if temp==prefix return true end i=i+1 diff --git a/test/parfait/test_word2.rb b/test/parfait/test_word2.rb index 9908d24e..cddc13e0 100644 --- a/test/parfait/test_word2.rb +++ b/test/parfait/test_word2.rb @@ -85,29 +85,27 @@ module Parfait assert one.compare(two) end - def test_start_with + 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) - #one = Parfait.new_word("hel") - #two = Parfait.new_word("hellooo") - #assert_equal false, one.start_with(two) - #one = Parfait.new_word("Vanilla") - #two = Parfait.new_word("vani") - #assert one.start_with(two) - #assert_equal true , @word.start_with("hello","hell") - #assert_equal true , @word.start_with("Adbfgsj","Adbf") - #assert_equal false , @word.start_with("Vanila","van") end + def test_first_char one = Parfait.new_word("one") one.set_char(0 , "T".ord)