00001 #include <tut/tut.hpp>
00002 #include <vector>
00003 #include <stdexcept>
00004
00005 using std::vector;
00006 using std::logic_error;
00007
00008 namespace tut
00009 {
00010
00011
00012 struct vector_basic
00013 {
00014 vector<int> v;
00015
00016 vector_basic(): v() { }
00017 virtual ~vector_basic() { }
00018 };
00019
00020
00021 typedef test_group<vector_basic> factory;
00022 typedef factory::object object;
00023
00024 }
00025
00026 namespace
00027 {
00028
00029 tut::factory tf("std::vector basic operations");
00030
00031 }
00032
00033 namespace tut
00034 {
00038 template<>
00039 template<>
00040 void object::test<1>()
00041 {
00042 v.push_back(100);
00043 ensure(v.size() == 1);
00044 ensure("size=1", v.size() == 1);
00045 ensure("v[0]=100", v[0] == 100);
00046 }
00047
00051 template<>
00052 template<>
00053 void object::test<23>()
00054 {
00055 v.clear();
00056
00057 throw std::logic_error("no rights");
00058 }
00059
00063 template<>
00064 template<>
00065 void object::test<2>()
00066 {
00067 v.resize(22);
00068 ensure_equals("capacity", 22U, v.size());
00069 }
00070
00074 template<>
00075 template<>
00076 void object::test<3>()
00077 {
00078 int c[] = { 1, 2, 3, 4 };
00079 v = std::vector<int>(&c[0], &c[4]);
00080 ensure_equals("size", v.size(), 4U);
00081 ensure("v[0]", v[0] == 1);
00082 ensure("v[1]", v[1] == 2);
00083 ensure("v[2]", v[2] == 3);
00084 ensure("v[3]", v[3] == 4);
00085 }
00086
00087 }
00088