Skip to content

Commit

Permalink
Merge pull request #164 from MeasureTransport/mparno/issue156
Browse files Browse the repository at this point in the history
Fixed MultiIndexSet Visualization and added test to catch this.
  • Loading branch information
rubiop authored Jul 22, 2022
2 parents 96eae14 + c61350d commit a245442
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 15 deletions.
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
80 changes: 66 additions & 14 deletions tests/MultiIndices/Test_MultiIndexSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,6 @@ TEST_CASE("Testing the MultiIndexSet class", "[MultiIndexSet]" ) {
REQUIRE( isAdmiss );
}

SECTION("Visualize")
{
auto limiter = [](MultiIndex const& multi){ return ( (multi.Get(0)==0)||(multi.Get(1)==0)||((multi.Get(0)<2)&&(multi.Get(1)<2)));};

MultiIndexSet set = MultiIndexSet::CreateTotalOrder(2, 3, limiter);
set.SetLimiter( MultiIndexLimiter::None() );

std::stringstream truth, output;
truth << " 4 | r \n 3 | a m \n 2 | a r \n 1 | a a r m \n 0 | a a a a r \n ----------------\n 0 1 2 3 4 \n";

set.Visualize(output);

REQUIRE(output.str() == truth.str());
}

/*
AdmissableNeighbor.UndefinedNeighbor
Expand Down Expand Up @@ -433,4 +419,70 @@ 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());
}

SECTION("TotalOrder")
{
auto limiter = [](MultiIndex const& multi){ return ( (multi.Get(0)==0)||(multi.Get(1)==0)||((multi.Get(0)<2)&&(multi.Get(1)<2)));};

MultiIndexSet set = MultiIndexSet::CreateTotalOrder(2, 3, limiter);
set.SetLimiter( MultiIndexLimiter::None() );

std::stringstream truth, output;
truth << " 4 | r \n"
<< " 3 | a m \n"
<< " 2 | a r \n"
<< " 1 | a a r m \n"
<< " 0 | a a a a r \n"
<< " ----------------\n"
<< " 0 1 2 3 4 \n";

set.Visualize(output);

REQUIRE(output.str() == truth.str());
}
}

0 comments on commit a245442

Please sign in to comment.