Skip to content

Commit

Permalink
Refs #8550. Print implementation and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Dec 4, 2013
1 parent de36ec3 commit 3f4b415
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Expand Up @@ -73,7 +73,21 @@ namespace DataObjects
/// Print specified item to the stream
virtual void print(size_t index, std::ostream& s) const
{
// TODO: implement
const std::vector<Type>& values = m_data.at(index);

auto it = values.begin();

if ( it != values.end() )
{
s << *it;
++it;
}

for ( ; it != values.end(); ++it )
{
s << ',';
s << *it;
}
}

/// Set item from a string value
Expand Down
27 changes: 27 additions & 0 deletions Code/Mantid/Framework/DataObjects/test/VectorColumnTest.h
Expand Up @@ -64,6 +64,33 @@ class VectorColumnTest : public CxxTest::TestSuite
TS_ASSERT_THROWS( col.read(4,"1,2,a,3"), std::invalid_argument);
}

void test_print()
{
VectorColumnTestHelper<int> col;

col.resize(3);

// Simple case
std::vector<int> v1;
v1.push_back(11); v1.push_back(22); v1.push_back(33); v1.push_back(44); v1.push_back(55);
col.cell< std::vector<int> >(0) = v1;
std::ostringstream s1;
TS_ASSERT_THROWS_NOTHING( col.print(0, s1) );
TS_ASSERT_EQUALS( s1.str(), "11,22,33,44,55" );

// Single element
std::vector<int> v2;
v2.push_back(9876);
col.cell< std::vector<int> >(1) = v2;
std::ostringstream s2;
TS_ASSERT_THROWS_NOTHING( col.print(1, s2) );
TS_ASSERT_EQUALS( s2.str(), "9876" );

// Unset element
std::ostringstream s3;
TS_ASSERT_THROWS_NOTHING( col.print(2, s3) );
TS_ASSERT( s3.str().empty() );
}
};


Expand Down

0 comments on commit 3f4b415

Please sign in to comment.