final word fix
that does the parfait
This commit is contained in:
parent
e70bfb9f7a
commit
cff827ad42
@ -20,11 +20,11 @@ module Parfait
|
|||||||
super()
|
super()
|
||||||
raise "Must init with int, not #{len.class}" unless len.kind_of? Fixnum
|
raise "Must init with int, not #{len.class}" unless len.kind_of? Fixnum
|
||||||
raise "Must init with positive, not #{len}" if len < 0
|
raise "Must init with positive, not #{len}" if len < 0
|
||||||
set_length( len - 1, 32 ) unless len == 0
|
set_length( len , 32 ) unless len == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def length()
|
def length()
|
||||||
obj_len = internal_object_length
|
obj_len = internal_object_length - 1
|
||||||
return obj_len
|
return obj_len
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -33,10 +33,10 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_length(len , fill_char)
|
def set_length(len , fill_char)
|
||||||
return if len < 0
|
return if len <= 0
|
||||||
counter = self.length()
|
counter = self.length()
|
||||||
return if counter >= len
|
return if counter >= len
|
||||||
internal_object_grow( len )
|
internal_object_grow( len + 1)
|
||||||
while( counter < len)
|
while( counter < len)
|
||||||
set_char( counter , fill_char)
|
set_char( counter , fill_char)
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
@ -46,12 +46,12 @@ module Parfait
|
|||||||
def set_char at , char
|
def set_char at , char
|
||||||
raise "char not fixnum #{char}" unless char.kind_of? Fixnum
|
raise "char not fixnum #{char}" unless char.kind_of? Fixnum
|
||||||
index = range_correct_index(at)
|
index = range_correct_index(at)
|
||||||
internal_object_set( index , char )
|
internal_object_set( index + 1 , char )
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_char at
|
def get_char at
|
||||||
index = range_correct_index(at)
|
index = range_correct_index(at)
|
||||||
return internal_object_get(index)
|
return internal_object_get(index + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def range_correct_index at
|
def range_correct_index at
|
||||||
|
@ -8,7 +8,7 @@ class TestEmptyWord < MiniTest::Test
|
|||||||
def def_same
|
def def_same
|
||||||
assert_equal @word , ::Parfait::Word.new_object(0)
|
assert_equal @word , ::Parfait::Word.new_object(0)
|
||||||
end
|
end
|
||||||
def test_list_create
|
def test_word_create
|
||||||
assert @word.empty?
|
assert @word.empty?
|
||||||
end
|
end
|
||||||
def test_empty_is_zero
|
def test_empty_is_zero
|
||||||
@ -59,7 +59,7 @@ class TestWord < MiniTest::Test
|
|||||||
def pest_one_char
|
def pest_one_char
|
||||||
assert 32 , @word.set_char(1 , 32)
|
assert 32 , @word.set_char(1 , 32)
|
||||||
end
|
end
|
||||||
def pest_empty_list_doesnt_return
|
def pest_empty_word_doesnt_return
|
||||||
assert_equal nil , @word.get(3)
|
assert_equal nil , @word.get(3)
|
||||||
end
|
end
|
||||||
def pest_one_set0
|
def pest_one_set0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user