Skip to content

Commit

Permalink
pr feedback, improve logic + more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Jan 6, 2021
1 parent 4224efd commit c1b7c10
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/libs/conduit/conduit_data_array.cpp
Expand Up @@ -1561,13 +1561,13 @@ DataArray<T>::to_summary_string_stream(std::ostream &os,
if(nele > 1)
os << "[";

bool first = true;
bool done = false;
bool done = (nele == 0);
int idx = 0;

while(!done)
{
if(!first)
// if not first, add a comma prefix
if(idx > 0 )
os << ", ";

switch(m_dtype.id())
Expand Down Expand Up @@ -1617,8 +1617,6 @@ DataArray<T>::to_summary_string_stream(std::ostream &os,
}
}

first=false;

idx++;

if(idx == bottom)
Expand Down
49 changes: 49 additions & 0 deletions src/tests/conduit/t_conduit_array.cpp
Expand Up @@ -648,18 +648,67 @@ TEST(conduit_array, summary_print)

va_int64.set({1,2,3,4,5});

// default (thresh is 5)
std::string v = va_int64.to_summary_string();
std::cout << v << std::endl;
EXPECT_EQ(v,"[1, 2, 3, 4, 5]");

// above threshold, even # to display
v = va_int64.to_summary_string(2);
std::cout << v << std::endl;
EXPECT_EQ(v,"[1, ..., 5]");

// above threshold, od # to display
v = va_int64.to_summary_string(3);
std::cout << v << std::endl;
EXPECT_EQ(v,"[1, 2, ..., 5]");

// above threshold, threshold is much larger than # of eles
v = va_int64.to_summary_string(64);
std::cout << v << std::endl;
EXPECT_EQ(v,"[1, 2, 3, 4, 5]");

// above threshold, threshold is negative
v = va_int64.to_summary_string(-1);
std::cout << v << std::endl;
EXPECT_EQ(v,"[1, 2, 3, 4, 5]");


// single ele array
std::vector<int64> v_int64_single(1,-1);
int64_array va_int64_single(&v_int64[0],DataType::int64(1));

va_int64_single.set({1});

v = va_int64_single.to_summary_string();
std::cout << v << std::endl;
EXPECT_EQ(v,"1");

v = va_int64_single.to_summary_string(64);
std::cout << v << std::endl;
EXPECT_EQ(v,"1");

v = va_int64_single.to_summary_string(-1);
std::cout << v << std::endl;
EXPECT_EQ(v,"1");


// single empty array
std::vector<int64> v_int64_empty(0,0);
int64_array va_int64_empty(&v_int64[0],DataType::int64(0));

v = va_int64_empty.to_summary_string();
std::cout << v << std::endl;
EXPECT_EQ(v,"");

v = va_int64_empty.to_summary_string(64);
std::cout << v << std::endl;
EXPECT_EQ(v,"");

v = va_int64_empty.to_summary_string(-1);
std::cout << v << std::endl;
EXPECT_EQ(v,"");

}


Expand Down
7 changes: 6 additions & 1 deletion src/tests/conduit/t_conduit_node.cpp
Expand Up @@ -1200,9 +1200,14 @@ TEST(conduit_node, describe)
EXPECT_EQ(d["e/max"].to_int(),12);
EXPECT_EQ(d["f/max"].to_float(),7.0);

EXPECT_EQ(d["a/mean"].to_float(),3.0);
EXPECT_EQ(d["b/mean"].to_float(),2.0);
EXPECT_EQ(d["c/mean"].to_float(),3.5);
EXPECT_EQ(d["d/mean"].to_float(),4.0);
EXPECT_EQ(d["e/mean"].to_float(),6.5);
EXPECT_EQ(d["f/mean"].to_float(),4.0);
EXPECT_EQ(d["g/mean"].to_float(),3.0);


n["a"] = {1,2,3,4,5};
n["b"] = {1,2,3};
n["c"] = {1,2,3,4,5,6};
Expand Down

0 comments on commit c1b7c10

Please sign in to comment.