1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <tut/tut.hpp>
#include <vector>
#include <stdexcept>
using std::vector;
using std::logic_error;
namespace tut
{
// Data used by each test
struct vector_basic
{
vector<int> v;
};
// Test group registration
typedef test_group<vector_basic> factory;
typedef factory::object object;
}
namespace
{
tut::factory tf("std::vector basic operations");
}
namespace tut
{
/**
* Checks push_back operation
*/
template<>
template<>
void object::test<1>()
{
v.push_back(100);
ensure(v.size() == 1);
ensure("size=1", v.size() == 1);
ensure("v[0]=100", v[0] == 100);
}
/**
* Checks clear operation
*/
template<>
template<>
void object::test<23>()
{
v.clear();
// imitation of user code exception
throw std::logic_error("no rights");
}
/**
* Checks resize operation
*/
template<>
template<>
void object::test<2>()
{
v.resize(22);
ensure_equals("capacity", 22U, v.size());
}
/**
* Checks range constructor
*/
template<>
template<>
void object::test<3>()
{
int c[] = { 1, 2, 3, 4 };
v = std::vector<int>(&c[0], &c[4]);
ensure_equals("size", v.size(), 4U);
ensure("v[0]", v[0] == 1);
ensure("v[1]", v[1] == 2);
ensure("v[2]", v[2] == 3);
ensure("v[3]", v[3] == 4);
}
}
|