more parfait ripples

changes due to previous changes in parfait api
This commit is contained in:
Torsten Ruger 2015-05-18 10:10:31 +03:00
parent d52cd82c92
commit d348e7afe7
6 changed files with 20 additions and 20 deletions

View File

@ -72,16 +72,16 @@ module Parfait
string = string.to_s if string.is_a? Symbol
word = Parfait::Word.new( string.length )
string.codepoints.each_with_index do |code , index |
word.set_char(index , code)
word.set_char(index + 1 , code)
end
word
end
def self.new_list array
list = List.new_object
list.set_length array.length
index = 0
index = 1
while index < array.length do
list.set(index , array[index])
list.set(index , array[index - 1])
end
list
end
@ -89,9 +89,9 @@ module Parfait
Word.class_eval do
def to_s
string = ""
index = 0
while( index < self.length)
string[index] = get_char(index).chr
index = 1
while( index <= self.length)
string[index - 1] = get_char(index).chr
index = index + 1
end
string

View File

@ -26,9 +26,9 @@ module Parfait
# set the names of the instance variables in one go
# used while booting the classes. At runtime the list would grow dynamically
def set_names list
self.set_length list.length
self.set_length list.get_length
index = 0
while index < list.length do
while index < list.get_length do
list.set(index , array.get(index))
end
end

View File

@ -79,7 +79,7 @@ module Parfait
end
def grow_to(len)
raise "Only positive lenths, #{len}" if len <= 0
raise "Only positive lenths, #{len}" if len < 0
old_length = self.get_length
return if old_length >= len
internal_object_grow(len + 1)

View File

@ -37,7 +37,7 @@ module Parfait
def get_layout()
puts "ME #{self.class}"
return internal_object_get(LAYOUT)
return internal_object_get(LAYOUT_INDEX)
end
# class stores the "latest" layout for instances, ie the layout a new object will

View File

@ -37,6 +37,7 @@ module Parfait
counter = self.length()
return if counter >= len
internal_object_grow( len + 1)
counter = counter + 1
while( counter < len)
set_char( counter , fill_char)
counter = counter + 1
@ -57,7 +58,8 @@ module Parfait
def range_correct_index at
index = at
index = self.length + at if at < 0
raise "index out of bounds #{at} > #{self.length}" if (index < 0) or (index > self.length)
raise "index must be positive , not #{at}" if (index <= 0)
raise "index too large #{at} > #{self.length}" if (index > self.length)
return index
end

View File

@ -5,9 +5,6 @@ class TestEmptyWord < MiniTest::Test
def setup
@word = ::Parfait::Word.new_object(0)
end
def def_same
assert_equal @word , ::Parfait::Word.new_object(0)
end
def test_word_create
assert @word.empty?
end
@ -16,7 +13,7 @@ class TestEmptyWord < MiniTest::Test
end
def test_index_check_get
assert_raises RuntimeError do
@word.get_char(1)
@word.get_char(0)
end
end
def test_index_check_set
@ -33,9 +30,6 @@ class TestWord < MiniTest::Test
def test_len
assert_equal 5 , @word.length
end
def def_same
assert_equal @word , ::Parfait::Word.new_object(5)
end
def test_index_check_get
assert_raises RuntimeError do
@word.get_char(-6)
@ -56,8 +50,12 @@ class TestWord < MiniTest::Test
@word.set_char(-6 , 32)
end
end
def pest_one_char
assert 32 , @word.set_char(1 , 32)
def test_one_char
assert_equal 32 , @word.set_char(1 , 32)
end
def test_one_char_doesnt_cuase_problems
@word.set_char(1 , 32)
assert_equal 32 , @word.get_char(1)
end
def pest_empty_word_doesnt_return
assert_equal nil , @word.get(3)