| 1 |
/*----------------------------------------------------------------------------- |
| 2 |
| Copyright (c) 2013-2026, Nucleic Development Team. |
| 3 |
| |
| 4 |
| Distributed under the terms of the Modified BSD License. |
| 5 |
| |
| 6 |
| The full license is in the file LICENSE, distributed with this software. |
| 7 |
|----------------------------------------------------------------------------*/ |
| 8 |
|
| 9 |
#include <gtest/gtest.h> |
| 10 |
#include <kiwi/kiwi.h> |
| 11 |
|
| 12 |
using namespace kiwi; |
| 13 |
|
| 14 |
// Test constraints creation and methods |
| 15 |
TEST(ConstraintTest, ConstraintCreationEQ) { |
| 16 |
Variable v("foo"); |
| 17 |
Constraint c(v + 1, RelationalOperator::OP_EQ); |
| 18 |
|
| 19 |
EXPECT_EQ(c.strength(), strength::required); |
| 20 |
EXPECT_EQ(c.op(), RelationalOperator::OP_EQ); |
| 21 |
|
| 22 |
auto e = c.expression(); |
| 23 |
auto t = e.terms(); |
| 24 |
EXPECT_EQ(e.constant(), 1); |
| 25 |
EXPECT_EQ(t.size(), 1); |
| 26 |
EXPECT_TRUE(t[0].variable().equals(v)); |
| 27 |
EXPECT_EQ(t[0].coefficient(), 1); |
| 28 |
} |
| 29 |
|
| 30 |
TEST(ConstraintTest, ConstraintCreationLE) { |
| 31 |
Variable v("foo"); |
| 32 |
Constraint c(v + 1, RelationalOperator::OP_LE); |
| 33 |
|
| 34 |
EXPECT_EQ(c.strength(), strength::required); |
| 35 |
EXPECT_EQ(c.op(), RelationalOperator::OP_LE); |
| 36 |
} |
| 37 |
|
| 38 |
TEST(ConstraintTest, ConstraintCreationGE) { |
| 39 |
Variable v("foo"); |
| 40 |
Constraint c(v + 1, RelationalOperator::OP_GE); |
| 41 |
|
| 42 |
EXPECT_EQ(c.strength(), strength::required); |
| 43 |
EXPECT_EQ(c.op(), RelationalOperator::OP_GE); |
| 44 |
} |
| 45 |
|
| 46 |
// Test constraint creation with different strengths |
| 47 |
TEST(ConstraintTest, ConstraintCreationWithStrength) { |
| 48 |
Variable v("foo"); |
| 49 |
|
| 50 |
Constraint c1(v + 1, RelationalOperator::OP_EQ, strength::weak); |
| 51 |
EXPECT_EQ(c1.strength(), strength::weak); |
| 52 |
|
| 53 |
Constraint c2(v + 1, RelationalOperator::OP_EQ, strength::medium); |
| 54 |
EXPECT_EQ(c2.strength(), strength::medium); |
| 55 |
|
| 56 |
Constraint c3(v + 1, RelationalOperator::OP_EQ, strength::strong); |
| 57 |
EXPECT_EQ(c3.strength(), strength::strong); |
| 58 |
|
| 59 |
Constraint c4(v + 1, RelationalOperator::OP_EQ, strength::required); |
| 60 |
EXPECT_EQ(c4.strength(), strength::required); |
| 61 |
} |
| 62 |
|
| 63 |
// Test modifying constraint strength using | operator |
| 64 |
TEST(ConstraintTest, ConstraintOrOperator) { |
| 65 |
Variable v("foo"); |
| 66 |
Constraint c(v + 1, RelationalOperator::OP_EQ); |
| 67 |
|
| 68 |
Constraint c1 = c | strength::weak; |
| 69 |
EXPECT_EQ(c1.strength(), strength::weak); |
| 70 |
|
| 71 |
Constraint c2 = c | strength::medium; |
| 72 |
EXPECT_EQ(c2.strength(), strength::medium); |
| 73 |
|
| 74 |
Constraint c3 = c | strength::strong; |
| 75 |
EXPECT_EQ(c3.strength(), strength::strong); |
| 76 |
|
| 77 |
Constraint c4 = c | strength::required; |
| 78 |
EXPECT_EQ(c4.strength(), strength::required); |
| 79 |
|
| 80 |
Constraint c5 = c | strength::create(1, 1, 0); |
| 81 |
EXPECT_EQ(c5.strength(), strength::create(1, 1, 0)); |
| 82 |
} |