review comments incorporated

This commit is contained in:
chhavikirtani2000 2020-03-28 16:54:29 +05:30 committed by Torsten Rüger
parent c477e90c45
commit fa28475b71
2 changed files with 32 additions and 9 deletions

View File

@ -192,16 +192,19 @@ module Parfait
def padded_length def padded_length
Object.padded( 4 * get_type().instance_length + @char_length ) Object.padded( 4 * get_type().instance_length + @char_length )
end end
def start_with(str1,prefix1) def start_with(other)
@str=str1 return false if other.length > self.length
@prefix=prefix1 @str=self.to_string
@prefix=other.to_string
s = @str.size() s = @str.size()
temp="" temp=""
for i in 0..s-1 i=0
while i<=s-1
temp=temp+@str[i] temp=temp+@str[i]
if temp==@prefix if temp==@prefix
return true return true
end end
i=i+1
end end
return false return false
end end

View File

@ -6,11 +6,7 @@ module Parfait
super super
@word = Parfait::Word.new(5) @word = Parfait::Word.new(5)
end end
def test_start_with
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_len def test_len
assert_equal 5 , @word.length assert_equal 5 , @word.length
end end
@ -88,6 +84,30 @@ module Parfait
two = Parfait.new_word("one") two = Parfait.new_word("one")
assert one.compare(two) assert one.compare(two)
end end
def test_start_with
one = Parfait.new_word("Hello")
two = Parfait.new_word("Hel")
assert one.start_with(two)
one = Parfait.new_word("Vanilla")
two = Parfait.new_word("Va")
assert one.start_with(two)
one = Parfait.new_word("hello")
two = Parfait.new_word("hellooo")
assert_equal false, one.start_with(two)
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 def test_first_char
one = Parfait.new_word("one") one = Parfait.new_word("one")
one.set_char(0 , "T".ord) one.set_char(0 , "T".ord)