also test array
minor (ahm) fixes to array logic
This commit is contained in:
parent
398516a596
commit
a94ce51c58
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user