Skip to content

Commit

Permalink
Add ::push_back(double) method for feature parity.
Browse files Browse the repository at this point in the history
Add tests for this and other push_back()'s.
  • Loading branch information
jgarzik committed May 5, 2017
1 parent d415300 commit 107db98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/univalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class UniValue {
UniValue tmpVal(val_);
return push_back(tmpVal);
}
bool push_back(double val_) {
UniValue tmpVal(val_);
return push_back(tmpVal);
}
bool push_backV(const std::vector<UniValue>& vec);

bool pushKV(const std::string& key, const UniValue& val);
Expand Down
11 changes: 10 additions & 1 deletion test/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,23 @@ BOOST_AUTO_TEST_CASE(univalue_array)

BOOST_CHECK(arr.push_backV(vec));

BOOST_CHECK(arr.push_back((uint64_t) 400ULL));
BOOST_CHECK(arr.push_back((int64_t) -400LL));
BOOST_CHECK(arr.push_back((int) -401));
BOOST_CHECK(arr.push_back(-40.1));

BOOST_CHECK_EQUAL(arr.empty(), false);
BOOST_CHECK_EQUAL(arr.size(), 5);
BOOST_CHECK_EQUAL(arr.size(), 9);

BOOST_CHECK_EQUAL(arr[0].getValStr(), "1023");
BOOST_CHECK_EQUAL(arr[1].getValStr(), "zippy");
BOOST_CHECK_EQUAL(arr[2].getValStr(), "pippy");
BOOST_CHECK_EQUAL(arr[3].getValStr(), "boing");
BOOST_CHECK_EQUAL(arr[4].getValStr(), "going");
BOOST_CHECK_EQUAL(arr[5].getValStr(), "400");
BOOST_CHECK_EQUAL(arr[6].getValStr(), "-400");
BOOST_CHECK_EQUAL(arr[7].getValStr(), "-401");
BOOST_CHECK_EQUAL(arr[8].getValStr(), "-40.1");

BOOST_CHECK_EQUAL(arr[999].getValStr(), "");

Expand Down

0 comments on commit 107db98

Please sign in to comment.