Mercurial > hg > octave-terminal
changeset 10090:655ab6f6c369
add tests for built-in class overloads
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 13 Jan 2010 08:44:24 +0100 |
parents | dd70982c81a3 |
children | a115046d462d |
files | test/ChangeLog test/Makefile.am test/bc_overloads_expected test/build_bc_overload_tests.sh test/build_bc_overloads_expected.m |
diffstat | 5 files changed, 368 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,10 @@ +2010-01-13 Jaroslav Hajek <highegg@gmail.com> + + * build_bc_overload_tests.sh: New shell script. + * build_bc_overloads_expected.m: New source (not normally used). + * bc_overloads_expected: New text file. + * Makefile.am: Build test_bc_overloads.m. + 2009-12-25 John W. Eaton <jwe@octave.org> * fntests.m (hastests): Use regexp instead of findstr and only
--- a/test/Makefile.am +++ b/test/Makefile.am @@ -62,19 +62,26 @@ include @Snork/module.mk include @Spork/module.mk -check: test_sparse.m +check: test_sparse.m test_bc_overloads.m $(top_builddir)/run-octave --norc --silent --no-history $(srcdir)/fntests.m $(srcdir) test_sparse.m: build_sparse_tests.sh $(srcdir)/build_sparse_tests.sh +test_bc_overloads.m: build_bc_overload_tests.sh bc_overloads_expected + $(srcdir)/build_bc_overload_tests.sh + EXTRA_DIST = \ ChangeLog \ build_sparse_tests.sh \ + build_bc_overload_tests.sh \ + bc_overloads_expected \ + build_bc_overloads_expected.m \ $(FCN_FILES) CLEANFILES = \ - test_sparse.m + test_sparse.m \ + test_bc_overloads.m DISTCLEANFILES = \ fntests.log
new file mode 100644 --- /dev/null +++ b/test/bc_overloads_expected @@ -0,0 +1,225 @@ +double double double +double single single +double logical double +double char double +double int8 int8 +double int16 int16 +double int32 int32 +double int64 int64 +double uint8 uint8 +double uint16 uint16 +double uint32 uint32 +double uint64 uint64 +double cell cell +double struct struct +double function_handle function_handle +single double single +single single single +single logical single +single char single +single int8 int8 +single int16 int16 +single int32 int32 +single int64 int64 +single uint8 uint8 +single uint16 uint16 +single uint32 uint32 +single uint64 uint64 +single cell cell +single struct struct +single function_handle function_handle +logical double double +logical single single +logical logical logical +logical char char +logical int8 int8 +logical int16 int16 +logical int32 int32 +logical int64 int64 +logical uint8 uint8 +logical uint16 uint16 +logical uint32 uint32 +logical uint64 uint64 +logical cell cell +logical struct struct +logical function_handle function_handle +char double char +char single single +char logical char +char char char +char int8 int8 +char int16 int16 +char int32 int32 +char int64 int64 +char uint8 uint8 +char uint16 uint16 +char uint32 uint32 +char uint64 uint64 +char cell cell +char struct struct +char function_handle function_handle +int8 double int8 +int8 single int8 +int8 logical int8 +int8 char int8 +int8 int8 int8 +int8 int16 int8 +int8 int32 int8 +int8 int64 int8 +int8 uint8 int8 +int8 uint16 int8 +int8 uint32 int8 +int8 uint64 int8 +int8 cell cell +int8 struct struct +int8 function_handle function_handle +int16 double int16 +int16 single int16 +int16 logical int16 +int16 char int16 +int16 int8 int16 +int16 int16 int16 +int16 int32 int16 +int16 int64 int16 +int16 uint8 int16 +int16 uint16 int16 +int16 uint32 int16 +int16 uint64 int16 +int16 cell cell +int16 struct struct +int16 function_handle function_handle +int32 double int32 +int32 single int32 +int32 logical int32 +int32 char int32 +int32 int8 int32 +int32 int16 int32 +int32 int32 int32 +int32 int64 int32 +int32 uint8 int32 +int32 uint16 int32 +int32 uint32 int32 +int32 uint64 int32 +int32 cell cell +int32 struct struct +int32 function_handle function_handle +int64 double int64 +int64 single int64 +int64 logical int64 +int64 char int64 +int64 int8 int64 +int64 int16 int64 +int64 int32 int64 +int64 int64 int64 +int64 uint8 int64 +int64 uint16 int64 +int64 uint32 int64 +int64 uint64 int64 +int64 cell cell +int64 struct struct +int64 function_handle function_handle +uint8 double uint8 +uint8 single uint8 +uint8 logical uint8 +uint8 char uint8 +uint8 int8 uint8 +uint8 int16 uint8 +uint8 int32 uint8 +uint8 int64 uint8 +uint8 uint8 uint8 +uint8 uint16 uint8 +uint8 uint32 uint8 +uint8 uint64 uint8 +uint8 cell cell +uint8 struct struct +uint8 function_handle function_handle +uint16 double uint16 +uint16 single uint16 +uint16 logical uint16 +uint16 char uint16 +uint16 int8 uint16 +uint16 int16 uint16 +uint16 int32 uint16 +uint16 int64 uint16 +uint16 uint8 uint16 +uint16 uint16 uint16 +uint16 uint32 uint16 +uint16 uint64 uint16 +uint16 cell cell +uint16 struct struct +uint16 function_handle function_handle +uint32 double uint32 +uint32 single uint32 +uint32 logical uint32 +uint32 char uint32 +uint32 int8 uint32 +uint32 int16 uint32 +uint32 int32 uint32 +uint32 int64 uint32 +uint32 uint8 uint32 +uint32 uint16 uint32 +uint32 uint32 uint32 +uint32 uint64 uint32 +uint32 cell cell +uint32 struct struct +uint32 function_handle function_handle +uint64 double uint64 +uint64 single uint64 +uint64 logical uint64 +uint64 char uint64 +uint64 int8 uint64 +uint64 int16 uint64 +uint64 int32 uint64 +uint64 int64 uint64 +uint64 uint8 uint64 +uint64 uint16 uint64 +uint64 uint32 uint64 +uint64 uint64 uint64 +uint64 cell cell +uint64 struct struct +uint64 function_handle function_handle +cell double cell +cell single cell +cell logical cell +cell char cell +cell int8 cell +cell int16 cell +cell int32 cell +cell int64 cell +cell uint8 cell +cell uint16 cell +cell uint32 cell +cell uint64 cell +cell cell cell +cell struct cell +cell function_handle function_handle +struct double struct +struct single struct +struct logical struct +struct char struct +struct int8 struct +struct int16 struct +struct int32 struct +struct int64 struct +struct uint8 struct +struct uint16 struct +struct uint32 struct +struct uint64 struct +struct cell struct +struct struct struct +struct function_handle function_handle +function_handle double function_handle +function_handle single function_handle +function_handle logical function_handle +function_handle char function_handle +function_handle int8 function_handle +function_handle int16 function_handle +function_handle int32 function_handle +function_handle int64 function_handle +function_handle uint8 function_handle +function_handle uint16 function_handle +function_handle uint32 function_handle +function_handle uint64 function_handle +function_handle cell function_handle +function_handle struct function_handle +function_handle function_handle function_handle
new file mode 100755 --- /dev/null +++ b/test/build_bc_overload_tests.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +# Copyright (C) 2010 VZLU Prague +# +# This file is part of Octave. +# +# Octave 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 3 of the License, or (at +# your option) any later version. +# +# Octave 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 Octave; see the file COPYING. If not, see +# <http://www.gnu.org/licenses/>. + +CLASSES="double single char logical int8 int16 int32 int64 \ +uint8 uint16 uint32 uint64 struct cell function_handle" + +for class in $CLASSES ; do + DIR=\@$class + test -d $DIR || mkdir $DIR || { echo "error: could not create $DIR" ; exit ; } + cat > $DIR/tbcover.m <<end +% DO NOT EDIT - generated automatically +function s = tbcover (x, y) + s = '$class'; +end +done + +cat > tbcover.m <<end +% DO NOT EDIT - generated automatically +function s = tbcover (x, y) + s = 'none'; +end + +if test "$1" == "overloads_only" ; then + exit +fi + +cat > test_bc_overloads.m <<end +## THIS IS AN AUTOMATICALLY GENERATED FILE --- DO NOT EDIT --- +## instead modify build_bc_overload_tests.sh to generate the tests that you want. + +%!shared ex +%! ex.double = 1; +%! ex.single = single(1); +%! ex.logical = true; +%! ex.char = 'char'; +%! ex.int8 = int8 (1); +%! ex.int16 = int16 (1); +%! ex.int32 = int32 (1); +%! ex.int64 = int64 (1); +%! ex.uint8 = uint8 (1); +%! ex.uint16 = uint16 (1); +%! ex.uint32 = uint32 (1); +%! ex.uint64 = uint64 (1); +%! ex.cell = {}; +%! ex.struct = struct (); +%! ex.function_handle = @numel; + +end + +cat bc_overloads_expected |\ +while read cl1 cl2 clr ; do + cat >> test_bc_overloads.m <<end +%% Name call +%!assert (tbcover (ex.$cl1, ex.$cl2), "$clr") +%% Handle call +%!assert ((@tbcover) (ex.$cl1, ex.$cl2), "$clr") + +end +done + +cat >> test_bc_overloads.m <<end +%%test handles through cellfun +%!test +%! f = fieldnames (ex); +%! n = numel (f); +%! s = c1 = c2 = cell (n); +%! for i = 1:n +%! for j = 1:n +%! c1{i,j} = ex.(f{i}); +%! c2{i,j} = ex.(f{j}); +%! s{i,j} = tbcover (ex.(f{i}), ex.(f{j})); +%! endfor +%! endfor +%! assert (cellfun (@tbcover, c1, c2, "uniformoutput", false), s); +end
new file mode 100644 --- /dev/null +++ b/test/build_bc_overloads_expected.m @@ -0,0 +1,35 @@ +% this script is intended to be Matlab compatible +% first, run the script +% +% ./build_bc_overloads_tests.sh overloads_onely +% +% to generate the overloaded functions. +% +ex.double = 1; +ex.single = single(1); +ex.logical = true; +ex.char = 'char'; +ex.int8 = int8 (1); +ex.int16 = int16 (1); +ex.int32 = int32 (1); +ex.int64 = int64 (1); +ex.uint8 = uint8 (1); +ex.uint16 = uint16 (1); +ex.uint32 = uint32 (1); +ex.uint64 = uint64 (1); +ex.cell = {}; +ex.struct = struct (); +ex.function_handle = @numel; + +f = fieldnames (ex); +n = numel (f); + +fid = fopen ('bc_overloads_expected','w'); +fid +for i = 1:n + for j = 1:n + s = tbcover (ex.(f{i}), ex.(f{j})); + fprintf (fid, '%s %s %s\n', f{i}, f{j}, s); + end +end +fclose (fid)