Skip to content

Commit

Permalink
Fixed MultiIndexSet Visualization and added test to catch this.
Browse files Browse the repository at this point in the history
  • Loading branch information
mparno committed Jul 22, 2022
1 parent 96eae14 commit 2dbd5d1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/MultiIndices/MultiIndexSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ void MultiIndexSet::AddForwardNeighbors(unsigned int globalIndex, bool addInacti


void MultiIndexSet::Visualize(std::ostream &out) const
{
{

unsigned int max_ord = maxOrders.at(1) + 1;
for(unsigned int order = 0; order <= maxOrders.at(1) + 1; order++) {
unsigned int i=max_ord - order;
Expand All @@ -421,15 +422,20 @@ void MultiIndexSet::Visualize(std::ostream &out) const
}

if(!found){
bool found2 = false;
for(auto& multi : allMultis){
if((multi.Get(0)==j)&&(multi.Get(1)==i)){
found2 = true;
if(IsAdmissible(multi)){
out << "r ";
}else{
out << "m ";
}
}
}

if(!found2)
out << " ";
}
}
out << std::endl;
Expand Down
45 changes: 45 additions & 0 deletions tests/MultiIndices/Test_MultiIndexSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,49 @@ TEST_CASE("Testing the MultiIndexSet class", "[MultiIndexSet]" ) {
REQUIRE( set.at(inds.at(2)) == MultiIndex{3,0} );

}
}


TEST_CASE("MultiIndexSet Visualization Test", "[MultiIndexSet_Viz]")
{
SECTION("Floating"){
Eigen::MatrixXi multis(1,2);
multis << 3,3;
MultiIndexSet mset = MultiIndexSet(multis);

std::stringstream sstream;
mset.Visualize(sstream);

std::stringstream expected;
expected << " 4 | m \n"
<< " 3 | m a m \n"
<< " 2 | m \n"
<< " 1 | \n"
<< " 0 | \n"
<< " ----------------\n"
<< " 0 1 2 3 4 \n";

CHECK(expected.str() == sstream.str());
}

SECTION("Fixed"){
Eigen::MatrixXi multis(2,2);
multis << 1,3,
3,3;
MultiIndexSet mset = MultiIndexSet(multis);

std::stringstream sstream;
mset.Visualize(sstream);

std::stringstream expected;
expected <<" 4 | m m \n"
<< " 3 | m a m a m \n"
<< " 2 | m m \n"
<< " 1 | \n"
<< " 0 | \n"
<< " ----------------\n"
<< " 0 1 2 3 4 \n";

CHECK(expected.str() == sstream.str());
}
}

0 comments on commit 2dbd5d1

Please sign in to comment.