--[[----------------------------------------------------------------------------

WFDiagnosticStatAccumulatorTest.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2014 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remains the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and are protected by all applicable
intellectual property laws, including trade secret and copyright laws.
Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

----------------------------------------------------------------------------]]--

	-- WF.core.diagnostic_log
local WFDiagnosticStatAccumulator = require 'WFDiagnosticStatAccumulator'

	-- WF.core.reactive
local KSPromises = require 'KSPromises'

	-- WF.core.self_test
local WFAsyncTestCase = require 'WFAsyncTestCase'


--============================================================================--

local WFDiagnosticStatAccumulatorTest = {}

--------------------------------------------------------------------------------

local function testAccumulator( testName )

	return function( expectedResult )

		local testName = "test" .. testName

		WFDiagnosticStatAccumulatorTest[ testName ] = function( test )

			local accumulator = WFDiagnosticStatAccumulator()

			WFAsyncTestCase( test )

				:waitFor( function()

					local actionFn = expectedResult.fn
					expectedResult.fn = nil

					if actionFn then
						actionFn( accumulator )
					end

					local result = accumulator:dump()

					return KSPromises.resolvedPromiseP( 'data', result )

				end )
				:continueWhenValueMatches( 'data', expectedResult )

		end

	end

end

--------------------------------------------------------------------------------

testAccumulator 'Empty'
{
	count = 0,
}

--------------------------------------------------------------------------------

testAccumulator 'One'
{
	fn = function( accumulator )

		accumulator:add( 42 )

	end,

	count = 1,
	min = 42,
	max = 42,
	avg = 42,
	total = 42,
}

--------------------------------------------------------------------------------

testAccumulator 'Two'
{
	fn = function( accumulator )

		accumulator:add( 42 )
		accumulator:add( 79 )

	end,

	count = 2,
	min = 42,
	max = 79,
	avg = 60.5,
	total = 121,
}

--------------------------------------------------------------------------------

testAccumulator 'Three'
{
	fn = function( accumulator )

		accumulator:add( 42 )
		accumulator:add( 53 )
		accumulator:add( 10 )

	end,

	count = 3,
	min = 10,
	max = 53,
	avg = 35,
	total = 105,
}

--------------------------------------------------------------------------------

return WFDiagnosticStatAccumulatorTest
