summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2008-07-04 18:45:09 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2008-07-04 18:45:09 +0000
commitb1098305da0a595e8305986a5b215200793defe3 (patch)
tree74b77907d7a04f8f9b233b60185f3cf7457652ab /libstdc++-v3/testsuite
parent3725d22e61ec5c3cfce882149a2d842bf1dd5dc7 (diff)
downloadppe42-gcc-b1098305da0a595e8305986a5b215200793defe3.tar.gz
ppe42-gcc-b1098305da0a595e8305986a5b215200793defe3.zip
2008-07-04 Chris Fairles <chris.fairles@gmail.com>
* include/std/ratio: New, per N2661. * include/Makefile.am: Update. * include/Makefile.in: Regenerate. * testsuite/20_util/ratio/cons/cons1.cc: New. * testsuite/20_util/ratio/cons/cons_overflow.cc: Likewise. * testsuite/20_util/ratio/operations/ops1.cc: Likewise. * testsuite/20_util/ratio/operations/ops2.cc: Likewise. * testsuite/20_util/ratio/operations/ops3.cc: Likewise. * testsuite/20_util/ratio/operations/ops_overflow.cc: Likewise. * testsuite/20_util/ratio/comparisons/comp1.cc: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@137482 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/20_util/ratio/comparisons/comp1.cc87
-rw-r--r--libstdc++-v3/testsuite/20_util/ratio/cons/cons1.cc57
-rw-r--r--libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow.cc58
-rw-r--r--libstdc++-v3/testsuite/20_util/ratio/operations/ops1.cc80
-rw-r--r--libstdc++-v3/testsuite/20_util/ratio/operations/ops2.cc78
-rw-r--r--libstdc++-v3/testsuite/20_util/ratio/operations/ops3.cc77
-rw-r--r--libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow.cc51
7 files changed, 488 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp1.cc b/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp1.cc
new file mode 100644
index 00000000000..73064c70919
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/ratio/comparisons/comp1.cc
@@ -0,0 +1,87 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2008 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 2, 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 COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include <ratio>
+#include <testsuite_hooks.h>
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ VERIFY(( std::ratio_equal<std::ratio<2,6>, std::ratio<1,3>>::value == 1 ));
+ VERIFY(( std::ratio_equal<std::ratio<2,6>, std::ratio<1,4>>::value == 0 ));
+
+ VERIFY(( std::ratio_not_equal<std::ratio<2,6>,
+ std::ratio<1,3>>::value == 0 ));
+ VERIFY(( std::ratio_not_equal<std::ratio<2,6>,
+ std::ratio<1,4>>::value == 1 ));
+}
+
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ VERIFY(( std::ratio_less<std::ratio<1,4>, std::ratio<1,3>>::value == 1 ));
+ VERIFY(( std::ratio_less<std::ratio<-1,3>, std::ratio<1,3>>::value == 1 ));
+
+ VERIFY(( std::ratio_less<std::ratio<1,3>, std::ratio<1,4>>::value == 0 ));
+ VERIFY(( std::ratio_less<std::ratio<1,3>, std::ratio<-1,3>>::value == 0 ));
+
+ VERIFY(( std::ratio_less_equal<std::ratio<-1,3>,
+ std::ratio<-1,3>>::value == 1 ));
+ VERIFY(( std::ratio_less_equal<std::ratio<1,4>,
+ std::ratio<1,3>>::value == 1 ));
+
+ VERIFY(( std::ratio_less_equal<std::ratio<1,4>,
+ std::ratio<-1,3>>::value == 0 ));
+ VERIFY(( std::ratio_less_equal<std::ratio<1,3>,
+ std::ratio<-1,3>>::value == 0 ));
+
+ VERIFY(( std::ratio_greater<std::ratio<1,3>, std::ratio<1,4>>::value == 1 ));
+ VERIFY(( std::ratio_greater<std::ratio<1,3>, std::ratio<-1,3>>::value == 1 ));
+
+ VERIFY(( std::ratio_greater<std::ratio<1,4>, std::ratio<1,3>>::value == 0 ));
+ VERIFY(( std::ratio_greater<std::ratio<-1,3>, std::ratio<1,3>>::value == 0 ));
+
+ VERIFY(( std::ratio_greater_equal<std::ratio<1,3>,
+ std::ratio<1,3>>::value == 1 ));
+ VERIFY(( std::ratio_greater_equal<std::ratio<1,3>,
+ std::ratio<-1,3>>::value == 1 ));
+
+ VERIFY(( std::ratio_greater_equal<std::ratio<-1,3>,
+ std::ratio<1,3>>::value == 0 ));
+ VERIFY(( std::ratio_greater_equal<std::ratio<1,4>,
+ std::ratio<1,3>>::value == 0 ));
+}
+
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
+
+int main()
+{
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+ test01();
+ test02();
+#endif
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/ratio/cons/cons1.cc b/libstdc++-v3/testsuite/20_util/ratio/cons/cons1.cc
new file mode 100644
index 00000000000..dc2f0dabd70
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/ratio/cons/cons1.cc
@@ -0,0 +1,57 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2008-07-03 Chris Fairles <chris.fairles@gmail.com>
+
+// Copyright (C) 2008 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 2, 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 COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include <ratio>
+#include <testsuite_hooks.h>
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ratio<1,3> r0;
+ std::ratio<2,6> r1;
+ std::ratio<2,-6> r2;
+ std::ratio<-2,6> r3;
+
+ VERIFY( r0.num == 1 );
+ VERIFY( r0.den == 3 );
+
+ VERIFY( r1.num == r0.num );
+ VERIFY( r1.den == r0.den );
+ VERIFY( r2.num == -r0.num );
+ VERIFY( r2.den == r0.den );
+ VERIFY( r3.num == -r0.num );
+ VERIFY( r3.den == r0.den );
+}
+
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
+
+int main()
+{
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+ test01();
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow.cc b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow.cc
new file mode 100644
index 00000000000..26bbfcdec53
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow.cc
@@ -0,0 +1,58 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2008 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 2, 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 COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include <ratio>
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+
+void
+test01()
+{
+ std::ratio<INTMAX_MAX, INTMAX_MAX> r1;
+ std::ratio<-INTMAX_MAX, INTMAX_MAX> r2;
+}
+
+void
+test02()
+{
+ std::ratio<INTMAX_MIN, 1> r1;
+}
+
+void
+test03()
+{
+ std::ratio<1, INTMAX_MIN> r1;
+}
+
+void
+test04()
+{
+ std::ratio<1,0> r1;
+}
+
+// { dg-error "instantiated from here" "" { target *-*-* } 36 }
+// { dg-error "instantiated from here" "" { target *-*-* } 42 }
+// { dg-error "instantiated from here" "" { target *-*-* } 48 }
+// { dg-error "denominator cannot be zero" "" { target *-*-* } 136 }
+// { dg-error "out of range" "" { target *-*-* } 137 }
+// { dg-excess-errors "In instantiation of" }
+
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops1.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops1.cc
new file mode 100644
index 00000000000..3f6a91d2180
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops1.cc
@@ -0,0 +1,80 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2008-07-03 Chris Fairles <chris.fairles@gmail.com>
+
+// Copyright (C) 2008 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 2, 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 COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include <ratio>
+#include <testsuite_hooks.h>
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ratio_add<std::ratio<3,8>, std::ratio<5,12>>::type r;
+
+ VERIFY( r.num == 19);
+ VERIFY( r.den == 24);
+}
+
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+ std::ratio_subtract<std::ratio<3,8>, std::ratio<5,12>>::type r;
+
+ VERIFY( r.num == -1);
+ VERIFY( r.den == 24);
+}
+
+void
+test03()
+{
+ bool test __attribute__((unused)) = true;
+ std::ratio_multiply<std::ratio<3,8>, std::ratio<5,12>>::type r;
+
+ VERIFY( r.num == 5);
+ VERIFY( r.den == 32);
+}
+
+void
+test04()
+{
+ bool test __attribute__((unused)) = true;
+ std::ratio_divide<std::ratio<3,8>, std::ratio<5,12>>::type r;
+
+ VERIFY( r.num == 9);
+ VERIFY( r.den == 10);
+}
+
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
+
+int main()
+{
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+ test01();
+ test02();
+ test03();
+ test04();
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops2.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops2.cc
new file mode 100644
index 00000000000..2dc2be6b6d8
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops2.cc
@@ -0,0 +1,78 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2008-07-03 Chris Fairles <chris.fairles@gmail.com>
+
+// Copyright (C) 2008 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 2, 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 COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include <ratio>
+#include <testsuite_hooks.h>
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+
+typedef std::ratio<1, INTMAX_MAX> one_over_max;
+typedef std::ratio<2, INTMAX_MAX> two_over_max;
+typedef std::ratio<INTMAX_MAX, 1> max_over_one;
+typedef std::ratio<INTMAX_MAX, 2> max_over_two;
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ratio_add<one_over_max, one_over_max>::type r1;
+
+ VERIFY( r1.num == two_over_max::num);
+ VERIFY( r1.den == two_over_max::den);
+
+ std::ratio_add<
+ std::ratio<INTMAX_MAX / 2, INTMAX_MAX / 2>,
+ std::ratio<INTMAX_MAX / 2 , INTMAX_MAX / 2 + 1>>::type r2;
+
+ VERIFY( r2.num == INTMAX_MAX);
+ VERIFY( r2.den == (INTMAX_MAX / 2) + 1);
+}
+
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ratio_subtract<one_over_max, one_over_max>::type r1;
+
+ VERIFY( r1.num == 0);
+ VERIFY( r1.den == 1);
+
+ std::ratio_subtract<
+ std::ratio<INTMAX_MAX / 2, INTMAX_MAX / 2>,
+ std::ratio<INTMAX_MAX / 2 , INTMAX_MAX / 2 + 1>>::type r2;
+
+ VERIFY( r2.num == 1);
+ VERIFY( r2.den == (INTMAX_MAX / 2) + 1);
+}
+
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
+
+int main()
+{
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+ test01();
+ test02();
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops3.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops3.cc
new file mode 100644
index 00000000000..d66c37cf383
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops3.cc
@@ -0,0 +1,77 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2008-07-03 Chris Fairles <chris.fairles@gmail.com>
+
+// Copyright (C) 2008 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 2, 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 COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include <ratio>
+#include <testsuite_hooks.h>
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ratio_multiply<
+ std::ratio<2, INTMAX_MAX>,
+ std::ratio<INTMAX_MAX, 2>>::type r1;
+
+ VERIFY( r1.num == 1);
+ VERIFY( r1.den == 1);
+
+ std::ratio_multiply<
+ std::ratio<INTMAX_MAX, 2>,
+ std::ratio<2 , INTMAX_MAX - 1>>::type r2;
+
+ VERIFY( r2.num == INTMAX_MAX);
+ VERIFY( r2.den == INTMAX_MAX - 1);
+}
+
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ratio_divide<
+ std::ratio<INTMAX_MAX, 2>,
+ std::ratio<INTMAX_MAX, 2>>::type r1;
+
+ VERIFY( r1.num == 1);
+ VERIFY( r1.den == 1);
+
+ std::ratio_divide<
+ std::ratio<INTMAX_MAX-1, 2>,
+ std::ratio<INTMAX_MAX, 2>>::type r2;
+
+ VERIFY( r2.num == INTMAX_MAX - 1);
+ VERIFY( r2.den == INTMAX_MAX);
+}
+
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
+
+int main()
+{
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+ test01();
+ test02();
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow.cc b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow.cc
new file mode 100644
index 00000000000..7dffda39da2
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/ratio/operations/ops_overflow.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// 2008-07-03 Chris Fairles <chris.fairles@gmail.com>
+
+// Copyright (C) 2008 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 2, 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 COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+#include <ratio>
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+
+void
+test01()
+{
+ std::ratio_add<std::ratio<INTMAX_MAX, 1>, std::ratio<1>>::type r1;
+}
+
+void
+test02()
+{
+ std::ratio_multiply<std::ratio<-INTMAX_MAX, 2>, std::ratio<3, 2>>::type r1;
+ std::ratio_multiply<std::ratio<INTMAX_MAX>, std::ratio<INTMAX_MAX>>::type r2;
+}
+
+// { dg-error "instantiated from here" "" { target *-*-* } 31 }
+// { dg-error "instantiated from here" "" { target *-*-* } 37 }
+// { dg-error "instantiated from here" "" { target *-*-* } 38 }
+// { dg-error "overflow in addition" "" { target *-*-* } 127 }
+// { dg-error "overflow in multiplication" "" { target *-*-* } 95 }
+// { dg-error "overflow in multiplication" "" { target *-*-* } 97 }
+// { dg-error "overflow in multiplication" "" { target *-*-* } 99 }
+// { dg-excess-errors "In instantiation of" }
+// { dg-excess-errors "out of range" }
+
+#endif //_GLIBCXX_USE_C99_STDINT_TR1
OpenPOWER on IntegriCloud