summaryrefslogtreecommitdiff
path: root/test/std/numerics/numarray/template.valarray/valarray.members
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/numerics/numarray/template.valarray/valarray.members')
-rw-r--r--test/std/numerics/numarray/template.valarray/valarray.members/apply_cref.pass.cpp51
-rw-r--r--test/std/numerics/numarray/template.valarray/valarray.members/apply_value.pass.cpp51
-rw-r--r--test/std/numerics/numarray/template.valarray/valarray.members/cshift.pass.cpp127
-rw-r--r--test/std/numerics/numarray/template.valarray/valarray.members/max.pass.cpp40
-rw-r--r--test/std/numerics/numarray/template.valarray/valarray.members/min.pass.cpp40
-rw-r--r--test/std/numerics/numarray/template.valarray/valarray.members/resize.pass.cpp41
-rw-r--r--test/std/numerics/numarray/template.valarray/valarray.members/shift.pass.cpp127
-rw-r--r--test/std/numerics/numarray/template.valarray/valarray.members/size.pass.cpp41
-rw-r--r--test/std/numerics/numarray/template.valarray/valarray.members/sum.pass.cpp28
-rw-r--r--test/std/numerics/numarray/template.valarray/valarray.members/swap.pass.cpp89
10 files changed, 635 insertions, 0 deletions
diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/apply_cref.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/apply_cref.pass.cpp
new file mode 100644
index 0000000000000..919a3a5e49976
--- /dev/null
+++ b/test/std/numerics/numarray/template.valarray/valarray.members/apply_cref.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class valarray;
+
+// valarray apply(value_type f(const value_type&)) const;
+
+#include <valarray>
+#include <cassert>
+
+typedef int T;
+
+T f(const T& t) {return t + 5;}
+
+int main()
+{
+ {
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.apply(f);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ const unsigned N1 = 0;
+ std::valarray<T> v1;
+ std::valarray<T> v2 = v1.apply(f);
+ assert(v2.size() == N1);
+ }
+ {
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = (v1+v1).apply(f);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+}
diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/apply_value.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/apply_value.pass.cpp
new file mode 100644
index 0000000000000..dc7a1a100a21d
--- /dev/null
+++ b/test/std/numerics/numarray/template.valarray/valarray.members/apply_value.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class valarray;
+
+// valarray apply(value_type f(value_type)) const;
+
+#include <valarray>
+#include <cassert>
+
+typedef int T;
+
+T f(T t) {return t + 5;}
+
+int main()
+{
+ {
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.apply(f);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ const unsigned N1 = 0;
+ std::valarray<T> v1;
+ std::valarray<T> v2 = v1.apply(f);
+ assert(v2.size() == N1);
+ }
+ {
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = (v1+v1).apply(f);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+}
diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/cshift.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/cshift.pass.cpp
new file mode 100644
index 0000000000000..601a6df8d5e54
--- /dev/null
+++ b/test/std/numerics/numarray/template.valarray/valarray.members/cshift.pass.cpp
@@ -0,0 +1,127 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class valarray;
+
+// valarray cshift(int i) const;
+
+#include <valarray>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.cshift(0);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.cshift(3);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.cshift(10);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.cshift(17);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.cshift(-3);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.cshift(-10);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.cshift(-17);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ const unsigned N1 = 0;
+ std::valarray<T> v1;
+ std::valarray<T> v2 = v1.cshift(-17);
+ assert(v2.size() == N1);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {8, 10, 12, 14, 16, 18, 20, 2, 4, 6};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = (v1 + v1).cshift(3);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {16, 18, 20, 2, 4, 6, 8, 10, 12, 14};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = (v1 + v1).cshift(-3);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+}
diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/max.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/max.pass.cpp
new file mode 100644
index 0000000000000..697d4cd19ed61
--- /dev/null
+++ b/test/std/numerics/numarray/template.valarray/valarray.members/max.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class valarray;
+
+// value_type max() const;
+
+#include <valarray>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef double T;
+ T a1[] = {1.5, 2.5, -3, 4, -5.5};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ assert(v1.max() == 4.0);
+ }
+ {
+ typedef double T;
+ std::valarray<T> v1;
+ v1.max();
+ }
+ {
+ typedef double T;
+ T a1[] = {1.5, 2.5, -3, 4, -5.5};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ assert((2*v1).max() == 8.0);
+ }
+}
diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/min.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/min.pass.cpp
new file mode 100644
index 0000000000000..dac59343715ab
--- /dev/null
+++ b/test/std/numerics/numarray/template.valarray/valarray.members/min.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class valarray;
+
+// value_type min() const;
+
+#include <valarray>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef double T;
+ T a1[] = {1.5, 2.5, -3, 4, 5.5};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ assert(v1.min() == -3.0);
+ }
+ {
+ typedef double T;
+ std::valarray<T> v1;
+ v1.min();
+ }
+ {
+ typedef double T;
+ T a1[] = {1.5, 2.5, -3, 4, 5.5};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ assert((2*v1).min() == -6.0);
+ }
+}
diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/resize.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/resize.pass.cpp
new file mode 100644
index 0000000000000..176d958aab92f
--- /dev/null
+++ b/test/std/numerics/numarray/template.valarray/valarray.members/resize.pass.cpp
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class valarray;
+
+// void resize(size_t n, value_type x = value_type());
+
+#include <valarray>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ v1.resize(8);
+ assert(v1.size() == 8);
+ for (int i = 0; i < v1.size(); ++i)
+ assert(v1[i] == 0);
+ v1.resize(0);
+ assert(v1.size() == 0);
+ v1.resize(80);
+ assert(v1.size() == 80);
+ for (int i = 0; i < v1.size(); ++i)
+ assert(v1[i] == 0);
+ v1.resize(40);
+ assert(v1.size() == 40);
+ for (int i = 0; i < v1.size(); ++i)
+ assert(v1[i] == 0);
+ }
+}
diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/shift.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/shift.pass.cpp
new file mode 100644
index 0000000000000..9a617a91a4170
--- /dev/null
+++ b/test/std/numerics/numarray/template.valarray/valarray.members/shift.pass.cpp
@@ -0,0 +1,127 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class valarray;
+
+// valarray shift(int i) const;
+
+#include <valarray>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.shift(0);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 0};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.shift(1);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {10, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.shift(9);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.shift(90);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.shift(-1);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.shift(-9);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = v1.shift(-90);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ const unsigned N1 = 0;
+ std::valarray<T> v1;
+ std::valarray<T> v2 = v1.shift(-90);
+ assert(v2.size() == N1);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {8, 10, 12, 14, 16, 18, 20, 0, 0, 0};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = (v1 + v1).shift(3);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ T a2[] = {0, 0, 0, 2, 4, 6, 8, 10, 12, 14};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2 = (v1 + v1).shift(-3);
+ assert(v2.size() == N1);
+ for (unsigned i = 0; i < N1; ++i)
+ assert(v2[i] == a2[i]);
+ }
+}
diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/size.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/size.pass.cpp
new file mode 100644
index 0000000000000..0aae5b8de7fad
--- /dev/null
+++ b/test/std/numerics/numarray/template.valarray/valarray.members/size.pass.cpp
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class valarray;
+
+// size_t size() const;
+
+#include <valarray>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ assert(v1.size() == N1);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5};
+ const unsigned N1 = 0;
+ std::valarray<T> v1(a1, N1);
+ assert(v1.size() == N1);
+ }
+ {
+ typedef int T;
+ const unsigned N1 = 0;
+ std::valarray<T> v1;
+ assert(v1.size() == N1);
+ }
+}
diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/sum.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/sum.pass.cpp
new file mode 100644
index 0000000000000..189f03d25cf45
--- /dev/null
+++ b/test/std/numerics/numarray/template.valarray/valarray.members/sum.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class valarray;
+
+// value_type sum() const;
+
+#include <valarray>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef double T;
+ T a1[] = {1.5, 2.5, 3, 4, 5.5};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ std::valarray<T> v1(a1, N1);
+ assert(v1.sum() == 16.5);
+ }
+}
diff --git a/test/std/numerics/numarray/template.valarray/valarray.members/swap.pass.cpp b/test/std/numerics/numarray/template.valarray/valarray.members/swap.pass.cpp
new file mode 100644
index 0000000000000..a90a809363761
--- /dev/null
+++ b/test/std/numerics/numarray/template.valarray/valarray.members/swap.pass.cpp
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class valarray;
+
+// void swap(valarray& v);
+
+#include <valarray>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5};
+ T a2[] = {6, 7, 8, 9, 10, 11, 12};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ const unsigned N2 = sizeof(a2)/sizeof(a2[0]);
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2(a2, N2);
+ std::valarray<T> v1_save = v1;
+ std::valarray<T> v2_save = v2;
+ v1.swap(v2);
+ assert(v1.size() == v2_save.size());
+ for (int i = 0; i < v1.size(); ++i)
+ assert(v1[i] == v2_save[i]);
+ assert(v2.size() == v1_save.size());
+ for (int i = 0; i < v2.size(); ++i)
+ assert(v2[i] == v1_save[i]);
+ }
+ {
+ typedef int T;
+ T a1[] = {1, 2, 3, 4, 5};
+ const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
+ const unsigned N2 = 0;
+ std::valarray<T> v1(a1, N1);
+ std::valarray<T> v2;
+ std::valarray<T> v1_save = v1;
+ std::valarray<T> v2_save = v2;
+ v1.swap(v2);
+ assert(v1.size() == v2_save.size());
+ for (int i = 0; i < v1.size(); ++i)
+ assert(v1[i] == v2_save[i]);
+ assert(v2.size() == v1_save.size());
+ for (int i = 0; i < v2.size(); ++i)
+ assert(v2[i] == v1_save[i]);
+ }
+ {
+ typedef int T;
+ T a2[] = {6, 7, 8, 9, 10, 11, 12};
+ const unsigned N1 = 0;
+ const unsigned N2 = sizeof(a2)/sizeof(a2[0]);
+ std::valarray<T> v1;
+ std::valarray<T> v2(a2, N2);
+ std::valarray<T> v1_save = v1;
+ std::valarray<T> v2_save = v2;
+ v1.swap(v2);
+ assert(v1.size() == v2_save.size());
+ for (int i = 0; i < v1.size(); ++i)
+ assert(v1[i] == v2_save[i]);
+ assert(v2.size() == v1_save.size());
+ for (int i = 0; i < v2.size(); ++i)
+ assert(v2[i] == v1_save[i]);
+ }
+ {
+ typedef int T;
+ const unsigned N1 = 0;
+ const unsigned N2 = 0;
+ std::valarray<T> v1;
+ std::valarray<T> v2;
+ std::valarray<T> v1_save = v1;
+ std::valarray<T> v2_save = v2;
+ v1.swap(v2);
+ assert(v1.size() == v2_save.size());
+ for (int i = 0; i < v1.size(); ++i)
+ assert(v1[i] == v2_save[i]);
+ assert(v2.size() == v1_save.size());
+ for (int i = 0; i < v2.size(); ++i)
+ assert(v2[i] == v1_save[i]);
+ }
+}