diff --git a/lib/parfait.rb b/lib/parfait.rb index 675ecf11..879db8bf 100644 --- a/lib/parfait.rb +++ b/lib/parfait.rb @@ -24,7 +24,7 @@ end class Parfait::Object include FakeMem def self.new_object *args - puts "I am #{self}" + #puts "I am #{self}" object = self.new(*args) object end @@ -38,7 +38,7 @@ class Parfait::Object @memory[index] = value end def internal_object_grow(index) - @memory[index] = niL + @memory[index] = nil end end class Parfait::Class diff --git a/lib/parfait/array.rb b/lib/parfait/array.rb index 5e55f98c..058679f6 100644 --- a/lib/parfait/array.rb +++ b/lib/parfait/array.rb @@ -37,6 +37,7 @@ module Parfait internal_object_grow(length) while( index < self.length ) internal_object_set( index , nil) + index += 1 end end #many basic array functions can not be defined in ruby, such as diff --git a/test/parfait/test_array.rb b/test/parfait/test_array.rb index 757d4937..675ec45b 100644 --- a/test/parfait/test_array.rb +++ b/test/parfait/test_array.rb @@ -1,37 +1,36 @@ require_relative "../helper" -class TestLists < MiniTest::Test +class TestList < MiniTest::Test def setup - @list = ::Parfait::Hash.new + @list = ::Parfait::Array.new_object end def test_list_create assert @list.empty? end def test_empty_list_doesnt_return assert_equal nil , @list.get(3) - assert_equal nil , @list.get(:any) + end + def test_one_set0 + assert_equal 1 , @list.set(0,1) end def test_one_set1 - assert_equal 1 , @list.set(1,1) - end - def test_one_set2 assert_equal :some , @list.set(1,:some) end def test_two_sets - assert_equal 1 , @list.set(1,1) + assert_equal 1 , @list.set(0,1) assert_equal :some , @list.set(1,:some) end def test_one_get1 - test_one_set1 - assert_equal 1 , @list.get(1) + test_one_set0 + assert_equal 1 , @list.get(0) end def test_one_get2 - test_one_set2 + test_one_set1 assert_equal :some , @list.get(1) end def test_many_get - shouldda = { :one => 1 , :two => 2 , :three => 3} + shouldda = { 1 => :one , 2 => :two , 3 => :three} shouldda.each do |k,v| @list.set(k,v) end diff --git a/test/parfait/test_hash.rb b/test/parfait/test_hash.rb index 757d4937..495cee3f 100644 --- a/test/parfait/test_hash.rb +++ b/test/parfait/test_hash.rb @@ -1,42 +1,42 @@ require_relative "../helper" -class TestLists < MiniTest::Test +class TestDictionary < MiniTest::Test def setup - @list = ::Parfait::Hash.new + @lookup = ::Parfait::Hash.new end def test_list_create - assert @list.empty? + assert @lookup.empty? end def test_empty_list_doesnt_return - assert_equal nil , @list.get(3) - assert_equal nil , @list.get(:any) + assert_equal nil , @lookup.get(3) + assert_equal nil , @lookup.get(:any) end def test_one_set1 - assert_equal 1 , @list.set(1,1) + assert_equal 1 , @lookup.set(1,1) end def test_one_set2 - assert_equal :some , @list.set(1,:some) + assert_equal :some , @lookup.set(1,:some) end def test_two_sets - assert_equal 1 , @list.set(1,1) - assert_equal :some , @list.set(1,:some) + assert_equal 1 , @lookup.set(1,1) + assert_equal :some , @lookup.set(1,:some) end def test_one_get1 test_one_set1 - assert_equal 1 , @list.get(1) + assert_equal 1 , @lookup.get(1) end def test_one_get2 test_one_set2 - assert_equal :some , @list.get(1) + assert_equal :some , @lookup.get(1) end def test_many_get shouldda = { :one => 1 , :two => 2 , :three => 3} shouldda.each do |k,v| - @list.set(k,v) + @lookup.set(k,v) end shouldda.each do |k,v| - assert_equal v , @list.get(k) + assert_equal v , @lookup.get(k) end end end