1 // { dg-do run } 2 // 2003-02-03 Volker Reichelt <reichelt@igpm.rwth-aachen.de> 3 4 // Copyright (C) 2003-2021 Free Software Foundation, Inc. 5 // 6 // This file is part of the GNU ISO C++ Library. This library is free 7 // software; you can redistribute it and/or modify it under the 8 // terms of the GNU General Public License as published by the 9 // Free Software Foundation; either version 3, or (at your option) 10 // any later version. 11 12 // This library is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 17 // You should have received a copy of the GNU General Public License along 18 // with this library; see the file COPYING3. If not see 19 // <http://www.gnu.org/licenses/>. 20 21 #include <valarray> 22 #include <testsuite_hooks.h> 23 test01()24void test01() // check unary operators 25 { 26 std::valarray<int> u(1); 27 u[0]=1; 28 29 VERIFY( (+u)[0] == +1 ); 30 VERIFY( (-u)[0] == -1 ); 31 VERIFY( (!u)[0] == !1 ); 32 VERIFY( (~u)[0] == ~1 ); 33 } 34 test02()35void test02() // check binary operators 36 { 37 std::valarray<int> u(1), v(1); 38 u[0]=1; 39 v[0]=3; 40 41 VERIFY( (u+ v)[0] == (1+ 3) ); 42 VERIFY( (u- v)[0] == (1- 3) ); 43 VERIFY( (u* v)[0] == (1* 3) ); 44 VERIFY( (u/ v)[0] == (1/ 3) ); 45 VERIFY( (u% v)[0] == (1% 3) ); 46 VERIFY( (u^ v)[0] == (1^ 3) ); 47 VERIFY( (u& v)[0] == (1& 3) ); 48 VERIFY( (u| v)[0] == (1| 3) ); 49 VERIFY( (u<<v)[0] == (1<<3) ); 50 VERIFY( (u>>v)[0] == (1>>3) ); 51 VERIFY( (u&&v)[0] == (1&&3) ); 52 VERIFY( (u||v)[0] == (1||3) ); 53 VERIFY( (u==v)[0] == (1==3) ); 54 VERIFY( (u!=v)[0] == (1!=3) ); 55 VERIFY( (u< v)[0] == (1< 3) ); 56 VERIFY( (u> v)[0] == (1> 3) ); 57 VERIFY( (u<=v)[0] == (1<=3) ); 58 VERIFY( (u>=v)[0] == (1>=3) ); 59 } 60 test03()61void test03() // check binary operators with scalar operands 62 { 63 std::valarray<int> u(1); 64 u[0]=1; 65 long v = 3; // LWG 3074 allows scalar operand to be different to value_type. 66 67 VERIFY( (u+ v)[0] == (1+ 3) ); 68 VERIFY( (u- v)[0] == (1- 3) ); 69 VERIFY( (u* v)[0] == (1* 3) ); 70 VERIFY( (u/ v)[0] == (1/ 3) ); 71 VERIFY( (u% v)[0] == (1% 3) ); 72 VERIFY( (u^ v)[0] == (1^ 3) ); 73 VERIFY( (u& v)[0] == (1& 3) ); 74 VERIFY( (u| v)[0] == (1| 3) ); 75 VERIFY( (u<<v)[0] == (1<<3) ); 76 VERIFY( (u>>v)[0] == (1>>3) ); 77 VERIFY( (u&&v)[0] == (1&&3) ); 78 VERIFY( (u||v)[0] == (1||3) ); 79 VERIFY( (u==v)[0] == (1==3) ); 80 VERIFY( (u!=v)[0] == (1!=3) ); 81 VERIFY( (u< v)[0] == (1< 3) ); 82 VERIFY( (u> v)[0] == (1> 3) ); 83 VERIFY( (u<=v)[0] == (1<=3) ); 84 VERIFY( (u>=v)[0] == (1>=3) ); 85 86 VERIFY( (v+ u)[0] == (3+ 1) ); 87 VERIFY( (v- u)[0] == (3- 1) ); 88 VERIFY( (v* u)[0] == (3* 1) ); 89 VERIFY( (v/ u)[0] == (3/ 1) ); 90 VERIFY( (v% u)[0] == (3% 1) ); 91 VERIFY( (v^ u)[0] == (3^ 1) ); 92 VERIFY( (v& u)[0] == (3& 1) ); 93 VERIFY( (v| u)[0] == (3| 1) ); 94 VERIFY( (v<<u)[0] == (3<<1) ); 95 VERIFY( (v>>u)[0] == (3>>1) ); 96 VERIFY( (v&&u)[0] == (3&&1) ); 97 VERIFY( (v||u)[0] == (3||1) ); 98 VERIFY( (v==u)[0] == (3==1) ); 99 VERIFY( (v!=u)[0] == (3!=1) ); 100 VERIFY( (v< u)[0] == (3< 1) ); 101 VERIFY( (v> u)[0] == (3> 1) ); 102 VERIFY( (v<=u)[0] == (3<=1) ); 103 VERIFY( (v>=u)[0] == (3>=1) ); 104 } 105 main()106int main() 107 { 108 test01(); 109 test02(); 110 test03(); 111 } 112