-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lua test for introspection and zencode language stats
- Loading branch information
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
scenarios = I.spy( zencode_scenarios() ) | ||
|
||
print'' | ||
print( 'Introspection found '.. #scenarios..' scenarios') | ||
print'' | ||
|
||
local before | ||
local after | ||
for _,v in ipairs(scenarios) do | ||
-- before = os.time() | ||
|
||
-- exceptions: data, zencode | ||
if v ~= 'zencode' and v ~= 'data' then | ||
print ('+ load: '..v) | ||
load_scenario('zencode_'..v) | ||
end | ||
-- after = os.time() | ||
-- print (' seconds: '..after-before) | ||
end | ||
|
||
print'' | ||
print( 'All scenarios are loaded now') | ||
print'' | ||
|
||
-- total_statements = ( 0 | ||
-- + table_size(ZEN.when_steps) | ||
-- + table_size(ZEN.given_steps) | ||
-- + table_size(ZEN.then_steps) | ||
-- + table_size(ZEN.foreach_steps) ) | ||
-- print( 'Total Zencode statements: '..total_statements) | ||
|
||
statements = { } | ||
for k,v in pairs(ZEN.when_steps) do table.insert(statements, k) end | ||
for k,v in pairs(ZEN.given_steps) do table.insert(statements, k) end | ||
for k,v in pairs(ZEN.then_steps) do table.insert(statements, k) end | ||
for k,v in pairs(ZEN.foreach_steps) do table.insert(statements, k) end | ||
|
||
tokens = { } | ||
for _,v in ipairs(statements) do | ||
local toks = strtok(trim(v):lower(), ' ') | ||
for _,t in ipairs(toks) do | ||
if t ~= "''" then | ||
if tokens[t] then | ||
tokens[t] = tokens[t] + 1 | ||
else | ||
tokens[t] = 1 | ||
end | ||
end | ||
end | ||
end | ||
|
||
print( 'Hall of fame:') | ||
local function sortbyval(tbl, sortFunction) | ||
local keys = {} | ||
for key in pairs(tbl) do | ||
table.insert(keys, key) | ||
end | ||
|
||
table.sort(keys, function(a, b) | ||
return sortFunction(tbl[a], tbl[b]) | ||
end) | ||
|
||
return keys | ||
end | ||
|
||
local sorted_tokens = sortbyval(tokens, function(a, b) return a < b end) | ||
|
||
for _,v in ipairs(sorted_tokens) do | ||
print(tokens[v]..'\t'..v) | ||
end | ||
|
||
print'' | ||
print( 'Total Zencode statements: '..#statements) | ||
print( 'Total unique word tokens: '..table_size(tokens)) | ||
print'' |