xref: /llvm-project/mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp (revision 2835be82db2037367154bc3226473947abbf661f)
1 //===- MatrixTest.cpp - Tests for QuasiPolynomial -------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "mlir/Analysis/Presburger/GeneratingFunction.h"
10 #include "./Utils.h"
11 #include <gmock/gmock.h>
12 #include <gtest/gtest.h>
13 
14 using namespace mlir;
15 using namespace presburger;
16 using namespace mlir::presburger::detail;
17 
TEST(GeneratingFunctionTest,sum)18 TEST(GeneratingFunctionTest, sum) {
19   GeneratingFunction gf1(2, {1, -1},
20                          {makeFracMatrix(3, 2, {{1, 2}, {5, 7}, {2, 6}}),
21                           makeFracMatrix(3, 2, {{5, 2}, {5, 3}, {7, 2}})},
22                          {{{3, 6}, {7, 2}}, {{2, 8}, {6, 3}}});
23   GeneratingFunction gf2(2, {1, 1},
24                          {makeFracMatrix(3, 2, {{6, 2}, {1, 4}, {2, 6}}),
25                           makeFracMatrix(3, 2, {{3, 2}, {6, 9}, {2, 5}})},
26                          {{{3, 7}, {5, 1}}, {{5, 2}, {6, 2}}});
27 
28   GeneratingFunction sum = gf1 + gf2;
29   EXPECT_EQ_REPR_GENERATINGFUNCTION(
30       sum, GeneratingFunction(2, {1, -1, 1, 1},
31                               {makeFracMatrix(3, 2, {{1, 2}, {5, 7}, {2, 6}}),
32                                makeFracMatrix(3, 2, {{5, 2}, {5, 3}, {7, 2}}),
33                                makeFracMatrix(3, 2, {{6, 2}, {1, 4}, {2, 6}}),
34                                makeFracMatrix(3, 2, {{3, 2}, {6, 9}, {2, 5}})},
35                               {{{3, 6}, {7, 2}},
36                                {{2, 8}, {6, 3}},
37                                {{3, 7}, {5, 1}},
38                                {{5, 2}, {6, 2}}}));
39 }
40