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

WFMLModelTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2025 Adobe
All Rights Reserved.

NOTICE: All information contained herein is, and remain the property of
Adobe and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe.

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

local KSData = require "KSData"
local KSPathUtils = require "KSPathUtils"
local WFPlatformInfo = require "WFPlatformInfo"
local WFStruct = require "WFStruct"
local WFMLImp = require "WFMLImp"
local WFRxTestCase = require "WFRxTestCase"

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

local WFMLModelTest = {}

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

if WFPlatformInfo.isiOS or WFPlatformInfo.isMac then

-- The MNIST example is for mac and iOS only, using CoreML
function WFMLModelTest.rxTestMNist( rxTest )

	local testDir = KSPathUtils.child( KSPathUtils.getStandardFilePath( 'testdata' ), 'assets' )

	local model = WFMLImp.WFMLModel( KSPathUtils.child( testDir, 'mnist_linear_ondevice.json' ) )

	rxTest:expectEqual( 1, model.inputCount )
	rxTest:expectEqual( 1, model.outputCount )

	local seven = KSData.memoryMappedContentsOfFile( KSPathUtils.child( testDir, '7.double' ) )

	local result = model:predict( seven )
	result = { WFStruct.unpack( '10d', result ) }

	rxTest:expectEqual( 10, #result )

	local max = 0.0
	local maxIndex = 0
	for i = 1, #result do
		if result[i] > max then
			max = result[i]
			maxIndex = i
		end
	end

	rxTest:expectEqual( 8, maxIndex )

end

end

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

return WFRxTestCase.wrapSuite( 'WFMLModelTest', WFMLModelTest )
