diff options
author | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-04-21 20:33:34 +0000 |
---|---|---|
committer | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-04-21 20:33:34 +0000 |
commit | b9e8095bd7c7b1492baf175e1ebf336dc3ff6e4d (patch) | |
tree | e72cc26bb321e8bf90f4e68330674848db54eddf /libstdc++-v3/testsuite/23_containers | |
parent | 61dfea14dbc2e4d8b70a6f1df61bce8aa70340ce (diff) | |
download | gcc-b9e8095bd7c7b1492baf175e1ebf336dc3ff6e4d.tar.gz |
2000-04-21 Benjamin Kosnik <bkoz@redhat.com>
* libstdc++-v3: New directory.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@33317 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers')
6 files changed, 483 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/bitset_ctor.cc b/libstdc++-v3/testsuite/23_containers/bitset_ctor.cc new file mode 100644 index 00000000000..922d47028a0 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset_ctor.cc @@ -0,0 +1,90 @@ +// 1999-06-08 bkoz + +// Copyright (C) 1999 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, 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 General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.5.1 bitset constructors + +#include <string> +#include <bitset> +#ifdef DEBUG_ASSERT +#include <assert.h> +#endif + +bool test01(void) +{ + bool test = true; + + // bitset() + const size_t n1 = 5; + std::bitset<n1> bit01; + for (int i = 0; i < n1; ++i) + test &= !bit01.test(i); + + // bitset(unsigned long) + const size_t n2 = 32; + unsigned long ul1 = 2; + std::bitset<n2> bit02(ul1); + test &= !bit02.test(0); + test &= bit02.test(1); + test &= !bit02.test(2); + + // template<_CharT, _Traits, _Alloc> + // explicit bitset(const basic_string<_C,_T,_A>&, size_type pos, size_type n) + std::string str01("stuff smith sessions"); + const size_t n3 = 128; + try { + std::bitset<n3> bit03(str01, 5); + } + catch(std::invalid_argument& fail) { + test &= true; + } + catch(...) { + test&= false; + } + + std::string str02("010101000011"); + int sz = str02.size(); + try { + std::bitset<n3> bit03(str02, 0); + std::string str03; + for (int i = 0; i < sz; ++i) + str03 += (bit03.test(i) ? '1' : '0'); + reverse(str03.begin(), str03.end()); + test &= str03 == str02; + } + catch(std::invalid_argument& fail) { + test &= false; + } + catch(...) { + test&= false; + } + + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int main() +{ + test01(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/bitset_shift.cc b/libstdc++-v3/testsuite/23_containers/bitset_shift.cc new file mode 100644 index 00000000000..d439edba369 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/bitset_shift.cc @@ -0,0 +1,116 @@ +// 2000-01-15 Anders Widell <awl@hem.passagen.se> + +// Copyright (C) 2000 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, 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 General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#include <string> +#include <set> +#include <bitset> + +#ifdef DEBUG_ASSERT +#include <assert.h> +#endif + +static char original_bits[1024]; +static char left_shifted[1024]; +static char right_shifted[1024]; + +char +random_bit() { + static long x = 1; + return ((x = (3432L*x + 6789L) % 9973L) & 1) + '0'; +} + +void +initialise(size_t size) { + for (size_t i=0; i<size; i++) + original_bits[i] = random_bit(); + + original_bits[size] = '\0'; + left_shifted[size] = '\0'; + right_shifted[size] = '\0'; +} + +void +shift_arrays(size_t shift_step, size_t size) { + for (size_t i=shift_step; i<size; i++) { + right_shifted[i] = original_bits[i-shift_step]; + left_shifted[size-i-1] = original_bits[size+shift_step-i-1]; + } + for (size_t i=0; i<shift_step && i<size; i++) { + right_shifted[i] = '0'; + left_shifted[size-i-1] = '0'; + } +} + +template <size_t size> + bool + do_test() { + bool test = true; + + std::bitset<size> shifted; + std::bitset<size> correct; + + initialise(size); + + //std::bitset<size> original = std::string(original_bits); + std::bitset<size> original = std::bitset<size> (std::string(original_bits)); + + for (size_t shift_step=0; shift_step==0 || shift_step<size; shift_step++) { + shift_arrays(shift_step, size); + + shifted = original; + shifted <<= shift_step; + //correct = std::string(left_shifted); + correct = std::bitset<size> (std::string(left_shifted)); + test &= shifted == correct; + + shifted = original; + shifted >>= shift_step; + //correct = std::string(right_shifted); + correct = std::bitset<size> (std::string(right_shifted)); + test &= shifted == correct; + } + + return test; + } + +bool +test01() { + bool test = true; + + test &= do_test<32>(); + test &= do_test<48>(); + test &= do_test<64>(); + + test &= do_test<511>(); + test &= do_test<513>(); + test &= do_test<997>(); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + +int +main() { + test01(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset.cc b/libstdc++-v3/testsuite/23_containers/multiset.cc new file mode 100644 index 00000000000..5e9c195c84c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset.cc @@ -0,0 +1,73 @@ +// 1999-06-24 bkoz + +// Copyright (C) 1999 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, 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 General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.3.4 template class multiset + +#include <iostream> +#include <set> +#include <algorithm> + +namespace std { + std::ostream& + operator<<(std::ostream& os, std::pair<int, int> const& p) + { return os << p.first << ' ' << p.second; } +} + +bool +operator<(std::pair<int, int> const& lhs, std::pair<int, int> const& rhs) +{ return lhs.first < rhs.first; } + +int main () +{ + typedef std::multiset<std::pair<int, int> >::iterator iterator; + std::pair<int, int> p(69, 0); + std::multiset<std::pair<int, int> > s; + + for (p.second = 0; p.second < 5; ++p.second) + s.insert(p); + for (iterator it = s.begin(); it != s.end(); ++it) + if (it->second < 5) + { + s.insert(it, p); + ++p.second; + } + + // XXX need to use debug-assert here and get this working with an + // ostrinsrtream, that way we can just check the strings for + // equivalance. + std::copy(s.begin(), s.end(), + std::ostream_iterator<std::pair<int, int> >(std::cout, "\n")); + + return 0; +} + +/* output: +69 5 +69 0 +69 6 +69 1 +69 7 +69 2 +69 8 +69 3 +69 9 +69 4 +*/ + diff --git a/libstdc++-v3/testsuite/23_containers/vector_capacity.cc b/libstdc++-v3/testsuite/23_containers/vector_capacity.cc new file mode 100644 index 00000000000..c5207f41361 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector_capacity.cc @@ -0,0 +1,69 @@ +// 1999-05-07 +// bkoz + +// Copyright (C) 1999 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, 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 General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.2.4.2 vector capacity + +#include <vector> +#ifdef DEBUG_ASSERT +#include <assert.h> +#endif + +template<typename T> + struct A { }; + +struct B { }; + +bool test01() +{ + + // non POD types + bool test = true; + std::vector< A<B> > vec01; + typedef std::vector< A<B> >::size_type size_type; + + size_type sz01 = vec01.capacity(); + vec01.reserve(100); + size_type sz02 = vec01.capacity(); + test &= sz02 >= sz01; + + sz01 = vec01.size() + 5; + vec01.resize(sz01); + sz02 = vec01.size(); + test &= sz01 == sz02; + + sz01 = vec01.size() - 5; + vec01.resize(sz01); + sz02 = vec01.size(); + test &= sz01 == sz02; + +#ifdef DEBUG_ASSERT + assert(test); +#endif + + return test; +} + +int main() +{ + test01(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector_ctor.cc b/libstdc++-v3/testsuite/23_containers/vector_ctor.cc new file mode 100644 index 00000000000..204ab55286e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector_ctor.cc @@ -0,0 +1,64 @@ +// 1999-06-29 +// bkoz + +// Copyright (C) 1999 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, 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 General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.2.4.1 vector constructors, copy, and assignment + +#include <vector> +#ifdef DEBUG_ASSERT +#include <assert.h> +#endif + +template<typename T> + struct A { }; + +struct B { }; + +bool test01() +{ + + // 1 + bool test = true; + std::vector< A<B> > vec01; + std::vector< A<B> > vec02(5); + typedef std::vector< A<B> >::size_type size_type; + + vec01 = vec02; + +#ifdef DEBUG_ASSERT + assert(test); +#endif + + return test; +} + +// 2 +template class std::vector<double>; +template class std::vector< A<B> >; + +int main() +{ + test01(); + + return 0; +} + + + diff --git a/libstdc++-v3/testsuite/23_containers/vector_modifiers.cc b/libstdc++-v3/testsuite/23_containers/vector_modifiers.cc new file mode 100644 index 00000000000..b72d749c503 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector_modifiers.cc @@ -0,0 +1,71 @@ +// 1999-11-09 bkoz + +// Copyright (C) 1999 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, 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 General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 23.2.4.3 vector modifiers + +#include <vector> +#ifdef DEBUG_ASSERT +#include <assert.h> +#endif + +template<typename T> + struct A { }; + +struct B { }; + +// vector::insert(iterator, inputiterator first, inputiterator last) +bool test01() +{ + bool test = true; + + // POD types + typedef std::vector<int> vec_POD; + vec_POD vec01; + int i01 = 5; + int* pi01 = &i01; + vec01.insert(vec01.begin(), pi01, pi01 + 1); + + // non POD types + typedef std::vector< A<B> > vec_nonPOD; + vec_nonPOD vec02; + A<B> np01; + A<B>* pnp01 = &np01; + vec02.insert(vec02.begin(), pnp01, pnp01 + 1); + + // Test that assign compiles. + vec01.assign (pi01, pi01 + 1); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + + return test; +} + +int main() +{ + test01(); + + return 0; +} + + + + |