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

test[m8n] 50 Sorting


-- sorting arrays & sets
if (smalltalk.Object:selectors():sorted():isNil()) then error("Wrong sorted result") end
if (smalltalk.Array:with_with_with_with_(1,4,2,4):asSet():sorted():asLiteral()~="#( 1 2 4 )") then error("Wrong sort result") end
if (smalltalk.Array:with_with_with_with_(1,44,2,1111):sorted():asLiteral()~="#( 1 2 44 1111 )") then error("Failed sorting numbers") end
if (smalltalk.Array:with_with_with_with_("1","44","2","1111"):sorted():asLiteral()~="#( 1 1111 2 44 )") then error("Failed sorting strings") end


--collecting implemented messages
all=smalltalk.Set:new()
smalltalk.Object:withAllSubclasses():do_(function(cls) all:addAll_(cls:selectors()); all:addAll_(cls:class():selectors()) end)
print("There are "..all:size().." messages implemented in the system")
print(all:sorted():asLiteral())
all=nil


--#sorted:
test=function(a,b) return a>b end
if (smalltalk.Object:selectors():sorted_(test):isNil()) then error("Wrong sorted result") end
if (smalltalk.Array:with_with_with_with_(1,4,2,4):asSet():sorted_(test):asLiteral()~="#( 4 2 1 )") then error("Wrong sort result") end
test=nil