blob: 05f9eed30bb4e62e1f2e3b90bbf0dc396277ff5b [file] [log] [blame]
Tony Huang9ac5e6e2023-08-24 09:01:44 +00001/*
2 * Copyright 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#undef LOG_TAG
18#define LOG_TAG "SmallAreaDetectionAllowMappingsTest"
19
20#include <gtest/gtest.h>
21
22#include "Scheduler/SmallAreaDetectionAllowMappings.h"
23
24namespace android::scheduler {
25
Tony Huangf3621102023-09-04 17:14:22 +080026class SmallAreaDetectionAllowMappingsTest : public testing::Test {
Tony Huang9ac5e6e2023-08-24 09:01:44 +000027protected:
28 SmallAreaDetectionAllowMappings mMappings;
Tony Huangf3621102023-09-04 17:14:22 +080029 static constexpr int32_t kAppId1 = 10100;
30 static constexpr int32_t kAppId2 = 10101;
31 static constexpr float kThreshold1 = 0.05f;
32 static constexpr float kThreshold2 = 0.07f;
Tony Huang9ac5e6e2023-08-24 09:01:44 +000033};
34
35namespace {
Tony Huangf3621102023-09-04 17:14:22 +080036TEST_F(SmallAreaDetectionAllowMappingsTest, testUpdate) {
37 std::vector<std::pair<int32_t, float>> mappings;
Tony Huang9ac5e6e2023-08-24 09:01:44 +000038 mappings.reserve(2);
Tony Huangf3621102023-09-04 17:14:22 +080039 mappings.push_back(std::make_pair(kAppId1, kThreshold1));
40 mappings.push_back(std::make_pair(kAppId2, kThreshold2));
Tony Huang9ac5e6e2023-08-24 09:01:44 +000041
42 mMappings.update(mappings);
Tony Huangf3621102023-09-04 17:14:22 +080043 ASSERT_EQ(mMappings.getThresholdForAppId(kAppId1).value(), kThreshold1);
44 ASSERT_EQ(mMappings.getThresholdForAppId(kAppId2).value(), kThreshold2);
Tony Huang9ac5e6e2023-08-24 09:01:44 +000045}
46
Tony Huangf3621102023-09-04 17:14:22 +080047TEST_F(SmallAreaDetectionAllowMappingsTest, testSetThesholdForAppId) {
48 mMappings.setThesholdForAppId(kAppId1, kThreshold1);
49 ASSERT_EQ(mMappings.getThresholdForAppId(kAppId1), kThreshold1);
Tony Huang9ac5e6e2023-08-24 09:01:44 +000050}
51
Tony Huangf3621102023-09-04 17:14:22 +080052TEST_F(SmallAreaDetectionAllowMappingsTest, testAppIdNotInTheMappings) {
53 ASSERT_EQ(mMappings.getThresholdForAppId(kAppId1), std::nullopt);
Tony Huang9ac5e6e2023-08-24 09:01:44 +000054}
55
56} // namespace
57} // namespace android::scheduler