2018-11-05 21:31:30 +11:00
|
|
|
#include <cruft/util/tap.hpp>
|
|
|
|
#include <cruft/util/array/darray.hpp>
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int, char**)
|
|
|
|
{
|
|
|
|
cruft::TAP::logger tap;
|
|
|
|
|
|
|
|
{
|
2018-11-08 14:11:00 +11:00
|
|
|
cruft::darray<8,int> val ({ 0, 1, 2, 3, 4, 5, 6, 7});
|
|
|
|
|
|
|
|
tap.expect_eq (val.size (), 8u, "query for size");
|
|
|
|
|
|
|
|
tap.expect_eq (val.capacity (), decltype(val)::elements, "static vs dynamic query for capacity");
|
|
|
|
|
|
|
|
{
|
|
|
|
auto const sum = std::accumulate (val.cbegin (), val.cend (), 0u);
|
|
|
|
tap.expect_eq (sum, 28u, "accumulate over initializer_list range");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
val.erase (val.begin () + 2);
|
|
|
|
tap.expect_eq (val.size (), 7u, "erasing removes one element");
|
|
|
|
|
|
|
|
auto const sum = std::accumulate (val.cbegin (), val.cend (), 0u);
|
|
|
|
tap.expect_eq (sum, 26u, "erase one element");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Try inserting a value and see if it sticks.
|
|
|
|
//
|
|
|
|
// Ensure that a unique value is used here.
|
|
|
|
// Perform an accumulate to check the rest of the values are there too.
|
|
|
|
val.insert (val.begin () + 4, 13);
|
|
|
|
tap.expect_eq (val[4], 13, "inserted values matches indexed value");
|
|
|
|
auto const sum = std::accumulate (val.cbegin (), val.cend (), 0u);
|
|
|
|
tap.expect_eq (sum, 39u, "accumulate over new array suggests all still present");
|
|
|
|
}
|
2018-11-05 21:31:30 +11:00
|
|
|
}
|
|
|
|
|
2018-11-08 14:11:00 +11:00
|
|
|
|
2018-11-05 21:31:30 +11:00
|
|
|
{
|
2018-11-08 14:11:00 +11:00
|
|
|
cruft::darray<8,int> val ({ 0, 1, 2, 3 });
|
|
|
|
cruft::darray<8,int> const res ({ 0, 1, 13, 13, 13, 2, 3 });
|
2018-11-05 21:31:30 +11:00
|
|
|
|
2018-11-08 14:11:00 +11:00
|
|
|
val.insert (val.begin () + 2, 3, 13);
|
|
|
|
tap.expect_eq (val, res, "trivial insert_n");
|
2018-11-05 21:31:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|