]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/26_numerics/valarray/30416.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 26_numerics / valarray / 30416.cc
CommitLineData
8e768214
PC
1// 2007-01-11 Paolo Carlini <pcarlini@suse.de>
2
99dee823 3// Copyright (C) 2007-2021 Free Software Foundation, Inc.
8e768214
PC
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
8e768214
PC
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
8e768214
PC
20
21#include <valarray>
22#include <testsuite_hooks.h>
23
24bool
25comp_vala(const std::valarray<int>& v1, const std::valarray<int>& v2)
26{
27 if (v1.size() == v2.size())
28 {
29 for (size_t i = 0; i < v1.size(); ++i)
30 if (v1[i] != v2[i])
31 return false;
32 return true;
33 }
34 return false;
35}
36
37void
38init_vala(std::valarray<int>& v, size_t first, size_t last, int val)
39{
40 for (size_t i = first; i <= last; ++i)
41 v[i] = val++;
42}
43
44// libstdc++/30416
45void test01()
46{
8e768214
PC
47 using namespace std;
48
49 // shift
50 valarray<int> v1;
51 valarray<int> v1_ris(v1.shift(0));
52 VERIFY( comp_vala(v1, v1_ris) );
53
54 valarray<int> v2;
55 valarray<int> v2_ris(v2.shift(10));
56 VERIFY( comp_vala(v2, v2_ris) );
57
58 valarray<int> v3;
59 valarray<int> v3_ris(v3.shift(-10));
60 VERIFY( comp_vala(v3, v3_ris) );
61
62 valarray<int> v4(10);
63 valarray<int> v4_ris(v4.shift(0));
64 VERIFY( comp_vala(v4, v4_ris) );
65
66 valarray<int> v5(10);
67 init_vala(v5, 0, 9, 1);
68 valarray<int> v5_ref(10);
69
70 valarray<int> v5_ris(v5.shift(16));
71 VERIFY( comp_vala(v5_ris, v5_ref) );
72
73 valarray<int> v6(10);
74 init_vala(v6, 0, 9, 1);
75 valarray<int> v6_ref(10);
76
77 valarray<int> v6_ris(v6.shift(-16));
78 VERIFY( comp_vala(v6_ris, v6_ref) );
79
80 valarray<int> v7(10);
81 init_vala(v7, 0, 9, 1);
82 valarray<int> v7_ref(10);
83
84 valarray<int> v7_ris(v7.shift(10));
85 VERIFY( comp_vala(v7_ris, v7_ref) );
86
87 valarray<int> v8(10);
88 init_vala(v8, 0, 9, 1);
89 valarray<int> v8_ref(10);
90
91 valarray<int> v8_ris(v8.shift(-10));
92 VERIFY( comp_vala(v8_ris, v8_ref) );
93
94 valarray<int> v9(10);
95 init_vala(v9, 0, 9, 1);
96 valarray<int> v9_ref(10);
97 init_vala(v9_ref, 0, 3, 7);
98
99 valarray<int> v9_ris(v9.shift(6));
100 VERIFY( comp_vala(v9_ris, v9_ref) );
101
102 valarray<int> v10(10);
103 init_vala(v10, 0, 9, 1);
104 valarray<int> v10_ref(10);
105 init_vala(v10_ref, 6, 9, 1);
106
107 valarray<int> v10_ris(v10.shift(-6));
108 VERIFY( comp_vala(v10_ris, v10_ref) );
109
110 // cshift
111 valarray<int> v11;
112 valarray<int> v11_ris(v11.cshift(0));
113 VERIFY( comp_vala(v11, v11_ris) );
114
115 valarray<int> v12;
116 valarray<int> v12_ris(v12.cshift(10));
117 VERIFY( comp_vala(v12, v12_ris) );
118
119 valarray<int> v13;
120 valarray<int> v13_ris(v13.cshift(-10));
121 VERIFY( comp_vala(v13, v13_ris) );
122
123 valarray<int> v14(10);
124 valarray<int> v14_ris(v14.cshift(0));
125 VERIFY( comp_vala(v14, v14_ris) );
126
127 valarray<int> v15(10);
128 init_vala(v15, 0, 9, 1);
129 valarray<int> v15_ref(10);
130 init_vala(v15_ref, 0, 3, 7);
131 init_vala(v15_ref, 4, 9, 1);
132
133 valarray<int> v15_ris(v15.cshift(16));
134 VERIFY( comp_vala(v15_ris, v15_ref) );
135
136 valarray<int> v16(10);
137 init_vala(v16, 0, 9, 1);
138 valarray<int> v16_ref(10);
139 init_vala(v16_ref, 0, 5, 5);
140 init_vala(v16_ref, 6, 9, 1);
141
142 valarray<int> v16_ris(v16.cshift(-16));
143 VERIFY( comp_vala(v16_ris, v16_ref) );
144
145 valarray<int> v17(10);
146 init_vala(v17, 0, 9, 1);
147
148 valarray<int> v17_ris(v15.cshift(10));
149 VERIFY( comp_vala(v17, v17_ris) );
150
151 valarray<int> v18(10);
152 init_vala(v18, 0, 9, 1);
153
154 valarray<int> v18_ris(v18.cshift(-10));
155 VERIFY( comp_vala(v18, v18_ris) );
156
157 valarray<int> v19(10);
158 init_vala(v19, 0, 9, 1);
159 valarray<int> v19_ref(10);
160 init_vala(v19_ref, 0, 3, 7);
161 init_vala(v19_ref, 4, 9, 1);
162
163 valarray<int> v19_ris(v15.cshift(6));
164 VERIFY( comp_vala(v19_ris, v19_ref) );
165
166 valarray<int> v20(10);
167 init_vala(v20, 0, 9, 1);
168 valarray<int> v20_ref(10);
169 init_vala(v20_ref, 0, 5, 5);
170 init_vala(v20_ref, 6, 9, 1);
171
172 valarray<int> v20_ris(v20.cshift(-6));
173 VERIFY( comp_vala(v20_ris, v20_ref) );
174}
175
176int main()
177{
178 test01();
179 return 0;
180}