-- $LastChangedDate: 2008-12-15 21:02:55 -0600 (Mon, 15 Dec 2008) $
-- This tests lib.Iterator()/IteratorAfter().

-- Compile NewInstance()/DerivedClass().
dofile( "../lib.lua" )

t = {}
t.a = 1
t.b = 1
t.c = 1

print( "Testing lib.Iterator() basic case." )
u = {}
for k,v in lib.Iterator(t,"a") do
	u[k] = v
end
assert( u.a == t.a and u.b == t.b and u.c == t.c )
print( "ok" )

-- Order is undefined.
-- An indirect way to test is by summing.
-- 1,1,1
-- 1,1
-- 1
-- sum = 6
print( "Testing lib.Iterator() multiple cases." )
sum = 0
for k,v in lib.Iterator(t,"a") do
	sum = sum + 1
end
for k,v in lib.Iterator(t,"b") do
	sum = sum + 1
end
for k,v in lib.Iterator(t,"c") do
	sum = sum + 1
end
assert( sum == 6 )
print( "ok" )

-------------------------------------------------------------------------------
-- Test lib.IteratorAfter()

print( "Testing lib.IteratorAfter() with empty table." )
t = {}
for k in lib.IteratorAfter( t ) do
	assert( false )
end
print( "ok" )

print( "Testing lib.IteratorAfter() with one-element table." )
t = {}
t.a = 1
for k in lib.IteratorAfter( t, "a" ) do
	assert( false )
end
print( "ok" )

-- Although order is undefined, pretent it is, then:
-- a: 1,1
-- b: 1
-- c: none
-- sum = 3
print( "Testing lib.IteratorAfter() with two-element table." )
t = {}
t.a = 1
t.b = 1
t.c = 1
sum = 0
for k in lib.IteratorAfter( t, "a" ) do
	sum = sum + 1
end
for k in lib.IteratorAfter( t, "b" ) do
	sum = sum + 1
end
for k in lib.IteratorAfter( t, "c" ) do
	sum = sum + 1
end
assert( sum == 3 )
print( "ok" )
