1 /*
2 * Copyright 2019 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 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 #include "Scheduler/StrongTyping.h"
20
21 using namespace testing;
22
23 namespace android {
24
TEST(StrongTypeTest,comparison)25 TEST(StrongTypeTest, comparison) {
26 using SpunkyType = StrongTyping<int, struct SpunkyTypeTag, Compare>;
27 SpunkyType f2(22);
28 SpunkyType f1(10);
29
30 EXPECT_TRUE(f1 == f1);
31 EXPECT_TRUE(SpunkyType(10) != SpunkyType(11));
32 EXPECT_FALSE(SpunkyType(31) != SpunkyType(31));
33
34 EXPECT_TRUE(SpunkyType(10) < SpunkyType(11));
35 EXPECT_TRUE(SpunkyType(-1) < SpunkyType(0));
36 EXPECT_FALSE(SpunkyType(-10) < SpunkyType(-20));
37
38 EXPECT_TRUE(SpunkyType(10) <= SpunkyType(11));
39 EXPECT_TRUE(SpunkyType(10) <= SpunkyType(10));
40 EXPECT_TRUE(SpunkyType(-10) <= SpunkyType(1));
41 EXPECT_FALSE(SpunkyType(10) <= SpunkyType(9));
42
43 EXPECT_TRUE(SpunkyType(11) >= SpunkyType(11));
44 EXPECT_TRUE(SpunkyType(12) >= SpunkyType(11));
45 EXPECT_FALSE(SpunkyType(11) >= SpunkyType(12));
46
47 EXPECT_FALSE(SpunkyType(11) > SpunkyType(12));
48 EXPECT_TRUE(SpunkyType(-11) < SpunkyType(7));
49 }
50
TEST(StrongTypeTest,addition)51 TEST(StrongTypeTest, addition) {
52 using FunkyType = StrongTyping<int, struct FunkyTypeTag, Compare, Add>;
53 FunkyType f2(22);
54 FunkyType f1(10);
55
56 EXPECT_THAT(f1 + f2, Eq(FunkyType(32)));
57 EXPECT_THAT(f2 + f1, Eq(FunkyType(32)));
58
59 EXPECT_THAT(++f1.value(), Eq(11));
60 EXPECT_THAT(f1.value(), Eq(11));
61 EXPECT_THAT(f1++.value(), Eq(11));
62 EXPECT_THAT(f1++.value(), Eq(12));
63 EXPECT_THAT(f1.value(), Eq(13));
64
65 auto f3 = f1;
66 EXPECT_THAT(f1, Eq(f3));
67 EXPECT_THAT(f1, Lt(f2));
68
69 f3 += f1;
70 EXPECT_THAT(f1.value(), Eq(13));
71 EXPECT_THAT(f3.value(), Eq(26));
72 }
73 } // namespace android
74