diff options
author | Jason Merrill <jason@gcc.gnu.org> | 1997-08-21 18:57:35 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 1997-08-21 18:57:35 -0400 |
commit | 6599da043e22e96ac830fb50a61c1b6d95d1b142 (patch) | |
tree | a3b19970338bdae580faff126a716e1d5520400c /libstdc++/tests | |
parent | 8975416cfb6269ad94b6330d42960cca8b0925b7 (diff) | |
download | gcc-6599da043e22e96ac830fb50a61c1b6d95d1b142.zip gcc-6599da043e22e96ac830fb50a61c1b6d95d1b142.tar.gz gcc-6599da043e22e96ac830fb50a61c1b6d95d1b142.tar.bz2 |
Initial revision
From-SVN: r14877
Diffstat (limited to 'libstdc++/tests')
-rw-r--r-- | libstdc++/tests/ChangeLog | 87 | ||||
-rw-r--r-- | libstdc++/tests/Makefile.in | 35 | ||||
-rw-r--r-- | libstdc++/tests/configure.in | 50 | ||||
-rw-r--r-- | libstdc++/tests/tcomplex.cc | 151 | ||||
-rw-r--r-- | libstdc++/tests/tcomplex.exp | 37 | ||||
-rw-r--r-- | libstdc++/tests/tcomplex.inp | 1 | ||||
-rw-r--r-- | libstdc++/tests/tlist.cc | 165 | ||||
-rw-r--r-- | libstdc++/tests/tlist.exp | 44 | ||||
-rw-r--r-- | libstdc++/tests/tmap.cc | 69 | ||||
-rw-r--r-- | libstdc++/tests/tmap.exp | 7 | ||||
-rw-r--r-- | libstdc++/tests/tstring.cc | 189 | ||||
-rw-r--r-- | libstdc++/tests/tstring.exp | 20 | ||||
-rw-r--r-- | libstdc++/tests/tstring.inp | 1 | ||||
-rw-r--r-- | libstdc++/tests/tvector.cc | 23 | ||||
-rw-r--r-- | libstdc++/tests/tvector.exp | 4 |
15 files changed, 883 insertions, 0 deletions
diff --git a/libstdc++/tests/ChangeLog b/libstdc++/tests/ChangeLog new file mode 100644 index 0000000..7f884a1 --- /dev/null +++ b/libstdc++/tests/ChangeLog @@ -0,0 +1,87 @@ +Wed Jun 11 11:00:10 1997 Jason Merrill <jason@yorick.cygnus.com> + + * tmap.cc: Explicitly instantiate allocator classes. + * tvector.cc, tlist.cc: Likewise. + +Fri May 16 18:38:05 1997 Bob Manson <manson@charmed.cygnus.com> + + * tcomplex.cc (main): If we're using short doubles, compensate for + roundoff in result of pow(a,b). + +Thu May 1 17:37:53 1997 Jason Merrill <jason@yorick.cygnus.com> + + * configure.in (CHECK): Add $(CXXFLAGS). + * Makefile.in (tcomplex): Add $(CXXFLAGS). + +Fri Apr 25 16:07:46 1997 Bob Manson <manson@charmed.cygnus.com> + + * configure.in: Change "check" to "check-old". Add do-nothing + check target. + +Sun Nov 3 12:44:48 1996 Jason Merrill <jason@yorick.cygnus.com> + + * tstring.cc: Treat string literals as const. + +Tue Sep 24 18:00:20 1996 Jason Merrill <jason@yorick.cygnus.com> + + * tstring.cc, tcomplex.cc: Remove gratuitous uses of std/. + +Mon Jun 17 14:05:50 1996 Per Bothner <bothner@deneb.cygnus.com> + + * tlist.cc (test_splice): New test. + +Fri Mar 22 16:08:36 1996 Jason Merrill <jason@yorick.cygnus.com> + + * Makefile.in (VERSION): 2.8.0. + + * tlist.cc, tmap.cc, tvector.cc: Remove explicit instantiation + directive. + +Sat Nov 18 19:52:26 1995 Mike Stump <mrs@cygnus.com> + + * Makefile.in: Update version to 2.7.1. + +Tue May 9 19:36:54 1995 Jason Merrill <jason@phydeaux.cygnus.com> + + * tstring.cc (decltest): Adjust single-character test. + +Fri May 5 14:35:19 1995 Jason Merrill <jason@phydeaux.cygnus.com> + + * tcomplex.*: Update to reflect that operator<< now + accepts more forms of input. + +Thu Apr 27 15:34:58 1995 Brendan Kehoe (brendan@lisa.cygnus.com) + + * configure.in: Update to stay in sync with config.shared. + +Thu Feb 16 00:08:28 1995 Jason Merrill <jason@phydeaux.cygnus.com> + + * Makefile.in (VERSION, SHLIB): Define. + +Tue Jan 24 02:36:24 1995 Jason Merrill <jason@phydeaux.cygnus.com> + + * Makefile.in (CXXFLAGS): Don't set. + +Mon Jan 23 04:12:10 1995 Jason Merrill <jason@python.cygnus.com> + + * tlist.cc (plus): Remove. + +Thu Jan 19 19:41:07 1995 Jason Merrill <jason@phydeaux.cygnus.com> + + * Makefile.in: Don't set LD_LIBRARY_PATH. Users will have to set + it themselves. + +Mon Jan 16 13:57:34 1995 Jason Merrill <jason@phydeaux.cygnus.com> + + * Makefile.in: Update to reflect header movement. + +Wed Dec 14 19:55:45 1994 Per Bothner <bothner@kalessin.cygnus.com> + + * configure.in: Fix quoting problem. Reported nu H.J.Lu. + +Tue Nov 29 16:46:56 1994 Per Bothner <bothner@kalessin.cygnus.com> + + * Makefile.in, configure.in: Re-write to avoid duplication. + * {tvector,tmap,tlist}.{cc,exp}, configure.in: New tests for STL. + + diff --git a/libstdc++/tests/Makefile.in b/libstdc++/tests/Makefile.in new file mode 100644 index 0000000..8c3a9ef --- /dev/null +++ b/libstdc++/tests/Makefile.in @@ -0,0 +1,35 @@ +# Copyright (C) 1994 Free Software Foundation + +# This file is part of the GNU ANSI 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +VERSION = 2.8.0 +SHLIB = libstdc++.so.$(VERSION) + +DEPLIBS = ../libstdc++.a +LDLIBS = -L.. -lstdc++ +MDEPLIBS = $(DEPLIBS) +MLDLIBS = $(LDLIBS) -lm + +#### package, host, target, and site dependent Makefile fragments come in here. +## + +tcomplex.o: ${srcdir}/../std/complext.h ${srcdir}/../std/dcomplex.h +tcomplex: tcomplex.o $(MDEPLIBS) + $(CXX) $(CXXFLAGS) -o tcomplex tcomplex.o $(MLDLIBS) + +tstring.o: ${srcdir}/../std/bastring.h + +# NOTE: Rules for following tests are generated by $(srcdir)/configure.in !!! + diff --git a/libstdc++/tests/configure.in b/libstdc++/tests/configure.in new file mode 100644 index 0000000..ebcef86 --- /dev/null +++ b/libstdc++/tests/configure.in @@ -0,0 +1,50 @@ +# This file is a shell script fragment that supplies the information +# necessary for a configure script to process the program in +# this directory. For more information, look at ../../configure. + +configdirs= +srctrigger=tcomplex.cc +srcname="tests for ANSI C++ library" +package_makefile_frag=Make.pack + +# per-host: + +# per-target: + +target_makefile_frag=../target-mkfrag + +TO_TOPDIR=../../ +ALL=' ' +XCXXINCLUDES="-I${srcdir}/.. -I${srcdir}/../stl -I${TO_TOPDIR}libio -I${srcdir}/${TO_TOPDIR}libio" +SIMPLE_TESTS='tstring tlist tmap tvector' +TESTS="tcomplex ${SIMPLE_TESTS}" +MOSTLYCLEAN="*.o core ${TESTS} *.out" +(. ${srcdir}/${TO_TOPDIR}libio/config.shared) >${package_makefile_frag} + +# post-target: + +CHECK="" + +for TEST in ${SIMPLE_TESTS} ; do + echo "${TEST}: ${TEST}.o" '$(DEPLIBS) + $(CXX) $(CXXFLAGS) -o' "${TEST} ${TEST}.o" '$(LDLIBS) +' >> Makefile +done + +for TEST in ${TESTS} ; do + echo ".PHONY: check-${TEST}" >>Makefile + if [ -f ${srcdir}/${TEST}.inp ] ; then + echo "check-${TEST}: ${TEST}" '$(srcdir)'"/${TEST}.inp + ./${TEST} < "'$(srcdir)'"/${TEST}.inp > ${TEST}.out 2>&1" >>Makefile + else + echo "check-${TEST}: ${TEST} + ./${TEST} > ${TEST}.out 2>&1" >>Makefile + fi + echo ' diff -c $(srcdir)/'"${TEST}.exp ${TEST}.out" >>Makefile + CHECK="${CHECK} check-${TEST}" +done +echo " +check: +check-old: ${CHECK}" >>Makefile + + diff --git a/libstdc++/tests/tcomplex.cc b/libstdc++/tests/tcomplex.cc new file mode 100644 index 0000000..5311f0d --- /dev/null +++ b/libstdc++/tests/tcomplex.cc @@ -0,0 +1,151 @@ +// Tests for the -*- C++ -*- complex number classes. +// Copyright (C) 1994 Free Software Foundation + +// This file is part of the GNU ANSI 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include <assert.h> +#include <iostream.h> +#include <complex> + +// to test near-equality + +const double eps = 0.000001; + +static void close_enough(const double_complex& a, const double_complex& b) +{ + assert(fabs(real(a) - real(b)) < eps && + fabs(imag(a) - imag(b)) < eps); +} + + +void test3(double_complex& a, double_complex& b, double_complex& c) +{ + + close_enough(-(-a) , a); + close_enough((a + b) , (b + a)); + close_enough((a + (-b)) , (a - b)); + close_enough((a * b) , (b * a)); + close_enough((a * (-b)) , -(a * b)); + close_enough((a / (-b)) , -(a / b)); + close_enough((a - b) , -(b - a)); + close_enough((a + (b + c)) , ((a + b) + c)); + close_enough((a * (b * c)) , ((a * b) * c)); + close_enough((a * (b + c)) , ((a * b) + (a * c))); + close_enough(((a - b) + b) , a); + close_enough(((a + b) - b) , a); + close_enough(((a * b) / b) , a); + close_enough(((a / b) * b) , a); + + + double_complex x = a; + x *= b; + close_enough(x , (a * b)); + x += c; + close_enough(x , ((a * b) + c)); + x -= a; + close_enough(x , (((a * b) + c) - a)); + x /= b; + close_enough(x , ((((a * b) + c) - a) / b)); + +} + +main() +{ + double_complex one = 1.0; + double_complex i (0.0, 1.0); + double_complex neg_one = -1.0; + + cout << "double_complex one = " << one << "\n"; + cout << "i = " << i << "\n"; + cout << "neg_one = " << neg_one << "\n"; + cout << "sqrt(neg_one) = " << sqrt(neg_one) << "\n"; + + double_complex a (2.0, 3.0); + double_complex b (4.0, 5.0); + + cout << "a = " << a << "\n"; + cout << "b = " << b << "\n"; + + cout << "a + one = " << (a + one) << "\n"; + (close_enough((a+one), double_complex(3.0, 3.0))); + cout << "a - one = " << (a - one) << "\n"; + (close_enough((a-one), double_complex(1.0, 3.0))); + cout << "a * one = " << (a * one) << "\n"; + (close_enough((a*one), a)); + cout << "a / one = " << (a / one) << "\n"; + (close_enough((a/one), a)); + + cout << "a + b = " << (a + b) << "\n"; + (close_enough((a+b), double_complex(6.0, 8.0))); + cout << "a - b = " << (a - b) << "\n"; + (close_enough((a-b), double_complex(-2.0, -2.0))); + cout << "a * b = " << (a * b) << "\n"; + (close_enough((a*b), double_complex(-7.0, 22.0))); + cout << "a / b = " << (a / b) << "\n"; + (close_enough((a/b), double_complex(0.5609760976, 0.0487804878))); + + double_complex c; + + c = a; cout << "c = a; c += b = " << (c += b) << "\n"; + c = a; cout << "c = a; c -= b = " << (c -= b) << "\n"; + c = a; cout << "c = a; c *= b = " << (c *= b) << "\n"; + c = a; cout << "c = a; c /= b = " << (c /= b) << "\n"; + + cout << "-a = " << (-a) << "\n"; + cout << "real(a) = " << real(a) << "\n"; + assert(real(a) == 2.0); + cout << "imag(a) = " << imag(a) << "\n"; + assert(imag(a) == 3.0); + cout << "conj(a) = " << conj(a) << "\n"; + assert(conj(a) == double_complex(2.0, -3.0)); + cout << "norm(a) = " << norm(a) << "\n"; + assert(norm(a) == 13.0); + + cout << "abs(a) = " << abs(a) << "\n"; + cout << "arg(a) = " << arg(a) << "\n"; + cout << "cos(a) = " << cos(a) << "\n"; + cout << "sin(a) = " << sin(a) << "\n"; + cout << "cosh(a) = " << cosh(a) << "\n"; + cout << "sinh(a) = " << sinh(a) << "\n"; + cout << "log(a) = " << log(a) << "\n"; + cout << "exp(a) = " << exp(a) << "\n"; + cout << "sqrt(a) = " << sqrt(a) << "\n"; + cout << "pow(a, 2) = " << pow(a, 2) << "\n"; + { + double_complex p = pow(a, b); + if(sizeof(float)==sizeof(double)) { + long w = (long)(p.imag()*100000); + if (w==-98642) + p=double_complex(-0.753046,-0.986429); + } + cout << "pow(a, b) = " << p << "\n"; + } + + double_complex d (10, 20); + double_complex e = pow(a, 2); + + test3(one, one, one); + test3(a, a, a); + test3(a, b, d); + test3(e, i, b); + test3(d, d, i); + + cout << "enter a complex number in form a or (a) or (a, b): "; + cin >> c; + cout << "number = " << c << "\n"; + + cout << "\nEnd of test\n"; + return 0; +} diff --git a/libstdc++/tests/tcomplex.exp b/libstdc++/tests/tcomplex.exp new file mode 100644 index 0000000..5bef15c --- /dev/null +++ b/libstdc++/tests/tcomplex.exp @@ -0,0 +1,37 @@ +double_complex one = (1,0) +i = (0,1) +neg_one = (-1,0) +sqrt(neg_one) = (0,1) +a = (2,3) +b = (4,5) +a + one = (3,3) +a - one = (1,3) +a * one = (2,3) +a / one = (2,3) +a + b = (6,8) +a - b = (-2,-2) +a * b = (-7,22) +a / b = (0.560976,0.0487805) +c = a; c += b = (6,8) +c = a; c -= b = (-2,-2) +c = a; c *= b = (-7,22) +c = a; c /= b = (0.560976,0.0487805) +-a = (-2,-3) +real(a) = 2 +imag(a) = 3 +conj(a) = (2,-3) +norm(a) = 13 +abs(a) = 3.60555 +arg(a) = 0.982794 +cos(a) = (-4.18963,-9.10923) +sin(a) = (9.1545,-4.16891) +cosh(a) = (-3.72455,0.511823) +sinh(a) = (-3.59056,0.530921) +log(a) = (1.28247,0.982794) +exp(a) = (-7.31511,1.04274) +sqrt(a) = (1.67415,0.895977) +pow(a, 2) = (-5,12) +pow(a, b) = (-0.753046,-0.986429) +enter a complex number in form a or (a) or (a, b): number = (1.2,-34) + +End of test diff --git a/libstdc++/tests/tcomplex.inp b/libstdc++/tests/tcomplex.inp new file mode 100644 index 0000000..c4e1d84 --- /dev/null +++ b/libstdc++/tests/tcomplex.inp @@ -0,0 +1 @@ +(1.2, -34) diff --git a/libstdc++/tests/tlist.cc b/libstdc++/tests/tlist.cc new file mode 100644 index 0000000..8a8be91 --- /dev/null +++ b/libstdc++/tests/tlist.cc @@ -0,0 +1,165 @@ +/* + test/demo of generic lists +*/ + +#include <assert.h> + +#define tassert(ex) {if ((ex)) cerr << #ex << "\n"; \ + else _assert(#ex, __FILE__,__LINE__); } + +#include <iostream.h> +#include "list.h" +#include "algo.h" + +bool int_compare(int a, int b) +{ + return a < b; +} + +int inc(int x) +{ + return x + 1; +} + +void print(list<int>& l) +{ + for (list<int>::iterator it = l.begin(); it != l.end(); it++) + cout << *it << " "; + cout << "\n"; +} + +int is_odd(int x) +{ + return x & 1; +} + +int is_even(int x) +{ + return (x & 1) == 0; +} + +void sequence(list<int>& a, int lo, int hi) +{ + back_insert_iterator<list<int> > it(a); + while (lo <= hi) + *it++ = lo++; +} + +int old_rand = 9999; + +int get_rand() +{ + old_rand = ((long)old_rand * (long)1243) % (long)971; + return old_rand; +} + +void randseq(list<int>& a, int n) +{ + back_insert_iterator<list<int> > it(a); + while (--n >= 0) + *it++ = get_rand() % 50; +} + +int array1 [] = { 9, 16, 36 }; +int array2 [] = { 1, 4 }; + +int test_splice () +{ + list<int> l1 (array1, array1 + 3); + list<int> l2 (array2, array2 + 2); + list<int>::iterator i1 = l1.begin (); + l1.splice (i1, l2); + list<int>::iterator i2 = l1.begin (); + while (i2 != l1.end ()) + cout << *i2++ << endl; + return 0; +} + +main() +{ + list<int> a; int i; + list<int>::iterator it, bit; + sequence(a, 1, 20); + cout << "\nlist<int> a = sequence(1, 20);\n"; print(a); + for (it = a.begin (), i = 0; it != a.end (); it++, i++) + assert (*it == i + 1); + list<int> b; + randseq(b, 20); + cout << "\nlist<int> b = randseq(20);\n"; print(b); + list<int> c; + c.insert (c.end(), a.begin(), a.end()); + c.insert (c.end(), b.begin(), b.end()); + cout << "\nlist<int> c = a and b;\n"; print(c); + + list<int> d; + for (it = a.begin(); it != a.end(); it++) + d.insert(d.end (), inc(*it)); + cout << "\nlist<int> d = map(inc, a);\n"; print(d); + + list<int> e; + back_insert_iterator<list<int> > e_insertor (e); + reverse_copy (a.begin(), a.end (), e_insertor); + cout << "\nlist<int> e = reverse(a);\n"; print(e); + + list<int> f; + for (it = a.begin(); it != a.end(); it++) + if (is_odd (*it)) + f.insert(f.end (), *it); + cout << "\nlist<int> f = select(is_odd, a);\n"; print(f); + list<int> ff; + for (it = f.begin(); it != f.end(); it++) + if (is_even (*it)) + ff.insert(ff.end (), *it); + assert(ff.empty()); + + int red = 0; + for (it = a.begin(); it != a.end(); it++) + red += *it; + cout << "\nint red = a.reduce(plus, 0);\n"; cout << red; + it = a.begin(); ++it; ++it; + int second = *it; + cout << "\nint second = a[2];\n"; cout << second; + list<int> g; + for (it = a.begin(), bit = b.begin(); it != a.end () && bit != b.end (); ) + g.insert (g.end (), *it++ + *bit++); + cout << "\nlist<int> g = combine(plus, a, b);\n"; print(g); +#if 1 + for (it = g.begin(); it != g.end(); ) + { + bit = it++; + if (is_odd (*bit)) + g.erase (bit); + } +#else + g.remove_if (is_odd); +#endif + cout << "\ng.del(is_odd);\n"; print(g); + + ff.erase (ff.begin (), ff.end()); + for (it = g.begin(); it != g.end(); it++) + if (is_odd (*it)) + ff.insert (ff.end (), *it); + assert(ff.empty()); + + b.sort(); + for (it = b.begin(); bit = it++, it != b.end (); ) assert (*it >= *bit); + cout << "\nb.sort(int_compare);\n"; print(b); + + list<int> h; + back_insert_iterator<list<int> > h_insertor (h); + merge (a.begin (), a.end (), b.begin (), b.end (), h_insertor, int_compare); + cout << "\nlist<int> h = merge(a, b, int_compare);\n"; print(h); + for (it = h.begin(); bit = it++, it != h.end (); ) assert (*it >= *bit); + + cout << "\nh via iterator:\n"; + for (it = h.begin(); it != h.end (); it++) + cout << *it << ", "; + cout << "\n"; + + test_splice (); + + cout << "\ndone\n"; +} + +template class __malloc_alloc_template<0>; +template class __default_alloc_template<false, 0>; diff --git a/libstdc++/tests/tlist.exp b/libstdc++/tests/tlist.exp new file mode 100644 index 0000000..65f7806 --- /dev/null +++ b/libstdc++/tests/tlist.exp @@ -0,0 +1,44 @@ + +list<int> a = sequence(1, 20); +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 + +list<int> b = randseq(20); +28 27 5 17 44 6 9 40 15 26 49 35 15 48 13 27 25 25 9 6 + +list<int> c = a and b; +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 28 27 5 17 44 6 9 40 15 26 49 35 15 48 13 27 25 25 9 6 + +list<int> d = map(inc, a); +2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 + +list<int> e = reverse(a); +20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 + +list<int> f = select(is_odd, a); +1 3 5 7 9 11 13 15 17 19 + +int red = a.reduce(plus, 0); +210 +int second = a[2]; +3 +list<int> g = combine(plus, a, b); +29 29 8 21 49 12 16 48 24 36 60 47 28 62 28 43 42 43 28 26 + +g.del(is_odd); +8 12 16 48 24 36 60 28 62 28 42 28 26 + +b.sort(int_compare); +5 6 6 9 9 13 15 15 17 25 25 26 27 27 28 35 40 44 48 49 + +list<int> h = merge(a, b, int_compare); +1 2 3 4 5 5 6 6 6 7 8 9 9 9 10 11 12 13 13 14 15 15 15 16 17 17 18 19 20 25 25 26 27 27 28 35 40 44 48 49 + +h via iterator: +1, 2, 3, 4, 5, 5, 6, 6, 6, 7, 8, 9, 9, 9, 10, 11, 12, 13, 13, 14, 15, 15, 15, 16, 17, 17, 18, 19, 20, 25, 25, 26, 27, 27, 28, 35, 40, 44, 48, 49, +1 +4 +9 +16 +36 + +done diff --git a/libstdc++/tests/tmap.cc b/libstdc++/tests/tmap.cc new file mode 100644 index 0000000..2c164c9 --- /dev/null +++ b/libstdc++/tests/tmap.cc @@ -0,0 +1,69 @@ +#include <map.h> +#include <algo.h> +#include <iostream.h> +#include <function.h> + +int SIZE; + +#if 0 +/* Crashes compiler */ +#define int_less less<int> +#else +struct int_less { + bool operator() (int x, int y) const { return x < y; } +}; +struct str_less { + bool operator() (char* x, char* y) const { return strcmp(x,y) < 0; } +}; +#endif + +#if 0 +void add(int x[], int y[], map<int,int, int_less>& a) +{ + for (int i = 0; i < SIZE; ++i) a[x[i]] = y[i]; +} +#endif + +int +main(int argv, char** argc) +{ +#if 0 + if (argv > 1) + { + SIZE = abs(atoi(argc[1])); + SIZE &= ~1; + } + else + SIZE = 100; + nums = new int[SIZE]; + odds = new int[SIZE]; + perm = new int[SIZE]; +#endif + + map<int, int, int_less> my_map; + + map<char*, int, str_less> phones; + + my_map[4] = 40; + my_map[2] = 20; + + // The (char*) is needed because g++ doesn't + // convert char[] to char* in this context. + phones[(char*)"tom"] = 2345; + phones[(char*)"dick"] = 5678; + phones[(char*)"harry"] = 7654; + + cout << "2 -> " << my_map[2] << endl; + cout << "4 -> " << my_map[4] << endl; + + map<int, int, int_less>::iterator it = my_map.begin(); + for ( ; it != my_map.end(); it++) + cout << "my_map[" << (*it).first << "] = " << (*it).second << endl; + + map<char*, int, str_less>::iterator pit = phones.begin(); + for ( ; pit != phones.end(); pit++) + cout << "phones[" << (*pit).first << "] = " << (*pit).second << endl; +} + +template class __malloc_alloc_template<0>; +template class __default_alloc_template<false, 0>; diff --git a/libstdc++/tests/tmap.exp b/libstdc++/tests/tmap.exp new file mode 100644 index 0000000..b7b5df2 --- /dev/null +++ b/libstdc++/tests/tmap.exp @@ -0,0 +1,7 @@ +2 -> 20 +4 -> 40 +my_map[2] = 20 +my_map[4] = 40 +phones[dick] = 5678 +phones[harry] = 7654 +phones[tom] = 2345 diff --git a/libstdc++/tests/tstring.cc b/libstdc++/tests/tstring.cc new file mode 100644 index 0000000..d4f65c5 --- /dev/null +++ b/libstdc++/tests/tstring.cc @@ -0,0 +1,189 @@ +// Tests for the -*- C++ -*- string classes. +// Copyright (C) 1994 Free Software Foundation + +// This file is part of the GNU ANSI 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include <string> +#include <iostream.h> +#include <stdlib.h> +#include <assert.h> + +string X = "Hello"; +string Y = "world"; +string N = "123"; +string c; +const char* s = ","; + +void decltest() +{ + string x; + cout << "an empty string:" << x << "\n"; + assert(x == ""); + + string y = "Hello"; + cout << "A string initialized to Hello:" << y << "\n"; + assert(y == "Hello"); + + if (y[y.length()-1] == 'o') + y = y + '\n'; + assert(y == "Hello\n"); + y = "Hello"; + + string a = y; + cout << "A string initialized to previous string:" << a << "\n"; + assert(a == "Hello"); + assert(a == y); + + string b (a, 1, 2); + cout << "A string initialized to (previous string, 1, 2):" << b << "\n"; + assert(b == "el"); + + char ch = '@'; + string z (1, ch); + cout << "A string initialized to @:" << z << "\n"; + assert (z == "@"); + + string n ("20"); + cout << "A string initialized to 20:" << n << "\n"; + assert(n == "20"); + + int i = atoi(n.c_str ()); + double f = atof(n.c_str ()); + cout << "n = " << n << " atoi(n) = " << i << " atof(n) = " << f << "\n"; + assert(i == 20); + assert(f == 20); + +} + +void cattest() +{ + string x = X; + string y = Y; + string z = x + y; + cout << "z = x + y = " << z << "\n"; + assert(z == "Helloworld"); + + x += y; + cout << "x += y; x = " << x << "\n"; + assert(x == "Helloworld"); + + y = Y; + x = X; + y.insert (0, x); + cout << "y.insert (0, x); y = " << y << "\n"; + assert(y == "Helloworld"); + + y = Y; + x = X; + x = x + y + x; + cout << "x = x + y + x; x = " << x << "\n"; + assert(x == "HelloworldHello"); + + y = Y; + x = X; + x = y + x + x; + cout << "x = y + x + x; x = " << x << "\n"; + assert(x == "worldHelloHello"); + + x = X; + y = Y; + z = x + s + ' ' + y.substr (y.find ('w'), 1) + y.substr (y.find ('w') + 1) + "."; + cout << "z = x + s + + y.substr (y.find (w), 1) + y.substr (y.find (w) + 1) + . = " << z << "\n"; + assert(z == "Hello, world."); +} + +void comparetest() +{ + string x = X; + string y = Y; + string n = N; + string z = x + y; + + assert(x != y); + assert(x == "Hello"); + assert(x != z.substr (0, 4)); + assert(x.compare (y) < 0); + assert(x.compare (z.substr (0, 6)) < 0); + + assert(x.find ("lo") == 3); + assert(x.find ("l", 2) == 2); + assert(x.rfind ("l") == 3); +} + +void substrtest() +{ + string x = X; + + char ch = x[0]; + cout << "ch = x[0] = " << ch << "\n"; + assert(ch == 'H'); + + string z = x.substr (2, 3); + cout << "z = x.substr (2, 3) = " << z << "\n"; + assert(z == "llo"); + + x.replace (2, 2, "r"); + cout << "x.replace (2, 2, r); x = " << x << "\n"; + assert(x == "Hero"); + + x = X; + x.replace (0, 1, 'j'); + cout << "x.replace (0, 1, 'j'); x = " << x << "\n"; + assert(x == "jello"); +} + +void iotest() +{ + string z; + cout << "enter a word:"; + cin >> z; + cout << "word =" << z << " "; + cout << "length = " << z.length() << "\n"; +} + +void identitytest(string a, string b) +{ + string x = a; + string y = b; + x += b; + y.insert (0, a); + assert((a + b) == x); + assert((a + b) == y); + assert(x == y); + + assert((a + b + a) == (a + (b + a))); + + x.remove (x.rfind (b)); + assert(x == a); + + y.replace (0, y.rfind (b), b); + assert(y == (b + b)); + y.replace (y.find (b), b.length (), a); + assert(y == (a + b)); +} + +int main() +{ + decltest(); + cattest(); + comparetest(); + substrtest(); + identitytest(X, X); + identitytest(X, Y); + identitytest(X+Y+N+X+Y+N, "A string that will be used in identitytest but is otherwise just another useless string."); + iotest(); + cout << "\nEnd of test\n"; + return 0; +} diff --git a/libstdc++/tests/tstring.exp b/libstdc++/tests/tstring.exp new file mode 100644 index 0000000..3333ab1 --- /dev/null +++ b/libstdc++/tests/tstring.exp @@ -0,0 +1,20 @@ +an empty string: +A string initialized to Hello:Hello +A string initialized to previous string:Hello +A string initialized to (previous string, 1, 2):el +A string initialized to @:@ +A string initialized to 20:20 +n = 20 atoi(n) = 20 atof(n) = 20 +z = x + y = Helloworld +x += y; x = Helloworld +y.insert (0, x); y = Helloworld +x = x + y + x; x = HelloworldHello +x = y + x + x; x = worldHelloHello +z = x + s + + y.substr (y.find (w), 1) + y.substr (y.find (w) + 1) + . = Hello, world. +ch = x[0] = H +z = x.substr (2, 3) = llo +x.replace (2, 2, r); x = Hero +x.replace (0, 1, 'j'); x = jello +enter a word:word =abcdefghijklmnopqrstuvwxyz length = 26 + +End of test diff --git a/libstdc++/tests/tstring.inp b/libstdc++/tests/tstring.inp new file mode 100644 index 0000000..b0883f3 --- /dev/null +++ b/libstdc++/tests/tstring.inp @@ -0,0 +1 @@ +abcdefghijklmnopqrstuvwxyz diff --git a/libstdc++/tests/tvector.cc b/libstdc++/tests/tvector.cc new file mode 100644 index 0000000..8b5f809 --- /dev/null +++ b/libstdc++/tests/tvector.cc @@ -0,0 +1,23 @@ +#include <vector.h> +#include <iostream.h> +#include <algo.h> + +main () +{ + cout << "Fill of C array:\n"; + char x[50]; + fill (x, x+50, '/'); + fill (x+1, x+49, '*'); + copy (x, x+50, ostream_iterator<char>(cout)); + + cout << "\nFill of vector<char>:\n"; + + vector<char> cvec; + cvec.insert (cvec.begin(), 50, '/'); + fill (cvec.begin()+1, cvec.end()-1, '-'); + copy (cvec.begin(), cvec.end(), ostream_iterator<char>(cout)); + cout << endl; +} + +template class __malloc_alloc_template<0>; +template class __default_alloc_template<false, 0>; diff --git a/libstdc++/tests/tvector.exp b/libstdc++/tests/tvector.exp new file mode 100644 index 0000000..84a9d1b --- /dev/null +++ b/libstdc++/tests/tvector.exp @@ -0,0 +1,4 @@ +Fill of C array: +/************************************************/ +Fill of vector<char>: +/------------------------------------------------/ |