aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/int128/ut/i128_comparison_ut.cpp
blob: 7b8d50881511757e050100a067a3ed753268f665 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <library/cpp/testing/unittest/registar.h>

#include <library/cpp/int128/int128.h>

#include <util/generic/cast.h>

Y_UNIT_TEST_SUITE(I128ComparisonPositiveWithPositiveSuite) {
    Y_UNIT_TEST(PositivePositiveGreater) {
        UNIT_ASSERT(i128{1} > i128{0});
        UNIT_ASSERT(i128{2} > i128{1});
        UNIT_ASSERT(i128{42} > i128{0});
        UNIT_ASSERT(i128{42} > i128{1});
        i128 big = i128{1, 0};
        UNIT_ASSERT(big > i128{1});
        UNIT_ASSERT(std::numeric_limits<i128>::max() > i128{0});
    }

    Y_UNIT_TEST(PositivePositiveGreaterOrEqual) {
        UNIT_ASSERT(i128{1} >= i128{0});
        UNIT_ASSERT(i128{2} >= i128{1});
        UNIT_ASSERT(i128{42} >= i128{0});
        UNIT_ASSERT(i128{42} >= i128{1});
        i128 big = i128{1, 0};
        UNIT_ASSERT(big >= i128{1});
        UNIT_ASSERT(std::numeric_limits<i128>::max() >= i128{0});

        UNIT_ASSERT(i128{0} >= i128{0});
        UNIT_ASSERT(i128{1} >= i128{1});
        UNIT_ASSERT(i128{2} >= i128{2});
        UNIT_ASSERT(i128{42} >= i128{42});
        UNIT_ASSERT(big >= big);
        UNIT_ASSERT(std::numeric_limits<i128>::max() >= std::numeric_limits<i128>::max());
    }

    Y_UNIT_TEST(PositivePositiveLess) {
        UNIT_ASSERT(i128{0} < i128{1});
        UNIT_ASSERT(i128{1} < i128{2});
        UNIT_ASSERT(i128{0} < i128{42});
        UNIT_ASSERT(i128{1} < i128{42});
        i128 big = i128{1, 0};
        UNIT_ASSERT(i128{1} < big);
        UNIT_ASSERT(i128{0} < std::numeric_limits<i128>::max());
    }

    Y_UNIT_TEST(PositivePositiveLessOrEqual) {
        UNIT_ASSERT(i128{0} <= i128{1});
        UNIT_ASSERT(i128{1} <= i128{2});
        UNIT_ASSERT(i128{0} <= i128{42});
        UNIT_ASSERT(i128{1} <= i128{42});
        i128 big = i128{1, 0};
        UNIT_ASSERT(i128{1} <= big);
        UNIT_ASSERT(i128{0} <= std::numeric_limits<i128>::max());

        UNIT_ASSERT(i128{0} <= i128{0});
        UNIT_ASSERT(i128{1} <= i128{1});
        UNIT_ASSERT(i128{2} <= i128{2});
        UNIT_ASSERT(i128{42} <= i128{42});
        UNIT_ASSERT(big <= big);
        UNIT_ASSERT(std::numeric_limits<i128>::max() <= std::numeric_limits<i128>::max());
    }
}

Y_UNIT_TEST_SUITE(I128ComparisonPositiveWithNegativeSuite) {
    Y_UNIT_TEST(PositiveNegativeGreater) {
        UNIT_ASSERT(i128{0} > i128{-1});
        UNIT_ASSERT(i128{2} > i128{-1});
        UNIT_ASSERT(i128{0} > i128{-42});
        UNIT_ASSERT(i128{42} > i128{-1});
        i128 big = i128{1, 0};
        UNIT_ASSERT(big > i128{-1});
        UNIT_ASSERT(std::numeric_limits<i128>::max() > i128{-1});
    }

    Y_UNIT_TEST(PositiveNegativeGreaterOrEqual) {
        UNIT_ASSERT(i128{0} >= i128{-1});
        UNIT_ASSERT(i128{2} >= i128{-1});
        UNIT_ASSERT(i128{0} >= i128{-42});
        UNIT_ASSERT(i128{42} >= i128{-1});
        i128 big = i128{1, 0};
        UNIT_ASSERT(big >= i128{-1});
        UNIT_ASSERT(std::numeric_limits<i128>::max() >= i128{-1});
    }

    Y_UNIT_TEST(NegativePositiveLess) {
        UNIT_ASSERT(i128{-1} < i128{0});
        UNIT_ASSERT(i128{-1} < i128{2});
        UNIT_ASSERT(i128{-42} < i128{0});
        UNIT_ASSERT(i128{-1} < i128{42});
        i128 big = i128{1, 0};
        UNIT_ASSERT(i128{-1} < big);
        UNIT_ASSERT(i128{-1} < std::numeric_limits<i128>::max());
    }

    Y_UNIT_TEST(NegativePositiveLessOrEqual) {
        UNIT_ASSERT(i128{-1} <= i128{0});
        UNIT_ASSERT(i128{-1} <= i128{2});
        UNIT_ASSERT(i128{-42} <= i128{0});
        UNIT_ASSERT(i128{-1} <= i128{42});
        i128 big = i128{1, 0};
        UNIT_ASSERT(i128{-1} <= big);
        UNIT_ASSERT(i128{-1} <= std::numeric_limits<i128>::max());
    }
}

Y_UNIT_TEST_SUITE(I128ComparisonNegativeWithNegativeSuite) {
    Y_UNIT_TEST(NegativeNegativeGreater) {
        UNIT_ASSERT(i128{-1} > i128{-2});
        UNIT_ASSERT(i128{-2} > i128{-3});
        UNIT_ASSERT(i128{-1} > i128{-42});
        UNIT_ASSERT(i128{-42} > i128{-142});
        i128 big = -i128{1, 0};
        UNIT_ASSERT(i128{-1} > big);
        UNIT_ASSERT(i128{-1} > std::numeric_limits<i128>::min());
    }

    Y_UNIT_TEST(NegativeNegativeGreaterOrEqual) {
        UNIT_ASSERT(i128{-1} >= i128{-2});
        UNIT_ASSERT(i128{-2} >= i128{-3});
        UNIT_ASSERT(i128{-1} >= i128{-42});
        UNIT_ASSERT(i128{-42} >= i128{-142});
        i128 big = -i128{1, 0};
        UNIT_ASSERT(i128{-1} >= big);
        UNIT_ASSERT(i128{-1} >= std::numeric_limits<i128>::min());
    }

    Y_UNIT_TEST(NegativeNegativeLess) {
        UNIT_ASSERT(i128{-2} < i128{-1});
        UNIT_ASSERT(i128{-3} < i128{-2});
        UNIT_ASSERT(i128{-42} < i128{-1});
        UNIT_ASSERT(i128{-142} < i128{42});
        i128 big = -i128{1, 0};
        UNIT_ASSERT(big < i128{-1});
        UNIT_ASSERT(std::numeric_limits<i128>::min() < i128{-1});
    }

    Y_UNIT_TEST(NegativeNegativeLessOrEqual) {
        UNIT_ASSERT(i128{-2} <= i128{-1});
        UNIT_ASSERT(i128{-3} <= i128{-2});
        UNIT_ASSERT(i128{-42} <= i128{-1});
        UNIT_ASSERT(i128{-142} <= i128{42});
        i128 big = -i128{1, 0};
        UNIT_ASSERT(big <= i128{-1});
        UNIT_ASSERT(std::numeric_limits<i128>::min() <= i128{-1});
    }
}