Last active
July 25, 2018 17:44
-
-
Save kentkrantz/f4f0303d15ee298eb9a5f8ea039cb432 to your computer and use it in GitHub Desktop.
Test getColors/findColors of AutoTouch
This file contains hidden or 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
| function table.val_to_str ( v ) | |
| if "string" == type( v ) then | |
| v = string.gsub( v, "\n", "\\n" ) | |
| if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then | |
| return "'" .. v .. "'" | |
| end | |
| return '"' .. string.gsub(v,'"', '\\"' ) .. '"' | |
| else | |
| return "table" == type( v ) and table.tostring( v ) or | |
| tostring( v ) | |
| end | |
| end | |
| function table.key_to_str ( k ) | |
| if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then | |
| return k | |
| else | |
| return "[" .. table.val_to_str( k ) .. "]" | |
| end | |
| end | |
| function table.tostring( tbl ) | |
| local result, done = {}, {} | |
| for k, v in ipairs( tbl ) do | |
| table.insert( result, table.val_to_str( v ) ) | |
| done[ k ] = true | |
| end | |
| for k, v in pairs( tbl ) do | |
| if not done[ k ] then | |
| table.insert( result, | |
| table.key_to_str( k ) .. "=" .. table.val_to_str( v ) ) | |
| end | |
| end | |
| return "{" .. table.concat( result, "," ) .. "}" | |
| end | |
| -------------------------------------------------------- | |
| local locations = {{10, 20}, {15, 29}, {30, 28}, {9, 16}, {16, 17}}; | |
| log("-----------------------------------"); | |
| log(">>>>>>>>>>>> locations:"); | |
| log(table.tostring(locations)) | |
| local points = {} | |
| local colors = getColors(locations); | |
| log("-----------------------------------"); | |
| log(">>>>>>>>>>>> found colors:"); | |
| for i, v in pairs(colors) do | |
| log(string.format(">>>>> Gotten color:%d", v)); | |
| local firstPointLocation = locations[1]; | |
| local currentLocation = locations[i]; | |
| local offsetX = currentLocation[1] - firstPointLocation[1]; | |
| local offsetY = currentLocation[2] - firstPointLocation[2]; | |
| table.insert(points, {v, offsetX, offsetY}) | |
| end | |
| log("-----------------------------------"); | |
| log(">>>>>>>>>>>> points:"); | |
| log(table.tostring(points)) | |
| log("-----------------------------------"); | |
| log(">>>>>>>>>>>> found locations:"); | |
| local ls = findColors(points, 0, nil); | |
| for i, v in pairs(ls) do | |
| log(string.format("Found rect at: %f,%f", v[1], v[2])); | |
| if (v[1] == locations[1][1] and v[2] == locations[1][2]) then | |
| log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ TEST getColors, findColors PASSED!") | |
| alert("TEST getColors, findColors PASSED!") | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment