final word fix

that does the parfait
This commit is contained in:
Torsten Ruger 2015-05-17 15:34:45 +03:00
parent e70bfb9f7a
commit cff827ad42
2 changed files with 8 additions and 8 deletions

View File

@ -20,11 +20,11 @@ module Parfait
super()
raise "Must init with int, not #{len.class}" unless len.kind_of? Fixnum
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
def length()
obj_len = internal_object_length
obj_len = internal_object_length - 1
return obj_len
end
@ -33,10 +33,10 @@ module Parfait
end
def set_length(len , fill_char)
return if len < 0
return if len <= 0
counter = self.length()
return if counter >= len
internal_object_grow( len )
internal_object_grow( len + 1)
while( counter < len)
set_char( counter , fill_char)
counter = counter + 1
@ -46,12 +46,12 @@ module Parfait
def set_char at , char
raise "char not fixnum #{char}" unless char.kind_of? Fixnum
index = range_correct_index(at)
internal_object_set( index , char )
internal_object_set( index + 1 , char )
end
def get_char at
index = range_correct_index(at)
return internal_object_get(index)
return internal_object_get(index + 1)
end
def range_correct_index at

View File

@ -8,7 +8,7 @@ class TestEmptyWord < MiniTest::Test
def def_same
assert_equal @word , ::Parfait::Word.new_object(0)
end
def test_list_create
def test_word_create
assert @word.empty?
end
def test_empty_is_zero
@ -59,7 +59,7 @@ class TestWord < MiniTest::Test
def pest_one_char
assert 32 , @word.set_char(1 , 32)
end
def pest_empty_list_doesnt_return
def pest_empty_word_doesnt_return
assert_equal nil , @word.get(3)
end
def pest_one_set0