Skip to content

Commit

Permalink
more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
xtofalex committed Mar 25, 2024
1 parent 5132fe5 commit e72d34e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
16 changes: 11 additions & 5 deletions src/snl/snl/kernel/SNLInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,22 @@ bool SNLInstance::isLeaf() const {
return getModel()->isLeaf();
}

SNLInstTerm* SNLInstance::getInstTerm(const SNLBitTerm* term) const {
if (term->getDesign() != getModel()) {
SNLInstTerm* SNLInstance::getInstTerm(const SNLBitTerm* bitTerm) const {
if (bitTerm == nullptr) {
std::string reason = "SNLInstance::getInsTerm error in "
+ getName().getString() + " model: " + getModel()->getName().getString()
+ " bitTerm arg is null";
throw SNLException(reason);
}
if (bitTerm->getDesign() != getModel()) {
std::string reason = "SNLInstance::getInsTerm incoherency: "
+ getName().getString() + " model: " + getModel()->getName().getString()
+ " and " + term->getString() + " model: " + term->getDesign()->getName().getString()
+ " and " + bitTerm->getString() + " model: " + bitTerm->getDesign()->getName().getString()
+ " should be the same";
throw SNLException(reason);
}
assert(term->getFlatID() < instTerms_.size());
return instTerms_[term->getFlatID()];
assert(bitTerm->getFlatID() < instTerms_.size());
return instTerms_[bitTerm->getFlatID()];
}

NajaCollection<SNLInstTerm*> SNLInstance::getInstTerms() const {
Expand Down
2 changes: 1 addition & 1 deletion src/snl/snl/kernel/SNLInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class SNLInstance final: public SNLDesignObject {
NajaCollection<SNLInstParameter*> getInstParameters() const;

///\return SNLInstTerm corresponding to the SNLBitTerm representative in this instance.
SNLInstTerm* getInstTerm(const SNLBitTerm* term) const;
SNLInstTerm* getInstTerm(const SNLBitTerm* bitTerm) const;
///\return the NajaCollection of all SNLInstTerm of this SNLInstance.
NajaCollection<SNLInstTerm*> getInstTerms() const;
/**
Expand Down
5 changes: 5 additions & 0 deletions test/snl/snl/kernel/SNLInstanceTest2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ TEST_F(SNLInstanceTest2, testInstTermRenameError) {
auto ins = SNLInstance::create(design_, model_, SNLName("instance"));
auto instTerm = ins->getInstTerm(a);
EXPECT_THROW(instTerm->setName(SNLName("b")), SNLException);
}

TEST_F(SNLInstanceTest2, testInstTermNullTerm) {
auto ins = SNLInstance::create(design_, model_, SNLName("instance"));
EXPECT_THROW(ins->getInstTerm(nullptr), SNLException);
}
24 changes: 22 additions & 2 deletions test/snl/snl/kernel/SNLOccurrenceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using ::testing::ElementsAre;
#include "SNLScalarNet.h"
#include "SNLBitNetOccurrence.h"
#include "SNLBitTermOccurrence.h"
#include "SNLInstTermOccurrence.h"
#include "SNLEquipotential.h"
#include "SNLException.h"
using namespace naja::SNL;
Expand All @@ -25,15 +26,17 @@ class SNLOccurrenceTest: public ::testing::Test {
// |-> h1: i(i)
// |-> h2: i(i)
// |-> prim: i(i)
// |-> prim: i(o) (dangling)
// simple test design with i term and net at each level
// connected to upper and lower level
//
// connected to upper and lower level.
// At bottom level prim:o is unconnected.
auto universe = SNLUniverse::create();
auto db = SNLDB::create(universe);
auto primitivesLib = SNLLibrary::create(db, SNLLibrary::Type::Primitives);
auto designsLib = SNLLibrary::create(db);
auto prim = SNLDesign::create(primitivesLib, SNLDesign::Type::Primitive, SNLName("PRIM"));
auto primi = SNLScalarTerm::create(prim, SNLTerm::Direction::Input, SNLName("i"));
auto primo = SNLScalarTerm::create(prim, SNLTerm::Direction::Input, SNLName("o"));
auto primiNet = SNLScalarNet::create(prim, SNLName("i"));
primi->setNet(primiNet);
auto top = SNLDesign::create(designsLib, SNLName("TOP"));
Expand Down Expand Up @@ -142,6 +145,23 @@ TEST_F(SNLOccurrenceTest, testh1Level) {
EXPECT_LT(h1iTermOccurrence, SNLBitNetOccurrence(h1Path, iTerm->getNet()));
}

TEST_F(SNLOccurrenceTest, testh2Level) {
auto h0Path = SNLPath(h0Instance_);
auto h1Path = SNLPath(h0Path, h1Instance_);
auto h2Path = SNLPath(h1Path, h2Instance_);
ASSERT_EQ(3, h2Path.size());
auto primI = primInstance_->getInstTerm(primInstance_->getModel()->getScalarTerm(SNLName("i")));
auto primO = primInstance_->getInstTerm(primInstance_->getModel()->getScalarTerm(SNLName("o")));
ASSERT_NE(nullptr, primI);
ASSERT_NE(nullptr, primO);
auto primITermOccurrence = SNLInstTermOccurrence(h2Path, primI);
auto primOTermOccurrence = SNLInstTermOccurrence(h2Path, primO);
ASSERT_TRUE(primITermOccurrence.isValid());
ASSERT_TRUE(primOTermOccurrence.isValid());
EXPECT_FALSE(primOTermOccurrence.getNetOccurrence().isValid());
EXPECT_EQ(nullptr, primOTermOccurrence.getNet());
}

TEST_F(SNLOccurrenceTest, testEquipotential0) {
ASSERT_NE(h0Instance_, nullptr);
auto top = h0Instance_->getDesign();
Expand Down

0 comments on commit e72d34e

Please sign in to comment.