lu = require("luaunit")
package.path = package.path .. ";../?.lua;../util/?.lua"
print(io.popen"cd":read'*l')
require('CpObject')
require('MovingAverage')

local avg = MovingAverage(5)
lu.assertEquals(avg:update(2), 2)
lu.assertEquals(avg:update(2), 2)
lu.assertEquals(avg:update(2), 2)
lu.assertEquals(avg:update(2), 2)
lu.assertEquals(avg:update(2), 2)
lu.assertEquals(avg:update(2), 2)

lu.assertEquals(avg:update(4), 2.4)
lu.assertEquals(avg:update(5), 3)
lu.assertEquals(avg:update(5), 3.6)
lu.assertEquals(avg:update(5), 4.2)
lu.assertEquals(avg:update(5), 4.8)
lu.assertEquals(avg:update(5), 5)

avg = MovingAverage(5)
lu.assertEquals(avg:update(2), 2)
lu.assertEquals(avg:update(4), 3)
lu.assertEquals(avg:update(6), 4)
lu.assertEquals(avg:update(4), 4)
lu.assertEquals(avg:update(2), 3.6)
lu.assertEquals(avg:update(2), 3.6)
lu.assertEquals(avg:update(2), 3.2)
