susumu.yata
null+****@clear*****
Fri Sep 5 17:34:15 JST 2014
susumu.yata 2014-09-05 17:34:15 +0900 (Fri, 05 Sep 2014) New Revision: a1577679dcc7d01d11d33a1b9f9f36d520b50c36 https://github.com/groonga/grnxx/commit/a1577679dcc7d01d11d33a1b9f9f36d520b50c36 Message: Add tests for Array<Int>. Modified files: test/test_array.cpp Modified: test/test_array.cpp (+71 -1) =================================================================== --- test/test_array.cpp 2014-09-05 17:31:52 +0900 (e4981d1) +++ test/test_array.cpp 2014-09-05 17:34:15 +0900 (b8875f2) @@ -66,7 +66,7 @@ void test_bool() { assert(!array.get(i)); } - std::vector<bool> values(NUM_ROWS); + std::vector<grnxx::Bool> values(NUM_ROWS); for (grnxx::Int i = 0; i < NUM_ROWS; ++i) { values[i] = (mersenne_twister() & 1) != 0; array.set(i, values[i]); @@ -85,7 +85,77 @@ void test_bool() { assert(array2.capacity() == NUM_ROWS); } +void test_int() { + grnxx::Error error; + + grnxx::Array<grnxx::Int> array; + assert(array.size() == 0); + assert(array.capacity() == 0); + + assert(array.push_back(&error, 123)); + assert(array.size() == 1); + assert(array.capacity() == 1); + assert(array[0] == 123); + + assert(array.push_back(&error, 456)); + assert(array.size() == 2); + assert(array.capacity() == 2); + assert(array[0] == 123); + assert(array[1] == 456); + + assert(array.push_back(&error, 789)); + assert(array.size() == 3); + assert(array.capacity() == 4); + assert(array[0] == 123); + assert(array[1] == 456); + assert(array[2] == 789); + + assert(array.resize(&error, 200, 12345)); + assert(array.size() == 200); + assert(array.capacity() == 200); + assert(array[0] == 123); + assert(array[1] == 456); + assert(array[2] == 789); + for (grnxx::Int i = 3; i < 200; ++i) { + assert(array[i] == 12345); + } + + constexpr grnxx::Int NUM_ROWS = 1 << 20; + + assert(array.resize(&error, NUM_ROWS, 0)); + assert(array.size() == NUM_ROWS); + assert(array.capacity() == NUM_ROWS); + assert(array[0] == 123); + assert(array[1] == 456); + assert(array[2] == 789); + for (grnxx::Int i = 3; i < 200; ++i) { + assert(array[i] == 12345); + } + for (grnxx::Int i = 200; i < NUM_ROWS; ++i) { + assert(array[i] == 0); + } + + std::vector<grnxx::Int> values(NUM_ROWS); + for (grnxx::Int i = 0; i < NUM_ROWS; ++i) { + values[i] = mersenne_twister(); + array[i] = values[i]; + assert(array[i] == values[i]); + } + + for (grnxx::Int i = 0; i < NUM_ROWS; ++i) { + assert(array[i] == values[i]); + } + + grnxx::Array<grnxx::Int> array2; + array2 = std::move(array); + assert(array.size() == 0); + assert(array.capacity() == 0); + assert(array2.size() == NUM_ROWS); + assert(array2.capacity() == NUM_ROWS); +} + int main() { test_bool(); + test_int(); return 0; } -------------- next part -------------- HTML����������������������������... 다운로드