diff options
Diffstat (limited to 'libstdc++-v3/testsuite/26_numerics/valarray')
18 files changed, 1033 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/27867.cc b/libstdc++-v3/testsuite/26_numerics/valarray/27867.cc new file mode 100644 index 000000000..4100aa7c4 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/27867.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2006, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <valarray> +#include <testsuite_hooks.h> + +// libstdc++/27867 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::valarray<int> v1(100, 1); + std::valarray<int> v2(100, 1); + std::valarray<bool> v3(true, 1); + + std::valarray<bool> resl(1); + resl = ((v1 == v2) == v3); + VERIFY( resl[0] == true ); + + std::valarray<bool> resr(1); + resr = (v3 == (v1 == v2)); + VERIFY( resr[0] == true ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/28277.cc b/libstdc++-v3/testsuite/26_numerics/valarray/28277.cc new file mode 100644 index 000000000..7e619c020 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/28277.cc @@ -0,0 +1,43 @@ +// 2006-07-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 Free Software Foundation +// +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <valarray> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + bool test __attribute__((unused)) = true; + + const std::valarray<int> v1(1, 5000000); + + const std::valarray<int> v2 = v1.shift(1); + VERIFY( v2.size() == v1.size() ); + VERIFY( v2[v1.size() - 1] == 0 ); + + const std::valarray<int> v3 = v2.cshift(-1); + VERIFY( v3.size() == v2.size() ); + VERIFY( v3[0] == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/30416.cc b/libstdc++-v3/testsuite/26_numerics/valarray/30416.cc new file mode 100644 index 000000000..4ce8f75ed --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/30416.cc @@ -0,0 +1,181 @@ +// 2007-01-11 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <valarray> +#include <testsuite_hooks.h> + +bool +comp_vala(const std::valarray<int>& v1, const std::valarray<int>& v2) +{ + if (v1.size() == v2.size()) + { + for (size_t i = 0; i < v1.size(); ++i) + if (v1[i] != v2[i]) + return false; + return true; + } + return false; +} + +void +init_vala(std::valarray<int>& v, size_t first, size_t last, int val) +{ + for (size_t i = first; i <= last; ++i) + v[i] = val++; +} + +// libstdc++/30416 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + // shift + valarray<int> v1; + valarray<int> v1_ris(v1.shift(0)); + VERIFY( comp_vala(v1, v1_ris) ); + + valarray<int> v2; + valarray<int> v2_ris(v2.shift(10)); + VERIFY( comp_vala(v2, v2_ris) ); + + valarray<int> v3; + valarray<int> v3_ris(v3.shift(-10)); + VERIFY( comp_vala(v3, v3_ris) ); + + valarray<int> v4(10); + valarray<int> v4_ris(v4.shift(0)); + VERIFY( comp_vala(v4, v4_ris) ); + + valarray<int> v5(10); + init_vala(v5, 0, 9, 1); + valarray<int> v5_ref(10); + + valarray<int> v5_ris(v5.shift(16)); + VERIFY( comp_vala(v5_ris, v5_ref) ); + + valarray<int> v6(10); + init_vala(v6, 0, 9, 1); + valarray<int> v6_ref(10); + + valarray<int> v6_ris(v6.shift(-16)); + VERIFY( comp_vala(v6_ris, v6_ref) ); + + valarray<int> v7(10); + init_vala(v7, 0, 9, 1); + valarray<int> v7_ref(10); + + valarray<int> v7_ris(v7.shift(10)); + VERIFY( comp_vala(v7_ris, v7_ref) ); + + valarray<int> v8(10); + init_vala(v8, 0, 9, 1); + valarray<int> v8_ref(10); + + valarray<int> v8_ris(v8.shift(-10)); + VERIFY( comp_vala(v8_ris, v8_ref) ); + + valarray<int> v9(10); + init_vala(v9, 0, 9, 1); + valarray<int> v9_ref(10); + init_vala(v9_ref, 0, 3, 7); + + valarray<int> v9_ris(v9.shift(6)); + VERIFY( comp_vala(v9_ris, v9_ref) ); + + valarray<int> v10(10); + init_vala(v10, 0, 9, 1); + valarray<int> v10_ref(10); + init_vala(v10_ref, 6, 9, 1); + + valarray<int> v10_ris(v10.shift(-6)); + VERIFY( comp_vala(v10_ris, v10_ref) ); + + // cshift + valarray<int> v11; + valarray<int> v11_ris(v11.cshift(0)); + VERIFY( comp_vala(v11, v11_ris) ); + + valarray<int> v12; + valarray<int> v12_ris(v12.cshift(10)); + VERIFY( comp_vala(v12, v12_ris) ); + + valarray<int> v13; + valarray<int> v13_ris(v13.cshift(-10)); + VERIFY( comp_vala(v13, v13_ris) ); + + valarray<int> v14(10); + valarray<int> v14_ris(v14.cshift(0)); + VERIFY( comp_vala(v14, v14_ris) ); + + valarray<int> v15(10); + init_vala(v15, 0, 9, 1); + valarray<int> v15_ref(10); + init_vala(v15_ref, 0, 3, 7); + init_vala(v15_ref, 4, 9, 1); + + valarray<int> v15_ris(v15.cshift(16)); + VERIFY( comp_vala(v15_ris, v15_ref) ); + + valarray<int> v16(10); + init_vala(v16, 0, 9, 1); + valarray<int> v16_ref(10); + init_vala(v16_ref, 0, 5, 5); + init_vala(v16_ref, 6, 9, 1); + + valarray<int> v16_ris(v16.cshift(-16)); + VERIFY( comp_vala(v16_ris, v16_ref) ); + + valarray<int> v17(10); + init_vala(v17, 0, 9, 1); + + valarray<int> v17_ris(v15.cshift(10)); + VERIFY( comp_vala(v17, v17_ris) ); + + valarray<int> v18(10); + init_vala(v18, 0, 9, 1); + + valarray<int> v18_ris(v18.cshift(-10)); + VERIFY( comp_vala(v18, v18_ris) ); + + valarray<int> v19(10); + init_vala(v19, 0, 9, 1); + valarray<int> v19_ref(10); + init_vala(v19_ref, 0, 3, 7); + init_vala(v19_ref, 4, 9, 1); + + valarray<int> v19_ris(v15.cshift(6)); + VERIFY( comp_vala(v19_ris, v19_ref) ); + + valarray<int> v20(10); + init_vala(v20, 0, 9, 1); + valarray<int> v20_ref(10); + init_vala(v20_ref, 0, 5, 5); + init_vala(v20_ref, 6, 9, 1); + + valarray<int> v20_ris(v20.cshift(-6)); + VERIFY( comp_vala(v20_ris, v20_ref) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/33084.cc b/libstdc++-v3/testsuite/26_numerics/valarray/33084.cc new file mode 100644 index 000000000..918414197 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/33084.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// { dg-do compile } + +#include <valarray> + +// libstdc++/33084 +void test01() +{ + std::valarray<char> vc(char(0), 10); + std::valarray<bool> res(10); + char c(0); + + res = vc == vc; + res = vc == c; + res = c == vc; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/40691.cc b/libstdc++-v3/testsuite/26_numerics/valarray/40691.cc new file mode 100644 index 000000000..5524835a6 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/40691.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do compile } + +#include <valarray> + +// PR libstdc++/40691 +void test01() +{ + const std::valarray<int> vi(12); + std::valarray<bool> vb1(12); + std::valarray<bool> vb2(3); + std::slice s(0,3,4); + + vb1 = !vi; + vb2 = !(std::valarray<int>)vi[s]; + vb2 = !vi[s]; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/algo.cc b/libstdc++-v3/testsuite/26_numerics/valarray/algo.cc new file mode 100644 index 000000000..c12497611 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/algo.cc @@ -0,0 +1,31 @@ +// 19990404 gdr + +// Copyright (C) 1999, 2000, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <valarray> + +int main() +{ + // 02: algo + using std::valarray; + valarray<double> b, c; + double m __attribute__((unused)) = std::abs(b - c).max(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/binary_closure.cc b/libstdc++-v3/testsuite/26_numerics/valarray/binary_closure.cc new file mode 100644 index 000000000..7dbcfbd52 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/binary_closure.cc @@ -0,0 +1,37 @@ +// 19990805 gdr +// +// XXX: to impove later. +// Origin: Andreas Amann <amann@physik.tu-berlin.de> +// CXXFLAGS: -g + +#include <iostream> +#include <valarray> + + +int main() +{ + std::valarray<double> a(10), b(10), c(10), d(10); + + a = 1.2; + b = 3.1; + + c = 4.0; + + d = ( 2.0 * b + a ); // works + std::cout << "d[4] = " << d[4] << std::endl; + + d = (a * 2.0 + b ); // works + std::cout << "d[4] = " << d[4] << std::endl; + + d = (a + b * 2.0 ); // segfaults! + std::cout << "d[4] = " << d[4] << std::endl; + d = (a + 2.0* b ); + + std::cout << "d[4] = " << d[4] << std::endl; + d = (a + 2.0* b ); + std::cout << "d[4] = " << d[4] << std::endl; + d = (a + 2.0* b ); + + std::cout << "d[4] = " << d[4] << std::endl; + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/const_bracket.cc b/libstdc++-v3/testsuite/26_numerics/valarray/const_bracket.cc new file mode 100644 index 000000000..abd9cd873 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/const_bracket.cc @@ -0,0 +1,39 @@ +// 20010518 gdr + +// Copyright (C) 2001, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <valarray> + +// dg-do compile + +template<typename P> + void copy(P, std::size_t) { } + +template<typename T> + void test(const std::valarray<T>& v) + { + copy(&v[0], v.size()); + } + +int main() +{ + std::valarray<double> v(190); + test(v); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/dr543.cc b/libstdc++-v3/testsuite/26_numerics/valarray/dr543.cc new file mode 100644 index 000000000..e474ef998 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/dr543.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2006, 2009 Free Software Foundation +// +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <valarray> +#include <testsuite_hooks.h> + +// DR 543. valarray slice default constructor +void test01() +{ + bool test __attribute__((unused)) = true; + + std::valarray<int> v1(10); + std::valarray<int> v2 = v1[std::slice()]; + VERIFY( v2.size() == 0 ); + + std::valarray<int> v3(10); + std::valarray<int> v4 = v3[std::gslice()]; + VERIFY( v4.size() == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/dr630-1.cc b/libstdc++-v3/testsuite/26_numerics/valarray/dr630-1.cc new file mode 100644 index 000000000..9e5d14a28 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/dr630-1.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2009 Free Software Foundation +// +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <valarray> +#include <testsuite_hooks.h> + +// DR 630. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + valarray<int> v1; + const valarray<int> v2(-1, 10000); + + v1 = v2; + VERIFY( v1.size() == v2.size() ); + VERIFY( (v1 == v2).min() == true ); + + valarray<int> v3(0, 10000); + const valarray<int> v4; + + v3 = v4; + VERIFY( v3.size() == v4.size() ); + VERIFY( v3.size() == 0 ); + + valarray<int> v5(0, 100); + const valarray<int> v6(-1, 10000); + + v5 = v6; + VERIFY( v5.size() == v6.size() ); + VERIFY( (v5 == v6).min() == true ); + + valarray<int> v7(0, 10000); + const valarray<int> v8(-1, 100); + + v7 = v8; + VERIFY( v7.size() == v8.size() ); + VERIFY( (v7 == v8).min() == true ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/dr630-2.cc b/libstdc++-v3/testsuite/26_numerics/valarray/dr630-2.cc new file mode 100644 index 000000000..ddb6bcaff --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/dr630-2.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2009 Free Software Foundation +// +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <valarray> +#include <testsuite_hooks.h> + +// DR 630. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + valarray<int> v1; + + v1 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; + VERIFY( v1.size() == 10 ); + VERIFY( v1.min() == -1 ); + VERIFY( v1.max() == -1 ); + + valarray<int> v2(0, 10); + + v2 = { }; + VERIFY( v2.size() == 0 ); + + valarray<int> v3(0, 10); + + v3 = { -1, -1, -1, -1, -1 }; + VERIFY( v3.size() == 5 ); + VERIFY( v3.min() == -1 ); + VERIFY( v3.max() == -1 ); + + valarray<int> v4(0, 5); + + v4 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; + VERIFY( v4.size() == 10 ); + VERIFY( v4.min() == -1 ); + VERIFY( v4.max() == -1 ); + + valarray<int> v5(0, 10); + + v5 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; + VERIFY( v5.size() == 10 ); + VERIFY( v5.min() == -1 ); + VERIFY( v5.max() == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/init-list.cc b/libstdc++-v3/testsuite/26_numerics/valarray/init-list.cc new file mode 100644 index 000000000..1c0665901 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/init-list.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2008, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. +// + +// { dg-options "-std=gnu++0x" } + +#include <valarray> +#include <testsuite_hooks.h> + +using namespace std; + +int test01() +{ + bool test __attribute__((unused)) = true; + + valarray<int> m({ 1, 5, 37 }); + VERIFY(m.size() == 3); + VERIFY(m[0] == 1); + VERIFY(m[1] == 5); + VERIFY(m[2] == 37); + + m = { 28, 37, 102 }; + VERIFY(m.size() == 3); + VERIFY(m[0] == 28); + VERIFY(m[1] == 37); + VERIFY(m[2] == 102); + + return test; +} + +int main() +{ + __gnu_test::set_memory_limits(); + test01(); +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/name_lookup.cc b/libstdc++-v3/testsuite/26_numerics/valarray/name_lookup.cc new file mode 100644 index 000000000..65d679a21 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/name_lookup.cc @@ -0,0 +1,133 @@ +// 2002-08-02 gdr + +// Copyright (C) 2002, 2003, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Test name lookup resolutions for standard functions applied to an +// array expression. +// { dg-do compile } + +#include <valarray> + +namespace My +{ + struct Number + { + operator bool() const; + }; + + Number operator+(Number); + Number operator-(Number); + Number operator~(Number); + + bool operator!(Number); + + Number operator+(Number, Number); + Number operator-(Number, Number); + Number operator*(Number, Number); + Number operator/(Number, Number); + Number operator%(Number, Number); + + Number operator^(Number, Number); + Number operator&(Number, Number); + Number operator|(Number, Number); + + Number operator<<(Number, Number); + Number operator>>(Number, Number); + + bool operator==(Number, Number); + bool operator!=(Number, Number); + bool operator<(Number, Number); + bool operator<=(Number, Number); + bool operator>(Number, Number); + bool operator>=(Number, Number); + + Number abs(Number); + + Number cos(Number); + Number cosh(Number); + Number acos(Number); + + Number sin(Number); + Number sinh(Number); + Number asin(Number); + + Number tan(Number); + Number tanh(Number); + Number atan(Number); + + Number exp(Number); + Number log(Number); + Number log10(Number); + Number sqrt(Number); + + Number atan2(Number, Number); + Number pow(Number, Number); +} + +int main() +{ + typedef std::valarray<My::Number> Array; + Array u(10), v(10); + v = +u; + v = -u; + v = ~u; + std::valarray<bool> z = !u; + + v = abs(u); + + v = cos(u); + v = cosh(u); + v = acos(u); + + v = sin(u); + v = sinh(u); + v = asin(u); + + v = tan(u); + v = tanh(u); + v = atan(u); + + v = exp(u); + v = log(u); + v = log10(u); + v = sqrt(u); + + Array w = u + v; + w = u - v; + w = u * v; + w = u / v; + w = u % v; + + w = u ^ v; + w = u & v; + w = u | v; + + w = u << v; + w = u >> v; + + z = u == v; + z = u != v; + z = u < v; + z = u <= v; + z = u > v; + z = u >= v; + + w = atan2(u, v); + w = pow(u, v); +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/operators.cc b/libstdc++-v3/testsuite/26_numerics/valarray/operators.cc new file mode 100644 index 000000000..82904334a --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/operators.cc @@ -0,0 +1,68 @@ +// { dg-do run } +// 2003-02-03 Volker Reichelt <reichelt@igpm.rwth-aachen.de> + +// Copyright (C) 2003, 2009 Free Software Foundation +// +// 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <valarray> +#include <testsuite_hooks.h> + +void test01() // check unary operators +{ + bool test __attribute__((unused)) = true; + std::valarray<int> u(1); + u[0]=1; + + VERIFY( (+u)[0] == +1 ); + VERIFY( (-u)[0] == -1 ); + VERIFY( (!u)[0] == !1 ); + VERIFY( (~u)[0] == ~1 ); +} + +void test02() // check binary operators +{ + bool test __attribute__((unused)) = true; + std::valarray<int> u(1), v(1); + u[0]=1; + v[0]=3; + + VERIFY( (u+ v)[0] == (1+ 3) ); + VERIFY( (u- v)[0] == (1- 3) ); + VERIFY( (u* v)[0] == (1* 3) ); + VERIFY( (u/ v)[0] == (1/ 3) ); + VERIFY( (u% v)[0] == (1% 3) ); + VERIFY( (u^ v)[0] == (1^ 3) ); + VERIFY( (u& v)[0] == (1& 3) ); + VERIFY( (u| v)[0] == (1| 3) ); + VERIFY( (u<<v)[0] == (1<<3) ); + VERIFY( (u>>v)[0] == (1>>3) ); + VERIFY( (u&&v)[0] == (1&&3) ); + VERIFY( (u||v)[0] == (1||3) ); + VERIFY( (u==v)[0] == (1==3) ); + VERIFY( (u!=v)[0] == (1!=3) ); + VERIFY( (u< v)[0] == (1< 3) ); + VERIFY( (u> v)[0] == (1> 3) ); + VERIFY( (u<=v)[0] == (1<=3) ); + VERIFY( (u>=v)[0] == (1>=3) ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/range_access.cc b/libstdc++-v3/testsuite/26_numerics/valarray/range_access.cc new file mode 100644 index 000000000..10f67dac8 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/range_access.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 26.6.10 valarray range access: [valarray.range] + +#include <valarray> + +void +test01() +{ + std::valarray<double> va{1.0, 2.0, 3.0}; + std::begin(va); + std::end(va); +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/26_numerics/valarray/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..d63ea7c75 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/requirements/explicit_instantiation.cc @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// This file tests explicit instantiation of library containers. + +#include <valarray> + +template class std::valarray<short>; diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/requirements/typedefs.cc b/libstdc++-v3/testsuite/26_numerics/valarray/requirements/typedefs.cc new file mode 100644 index 000000000..6501d0738 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/requirements/typedefs.cc @@ -0,0 +1,30 @@ +// { dg-do compile } + +// Copyright (C) 2007, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 6.2.2 Class template array + +#include <valarray> + +void test01() +{ + // Check for required typedefs + typedef std::valarray<int> test_type; + typedef test_type::value_type value_type; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/subset_assignment.cc b/libstdc++-v3/testsuite/26_numerics/valarray/subset_assignment.cc new file mode 100644 index 000000000..00ec70b60 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/subset_assignment.cc @@ -0,0 +1,78 @@ +// 2004-01-03 Jerry Quinn <jlquinn@optonline.net> + +// Copyright (C) 2004, 2009 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 3, 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 COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// PR 3247 + +// This is DR-253. Test for accessible assignment-operators. +#include <valarray> +#include <testsuite_hooks.h> + +bool check_array(std::valarray<double>& a, double b[]) +{ + for (unsigned int i=0; i < a.size(); i++) + if (a[i] != b[i]) return false; + return true; +} + +int main() +{ + std::valarray<double> val_d(10); // 0 1 2 3 4 5 6 7 8 9 + std::valarray<double> val_d1(10); // 10 9 8 7 6 5 4 3 2 1 + + for (int i=0; i< 10; i++) { val_d[i] = 10; val_d1[i] = i; } + std::valarray<double> val_c(val_d); + std::valarray<double> val_f(val_d); + std::valarray<double> val_g(val_d); + + std::slice slc(1, 3, 3); // 1 4 7 + val_d[slc] = val_d1[slc]; + + double ans1[10] = {10, 1, 10, 10, 4, 10, 10, 7, 10, 10}; + VERIFY(check_array(val_d, ans1)); + + std::valarray<std::size_t> val_size(2); + std::valarray<std::size_t> val_stride(2); + val_size[0] = 2; val_size[1] = 3; + val_stride[0] = 4; val_stride[1] = 1; + + std::gslice gslc(1, val_size, val_stride); + val_c[gslc] = val_d1[gslc]; + + double ans2[10] = {10, 1, 2, 3, 10, 5, 6, 7, 10, 10}; + VERIFY(check_array(val_c, ans2)); + + std::valarray<bool> val_b(false, 10); + val_b[2] = val_b[6] = val_b[9] = true; + val_f[val_b] = val_d1[val_b]; + + double ans3[10] = {10, 10, 2, 10, 10, 10, 6, 10, 10, 9}; + VERIFY(check_array(val_f, ans3)); + + size_t addr[] = {1, 2, 3, 4, 5}; + size_t addr1[] = {2, 7, 1, 9, 4}; + std::valarray<std::size_t> val_indirect(addr, 5); + std::valarray<std::size_t> val_indirect1(addr1, 5); + val_g[val_indirect] = val_d1[val_indirect1]; + + double ans4[10] = {10, 2, 7, 1, 9, 4, 10, 10, 10, 10}; + VERIFY(check_array(val_g, ans4)); + + return 0; +}; |