From fb67ab586f5c0824b9b40ea777a087bbd189688e Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Mon, 6 Nov 2017 05:49:58 -0500 Subject: [PATCH] testing: Add __eq and __tostring tests for Lua securities --- internal/handlers/securities_lua_test.go | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/handlers/securities_lua_test.go b/internal/handlers/securities_lua_test.go index 0d9ee84..af8a440 100644 --- a/internal/handlers/securities_lua_test.go +++ b/internal/handlers/securities_lua_test.go @@ -33,7 +33,19 @@ func TestLuaSecurities(t *testing.T) { } securityids.Sort() + equalityString := "" + for i, _ := range securityids { + for j, _ := range securityids { + if i == j { + equalityString += "true" + } else { + equalityString += "false" + } + } + } + simpleLuaTest(t, d.clients[0], []LuaTest{ + {"__tostring", `return get_default_currency()`, fmt.Sprintf("%s - %s (%s)", defaultSecurity.Name, defaultSecurity.Description, defaultSecurity.Symbol)}, {"SecurityId", `return get_default_currency().SecurityId`, strconv.FormatInt(defaultSecurity.SecurityId, 10)}, {"Name", `return get_default_currency().Name`, defaultSecurity.Name}, {"Description", `return get_default_currency().Description`, defaultSecurity.Description}, @@ -41,6 +53,24 @@ func TestLuaSecurities(t *testing.T) { {"Precision", `return get_default_currency().Precision`, strconv.FormatInt(int64(defaultSecurity.Precision), 10)}, {"Type", `return get_default_currency().Type`, strconv.FormatInt(int64(defaultSecurity.Type), 10)}, {"AlternateId", `return get_default_currency().AlternateId`, defaultSecurity.AlternateId}, + {"__eq", ` +securities = get_securities() +sorted = {} +for id in pairs(securities) do + table.insert(sorted, id) +end +str = "" +table.sort(sorted) +for i,idi in ipairs(sorted) do + for j,idj in ipairs(sorted) do + if securities[idi] == securities[idj] then + str = str .. "true" + else + str = str .. "false" + end + end +end +return str`, equalityString}, {"get_securities()", ` sorted = {} for id in pairs(get_securities()) do