1 #include "mlir/Analysis/Presburger/Fraction.h"
3 #include <gmock/gmock.h>
4 #include <gtest/gtest.h>
7 using namespace presburger
;
9 TEST(FractionTest
, getAsInteger
) {
11 EXPECT_EQ(f
.getAsInteger(), DynamicAPInt(3));
14 TEST(FractionTest
, nearIntegers
) {
17 EXPECT_EQ(floor(f
), 3);
18 EXPECT_EQ(ceil(f
), 4);
21 TEST(FractionTest
, reduce
) {
22 Fraction
f(20, 35), g(-56, 63);
23 EXPECT_EQ(f
, Fraction(4, 7));
24 EXPECT_EQ(g
, Fraction(-8, 9));
27 TEST(FractionTest
, arithmetic
) {
28 Fraction
f(3, 4), g(-2, 3);
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));
36 EXPECT_EQ(f
, Fraction(-9, 8));
38 EXPECT_EQ(f
, Fraction(3, 4));
40 EXPECT_EQ(f
, Fraction(Fraction(1, 12)));
42 EXPECT_EQ(f
, Fraction(3, 4));
45 TEST(FractionTest
, relational
) {
46 Fraction
f(2, 5), g(3, 7);
50 EXPECT_EQ(f
, Fraction(4, 10));