Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocoh committed Oct 18, 2024
1 parent 033c73b commit 5fbbe06
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
25 changes: 21 additions & 4 deletions src/core/NajaCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -1070,13 +1070,30 @@ template<class Type> class NajaCollection {
return NajaCollection<ReturnType>();
}

NajaBaseIterator<Type>* begin_() { if (collection_) { return collection_->begin(); } return nullptr; }
NajaBaseIterator<Type>* end_() { if (collection_) { return collection_->end(); } return nullptr; }
Iterator begin() { return Iterator(begin_()); }
Iterator end() { return Iterator(end_()); }
NajaBaseIterator<Type>* begin_() const { if (collection_) { return collection_->begin(); } return nullptr; }
NajaBaseIterator<Type>* end_() const { if (collection_) { return collection_->end(); } return nullptr; }
Iterator begin() const { return Iterator(begin_()); }
Iterator end() const { return Iterator(end_()); }

size_t size() const { if (collection_) { return collection_->size(); } return 0; }
bool empty() const { if (collection_) { return collection_->empty(); } return true; }

//comperator
bool operator==(const NajaCollection<Type>& r) const {
if (size() == r.size()) {
auto it = begin();
auto rit = r.begin();
while (it != end()) {
if (*it != *rit) {
return false;

Check warning on line 1088 in src/core/NajaCollection.h

View check run for this annotation

Codecov / codecov/patch

src/core/NajaCollection.h#L1088

Added line #L1088 was not covered by tests
}
++it;
++rit;
}
return true;
}
return false;

Check warning on line 1095 in src/core/NajaCollection.h

View check run for this annotation

Codecov / codecov/patch

src/core/NajaCollection.h#L1095

Added line #L1095 was not covered by tests
}
private:
const NajaBaseCollection<Type>* collection_ {nullptr};
};
Expand Down
20 changes: 14 additions & 6 deletions test/snl/snl/kernel/SNLEquipotentialTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,22 @@ TEST_F(SNLEquipotentialTest, test) {
auto cpio = SNLInstTermOccurrence(cPath, cpi);

SNLEquipotential equipotentialTopI0(topi0);
EXPECT_THAT(equipotentialTopI0.getTerms(), ElementsAre(topi0, topi1, topout));
EXPECT_THAT(equipotentialTopI0.getInstTermOccurrences(), ElementsAre(aapio, bbpio, cpio));
std::set<SNLBitTerm*> terms;
terms.insert(topi0);
terms.insert(topi1);
terms.insert(topout);
std::set<SNLInstTermOccurrence> instTermOccurrences;
instTermOccurrences.insert(aapio);
instTermOccurrences.insert(bbpio);
instTermOccurrences.insert(cpio);
EXPECT_EQ(equipotentialTopI0.getTerms(), naja::NajaCollection(new naja::NajaSTLCollection(&terms)));
EXPECT_EQ(equipotentialTopI0.getInstTermOccurrences(), naja::NajaCollection(new naja::NajaSTLCollection(&instTermOccurrences)));

SNLEquipotential equipotentialTopI1(topi1);
EXPECT_THAT(equipotentialTopI1.getTerms(), ElementsAre(topi0, topi1, topout));
EXPECT_THAT(equipotentialTopI1.getInstTermOccurrences(), ElementsAre(aapio, bbpio, cpio));
EXPECT_EQ(equipotentialTopI1.getTerms(), naja::NajaCollection(new naja::NajaSTLCollection(&terms)));
EXPECT_EQ(equipotentialTopI1.getInstTermOccurrences(), naja::NajaCollection(new naja::NajaSTLCollection(&instTermOccurrences)));

SNLEquipotential equipotentialTopOut(topout);
EXPECT_THAT(equipotentialTopOut.getTerms(), ElementsAre(topi0, topi1, topout));
EXPECT_THAT(equipotentialTopOut.getInstTermOccurrences(), ElementsAre(aapio, bbpio, cpio));
EXPECT_EQ(equipotentialTopOut.getTerms(), naja::NajaCollection(new naja::NajaSTLCollection(&terms)));
EXPECT_EQ(equipotentialTopOut.getInstTermOccurrences(), naja::NajaCollection(new naja::NajaSTLCollection(&instTermOccurrences)));
}
12 changes: 8 additions & 4 deletions test/snl/snl/kernel/SNLOccurrenceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ TEST_F(SNLOccurrenceTest, testEquipotential0) {
auto topi = top->getScalarTerm(SNLName("i"));
ASSERT_NE(topi, nullptr);
SNLEquipotential equipotential(topi);
EXPECT_THAT(equipotential.getTerms(), ElementsAre(topi));
EXPECT_EQ(equipotential.getTerms().size(), 1);
EXPECT_EQ(*equipotential.getTerms().begin(), topi);
SNLPath::PathStringDescriptor h2StringPath = {"h0", "h1", "h2"};
SNLPath h2Path(top, h2StringPath);
EXPECT_FALSE(h2Path.empty());
Expand All @@ -184,7 +185,8 @@ TEST_F(SNLOccurrenceTest, testEquipotential0) {
ASSERT_NE(nullptr, primi);
auto primiOccurrence = SNLInstTermOccurrence(h2Path, primi);
ASSERT_TRUE(primiOccurrence.isValid());
EXPECT_THAT(equipotential.getInstTermOccurrences(), ElementsAre(primiOccurrence));
EXPECT_EQ(equipotential.getInstTermOccurrences().size(), 1);
EXPECT_EQ(*equipotential.getInstTermOccurrences().begin(), primiOccurrence);
}

TEST_F(SNLOccurrenceTest, testEquipotential1) {
Expand All @@ -199,7 +201,8 @@ TEST_F(SNLOccurrenceTest, testEquipotential1) {
ASSERT_NE(nullptr, h2i);
auto h2iOccurrence = SNLInstTermOccurrence(h1Path, h2i);
SNLEquipotential equipotential(h2iOccurrence);
EXPECT_THAT(equipotential.getTerms(), ElementsAre(topi));
EXPECT_EQ(equipotential.getTerms().size(), 1);
EXPECT_EQ(*equipotential.getTerms().begin(), topi);
SNLPath::PathStringDescriptor h2StringPath = {"h0", "h1", "h2"};
SNLPath h2Path(top, h2StringPath);
EXPECT_FALSE(h2Path.empty());
Expand All @@ -209,7 +212,8 @@ TEST_F(SNLOccurrenceTest, testEquipotential1) {
ASSERT_NE(nullptr, primi);
auto primiOccurrence = SNLInstTermOccurrence(h2Path, primi);
ASSERT_TRUE(primiOccurrence.isValid());
EXPECT_THAT(equipotential.getInstTermOccurrences(), ElementsAre(primiOccurrence));
EXPECT_EQ(equipotential.getInstTermOccurrences().size(), 1);
EXPECT_EQ(*equipotential.getInstTermOccurrences().begin(), primiOccurrence);
}

TEST_F(SNLOccurrenceTest, testErrors) {
Expand Down

0 comments on commit 5fbbe06

Please sign in to comment.