]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/26_numerics/numeric_arrays/30416.cc
Index: gcc/ChangeLog
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 26_numerics / numeric_arrays / 30416.cc
1 // 2007-01-11 Paolo Carlini <pcarlini@suse.de>
2
3 // Copyright (C) 2007 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 2, or (at your option)
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
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 #include <valarray>
31 #include <testsuite_hooks.h>
32
33 bool
34 comp_vala(const std::valarray<int>& v1, const std::valarray<int>& v2)
35 {
36 if (v1.size() == v2.size())
37 {
38 for (size_t i = 0; i < v1.size(); ++i)
39 if (v1[i] != v2[i])
40 return false;
41 return true;
42 }
43 return false;
44 }
45
46 void
47 init_vala(std::valarray<int>& v, size_t first, size_t last, int val)
48 {
49 for (size_t i = first; i <= last; ++i)
50 v[i] = val++;
51 }
52
53 // libstdc++/30416
54 void test01()
55 {
56 bool test __attribute__((unused)) = true;
57 using namespace std;
58
59 // shift
60 valarray<int> v1;
61 valarray<int> v1_ris(v1.shift(0));
62 VERIFY( comp_vala(v1, v1_ris) );
63
64 valarray<int> v2;
65 valarray<int> v2_ris(v2.shift(10));
66 VERIFY( comp_vala(v2, v2_ris) );
67
68 valarray<int> v3;
69 valarray<int> v3_ris(v3.shift(-10));
70 VERIFY( comp_vala(v3, v3_ris) );
71
72 valarray<int> v4(10);
73 valarray<int> v4_ris(v4.shift(0));
74 VERIFY( comp_vala(v4, v4_ris) );
75
76 valarray<int> v5(10);
77 init_vala(v5, 0, 9, 1);
78 valarray<int> v5_ref(10);
79
80 valarray<int> v5_ris(v5.shift(16));
81 VERIFY( comp_vala(v5_ris, v5_ref) );
82
83 valarray<int> v6(10);
84 init_vala(v6, 0, 9, 1);
85 valarray<int> v6_ref(10);
86
87 valarray<int> v6_ris(v6.shift(-16));
88 VERIFY( comp_vala(v6_ris, v6_ref) );
89
90 valarray<int> v7(10);
91 init_vala(v7, 0, 9, 1);
92 valarray<int> v7_ref(10);
93
94 valarray<int> v7_ris(v7.shift(10));
95 VERIFY( comp_vala(v7_ris, v7_ref) );
96
97 valarray<int> v8(10);
98 init_vala(v8, 0, 9, 1);
99 valarray<int> v8_ref(10);
100
101 valarray<int> v8_ris(v8.shift(-10));
102 VERIFY( comp_vala(v8_ris, v8_ref) );
103
104 valarray<int> v9(10);
105 init_vala(v9, 0, 9, 1);
106 valarray<int> v9_ref(10);
107 init_vala(v9_ref, 0, 3, 7);
108
109 valarray<int> v9_ris(v9.shift(6));
110 VERIFY( comp_vala(v9_ris, v9_ref) );
111
112 valarray<int> v10(10);
113 init_vala(v10, 0, 9, 1);
114 valarray<int> v10_ref(10);
115 init_vala(v10_ref, 6, 9, 1);
116
117 valarray<int> v10_ris(v10.shift(-6));
118 VERIFY( comp_vala(v10_ris, v10_ref) );
119
120 // cshift
121 valarray<int> v11;
122 valarray<int> v11_ris(v11.cshift(0));
123 VERIFY( comp_vala(v11, v11_ris) );
124
125 valarray<int> v12;
126 valarray<int> v12_ris(v12.cshift(10));
127 VERIFY( comp_vala(v12, v12_ris) );
128
129 valarray<int> v13;
130 valarray<int> v13_ris(v13.cshift(-10));
131 VERIFY( comp_vala(v13, v13_ris) );
132
133 valarray<int> v14(10);
134 valarray<int> v14_ris(v14.cshift(0));
135 VERIFY( comp_vala(v14, v14_ris) );
136
137 valarray<int> v15(10);
138 init_vala(v15, 0, 9, 1);
139 valarray<int> v15_ref(10);
140 init_vala(v15_ref, 0, 3, 7);
141 init_vala(v15_ref, 4, 9, 1);
142
143 valarray<int> v15_ris(v15.cshift(16));
144 VERIFY( comp_vala(v15_ris, v15_ref) );
145
146 valarray<int> v16(10);
147 init_vala(v16, 0, 9, 1);
148 valarray<int> v16_ref(10);
149 init_vala(v16_ref, 0, 5, 5);
150 init_vala(v16_ref, 6, 9, 1);
151
152 valarray<int> v16_ris(v16.cshift(-16));
153 VERIFY( comp_vala(v16_ris, v16_ref) );
154
155 valarray<int> v17(10);
156 init_vala(v17, 0, 9, 1);
157
158 valarray<int> v17_ris(v15.cshift(10));
159 VERIFY( comp_vala(v17, v17_ris) );
160
161 valarray<int> v18(10);
162 init_vala(v18, 0, 9, 1);
163
164 valarray<int> v18_ris(v18.cshift(-10));
165 VERIFY( comp_vala(v18, v18_ris) );
166
167 valarray<int> v19(10);
168 init_vala(v19, 0, 9, 1);
169 valarray<int> v19_ref(10);
170 init_vala(v19_ref, 0, 3, 7);
171 init_vala(v19_ref, 4, 9, 1);
172
173 valarray<int> v19_ris(v15.cshift(6));
174 VERIFY( comp_vala(v19_ris, v19_ref) );
175
176 valarray<int> v20(10);
177 init_vala(v20, 0, 9, 1);
178 valarray<int> v20_ref(10);
179 init_vala(v20_ref, 0, 5, 5);
180 init_vala(v20_ref, 6, 9, 1);
181
182 valarray<int> v20_ris(v20.cshift(-6));
183 VERIFY( comp_vala(v20_ris, v20_ref) );
184 }
185
186 int main()
187 {
188 test01();
189 return 0;
190 }