susumu.yata
null+****@clear*****
Fri Sep 5 11:30:58 JST 2014
susumu.yata 2014-09-05 11:30:58 +0900 (Fri, 05 Sep 2014) New Revision: 5c856c3bace22eaa132218f0e0b2490b389f6f19 https://github.com/groonga/grnxx/commit/5c856c3bace22eaa132218f0e0b2490b389f6f19 Message: Add tests for Array<Bool>. Added files: test/test_array.cpp Modified files: .gitignore test/Makefile.am Modified: .gitignore (+1 -0) =================================================================== --- .gitignore 2014-09-05 11:13:45 +0900 (0e9fb88) +++ .gitignore 2014-09-05 11:30:58 +0900 (e1895f7) @@ -29,6 +29,7 @@ oprofile_data/ src/grnxx stamp-h1 test/*.trs +test/test_array test/test_db test/test_table test/test_column Modified: test/Makefile.am (+4 -0) =================================================================== --- test/Makefile.am 2014-09-05 11:13:45 +0900 (cc22b45) +++ test/Makefile.am 2014-09-05 11:30:58 +0900 (462e5ca) @@ -1,4 +1,5 @@ TESTS = \ + test_array \ test_db \ test_table \ test_column \ @@ -9,6 +10,9 @@ TESTS = \ check_PROGRAMS = $(TESTS) +test_array_SOURCES = test_array.cpp +test_array_LDADD = $(top_srcdir)/lib/grnxx/libgrnxx.la + test_db_SOURCES = test_db.cpp test_db_LDADD = $(top_srcdir)/lib/grnxx/libgrnxx.la Added: test/test_array.cpp (+84 -0) 100644 =================================================================== --- /dev/null +++ test/test_array.cpp 2014-09-05 11:30:58 +0900 (c5da81c) @@ -0,0 +1,84 @@ +/* + Copyright (C) 2012-2014 Brazil, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include <cassert> +#include <iostream> +#include <random> +#include <vector> + +#include "grnxx/array.hpp" +#include "grnxx/error.hpp" + +std::mt19937_64 mersenne_twister; + +void test_bool() { + grnxx::Error error; + + grnxx::Array<grnxx::Bool> array; + assert(array.size() == 0); + assert(array.capacity() == 0); + + assert(array.push_back(&error, true)); + assert(array.size() == 1); + assert(array.capacity() == 64); + assert(array[0]); + + assert(array.push_back(&error, false)); + assert(array.size() == 2); + assert(array.capacity() == 64); + assert(array[0]); + assert(!array[1]); + + assert(array.resize(&error, 200, true)); + assert(array.size() == 200); + assert(array.capacity() == 256); + assert(array[0]); + assert(!array[1]); + for (grnxx::Int i = 2; i < 200; ++i) { + assert(array.get(i)); + } + + constexpr grnxx::Int NUM_ROWS = 1 << 20; + + assert(array.resize(&error, NUM_ROWS, false)); + assert(array.size() == NUM_ROWS); + assert(array.capacity() == NUM_ROWS); + assert(array[0]); + assert(!array[1]); + for (grnxx::Int i = 2; i < 200; ++i) { + assert(array.get(i)); + } + for (grnxx::Int i = 200; i < NUM_ROWS; ++i) { + assert(!array.get(i)); + } + + std::vector<bool> values(NUM_ROWS); + for (grnxx::Int i = 0; i < NUM_ROWS; ++i) { + values[i] = (mersenne_twister() & 1) != 0; + array.set(i, values[i]); + assert(array[i] == values[i]); + } + + for (grnxx::Int i = 0; i < NUM_ROWS; ++i) { + assert(array[i] == values[i]); + } +} + +int main() { + test_bool(); + return 0; +} -------------- next part -------------- HTML����������������������������...Download