mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 07:59:35 +00:00
Move regression and other tests to separate directory
This commit is contained in:
parent
4f5878daec
commit
186fad5b09
5 changed files with 364 additions and 281 deletions
45
scripts/lua/modules/timeseries/tests/utils_test.lua
Normal file
45
scripts/lua/modules/timeseries/tests/utils_test.lua
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
--
|
||||
-- (C) 2018 - ntop.org
|
||||
--
|
||||
|
||||
local ts_common = require("ts_common")
|
||||
|
||||
local function interpolateSerie_test1(test)
|
||||
local serie = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
||||
local target_points = 19
|
||||
local max_err_perc = 10
|
||||
local res = ts_common.upsampleSerie(serie, target_points)
|
||||
|
||||
if not(#res == target_points) then
|
||||
return test:assertion_failed("target_points == #res")
|
||||
end
|
||||
|
||||
local sum = function(a)
|
||||
local s = 0
|
||||
for _, x in pairs(a) do
|
||||
s = s + x
|
||||
end
|
||||
return s
|
||||
end
|
||||
|
||||
local avg1 = sum(serie) / #serie
|
||||
local avg2 = sum(res) / #res
|
||||
local err = math.abs(avg1 - avg2)
|
||||
local err_perc = err * 100 / avg1
|
||||
|
||||
if not(err_perc <= max_err_perc) then
|
||||
return test:failure("err <= ".. max_err_perc .."%")
|
||||
end
|
||||
|
||||
return test:success()
|
||||
end
|
||||
|
||||
function run(tester)
|
||||
local rv = tester.run_test("interpolateSerie:test1", interpolateSerie_test1)
|
||||
|
||||
return rv
|
||||
end
|
||||
|
||||
return {
|
||||
run = run
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue