[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[m8n] 50 KeyedCollection


-- setup
tuples=smalltalk.Array:new()
tuples:add_(smalltalk.Array:with_with_("one",1))
tuples:add_(smalltalk.Array:with_with_("two",2))
tuples:add_(smalltalk.Array:with_with_("four",4))
tuples:add_(smalltalk.Array:with_with_("ten",10))
test=smalltalk.Dictionary:fromTuples_(tuples)
dict=test
pool=smalltalk.PoolDictionary:fromTuples_(tuples)


--testing contents
if (test:isEmpty()) then error("Broken - Should have contents") end
if (test:size()~=tuples:size()) then error("Should have same size as tuples") end
if (pool:isEmpty()) then error("Broken - Should have contents") end
if (pool:size()~=tuples:size()) then error("Should have same size as tuples") end


--instance messages
if (not test:_eq(test)) then error("Must return true") end
if (not test:associations():eq_(pool:associations())) then error("Must have same contents") end


--handle nil key&values
pool:at_put_(nil,123)
pool:at_put_(123,nil)
if (not pool:includesKey_(nil)) then error("Must include nil as key") end
if (not pool:keys():includes_(nil)) then error("nil must be included in keys") end
if (not pool:values():includes_(nil)) then error("nil must be included in values") end
if (not test:at_ifAbsent_(123,function() return "missing" end)==nil) then error("Must have value nil at 123") end
test:at_put_(nil,123)
test:at_put_(123,nil)
if (not test:includesKey_(nil)) then error("Must include nil as key") end
if (not test:keys():includes_(nil)) then error("nil must be included in keys") end
if (not test:values():includes_(nil)) then error("nil must be included in values") end
if (not test:at_ifAbsent_(123,function() return "missing" end)==nil) then error("Must have value nil at 123") end


-- cleanup
test ,dict ,tuples ,pool = nil