also test array

minor (ahm) fixes to array logic
This commit is contained in:
Torsten Ruger 2015-05-12 19:03:14 +03:00
parent 398516a596
commit a94ce51c58
4 changed files with 26 additions and 26 deletions

View File

@ -24,7 +24,7 @@ end
class Parfait::Object class Parfait::Object
include FakeMem include FakeMem
def self.new_object *args def self.new_object *args
puts "I am #{self}" #puts "I am #{self}"
object = self.new(*args) object = self.new(*args)
object object
end end
@ -38,7 +38,7 @@ class Parfait::Object
@memory[index] = value @memory[index] = value
end end
def internal_object_grow(index) def internal_object_grow(index)
@memory[index] = niL @memory[index] = nil
end end
end end
class Parfait::Class class Parfait::Class

View File

@ -37,6 +37,7 @@ module Parfait
internal_object_grow(length) internal_object_grow(length)
while( index < self.length ) while( index < self.length )
internal_object_set( index , nil) internal_object_set( index , nil)
index += 1
end end
end end
#many basic array functions can not be defined in ruby, such as #many basic array functions can not be defined in ruby, such as

View File

@ -1,37 +1,36 @@
require_relative "../helper" require_relative "../helper"
class TestLists < MiniTest::Test class TestList < MiniTest::Test
def setup def setup
@list = ::Parfait::Hash.new @list = ::Parfait::Array.new_object
end end
def test_list_create def test_list_create
assert @list.empty? assert @list.empty?
end end
def test_empty_list_doesnt_return def test_empty_list_doesnt_return
assert_equal nil , @list.get(3) 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 end
def test_one_set1 def test_one_set1
assert_equal 1 , @list.set(1,1)
end
def test_one_set2
assert_equal :some , @list.set(1,:some) assert_equal :some , @list.set(1,:some)
end end
def test_two_sets 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) assert_equal :some , @list.set(1,:some)
end end
def test_one_get1 def test_one_get1
test_one_set1 test_one_set0
assert_equal 1 , @list.get(1) assert_equal 1 , @list.get(0)
end end
def test_one_get2 def test_one_get2
test_one_set2 test_one_set1
assert_equal :some , @list.get(1) assert_equal :some , @list.get(1)
end end
def test_many_get def test_many_get
shouldda = { :one => 1 , :two => 2 , :three => 3} shouldda = { 1 => :one , 2 => :two , 3 => :three}
shouldda.each do |k,v| shouldda.each do |k,v|
@list.set(k,v) @list.set(k,v)
end end

View File

@ -1,42 +1,42 @@
require_relative "../helper" require_relative "../helper"
class TestLists < MiniTest::Test class TestDictionary < MiniTest::Test
def setup def setup
@list = ::Parfait::Hash.new @lookup = ::Parfait::Hash.new
end end
def test_list_create def test_list_create
assert @list.empty? assert @lookup.empty?
end end
def test_empty_list_doesnt_return def test_empty_list_doesnt_return
assert_equal nil , @list.get(3) assert_equal nil , @lookup.get(3)
assert_equal nil , @list.get(:any) assert_equal nil , @lookup.get(:any)
end end
def test_one_set1 def test_one_set1
assert_equal 1 , @list.set(1,1) assert_equal 1 , @lookup.set(1,1)
end end
def test_one_set2 def test_one_set2
assert_equal :some , @list.set(1,:some) assert_equal :some , @lookup.set(1,:some)
end end
def test_two_sets def test_two_sets
assert_equal 1 , @list.set(1,1) assert_equal 1 , @lookup.set(1,1)
assert_equal :some , @list.set(1,:some) assert_equal :some , @lookup.set(1,:some)
end end
def test_one_get1 def test_one_get1
test_one_set1 test_one_set1
assert_equal 1 , @list.get(1) assert_equal 1 , @lookup.get(1)
end end
def test_one_get2 def test_one_get2
test_one_set2 test_one_set2
assert_equal :some , @list.get(1) assert_equal :some , @lookup.get(1)
end end
def test_many_get def test_many_get
shouldda = { :one => 1 , :two => 2 , :three => 3} shouldda = { :one => 1 , :two => 2 , :three => 3}
shouldda.each do |k,v| shouldda.each do |k,v|
@list.set(k,v) @lookup.set(k,v)
end end
shouldda.each do |k,v| shouldda.each do |k,v|
assert_equal v , @list.get(k) assert_equal v , @lookup.get(k)
end end
end end
end end