1#include "mlir/Analysis/Presburger/Fraction.h"
2#include "./Utils.h"
3#include <gmock/gmock.h>
4#include <gtest/gtest.h>
5
6using namespace mlir;
7using namespace presburger;
8
9TEST(FractionTest, getAsInteger) {
10 Fraction f(3, 1);
11 EXPECT_EQ(f.getAsInteger(), MPInt(3));
12}
13
14TEST(FractionTest, nearIntegers) {
15 Fraction f(52, 14);
16
17 EXPECT_EQ(floor(f), 3);
18 EXPECT_EQ(ceil(f), 4);
19}
20
21TEST(FractionTest, reduce) {
22 Fraction f(20, 35), g(-56, 63);
23 EXPECT_EQ(f, Fraction(4, 7));
24 EXPECT_EQ(g, Fraction(-8, 9));
25}
26
27TEST(FractionTest, arithmetic) {
28 Fraction f(3, 4), g(-2, 3);
29
30 EXPECT_EQ(f / g, Fraction(-9, 8));
31 EXPECT_EQ(f * g, Fraction(-1, 2));
32 EXPECT_EQ(f + g, Fraction(1, 12));
33 EXPECT_EQ(f - g, Fraction(17, 12));
34
35 f /= g;
36 EXPECT_EQ(f, Fraction(-9, 8));
37 f *= g;
38 EXPECT_EQ(f, Fraction(3, 4));
39 f += g;
40 EXPECT_EQ(f, Fraction(Fraction(1, 12)));
41 f -= g;
42 EXPECT_EQ(f, Fraction(3, 4));
43}
44
45TEST(FractionTest, relational) {
46 Fraction f(2, 5), g(3, 7);
47 EXPECT_TRUE(f < g);
48 EXPECT_FALSE(g < f);
49
50 EXPECT_EQ(f, Fraction(4, 10));
51}
52

source code of mlir/unittests/Analysis/Presburger/FractionTest.cpp