-- Copyright (c) 2024 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.
local lu = require 'luaunit'
local cooling_enums = require 'basic_cooling.define.cooling_enums'
local props = require 'basic_cooling.define.cooling_properties'
local pumps_config = require 'basic_cooling.cooling_config.pumps_config'
local cooling_policy = require 'basic_cooling.cooling_policys'

TestCoolingPolicy = {}

function TestCoolingPolicy:test_enable_default_cooling_policy()
    local tmp = {
        objs = {
            [1] = { PolicyIdx = 1, PolicyType = 4294967295, IsValid = 0 },
            [2] = { PolicyIdx = 2, PolicyType = 1, IsValid = 0 },
            [3] = { PolicyIdx = 3, PolicyType = 1, IsValid = 0 },
            [10] = { PolicyIdx = 10, PolicyType = 2, IsValid = 0 },
            [11] = { PolicyIdx = 11, PolicyType = 2, IsValid = 0 },
            [12] = { PolicyIdx = 12, PolicyType = 2, IsValid = 0 }
        },
        default_policy_id = -1,
        set_policy_updated_flag = function()
            return
        end
    }
    local ok = pcall(function()
        return cooling_policy.enable_default_cooling_policy(tmp)
    end)
    lu.assertEquals(ok, true)
    -- 经过计算后，PolicyType为1的调速策略仅2生效，PolicyType为2的调速策略仅10生效
    for _, obj in pairs(tmp.objs) do
        if obj.PolicyIdx == 1 then
            lu.assertEquals(obj.IsValid, 1)
        else
            lu.assertEquals(obj.IsValid, 0)
        end
    end
    lu.assertEquals(tmp.default_policy_id, 1)
end