comparison test/build_bc_overload_tests.sh @ 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
children ffc5426c85a4
comparison
equal deleted inserted replaced
10089:dd70982c81a3 10090:655ab6f6c369
1 #!/bin/sh
2
3 # Copyright (C) 2010 VZLU Prague
4 #
5 # This file is part of Octave.
6 #
7 # Octave is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 3 of the License, or (at
10 # your option) any later version.
11 #
12 # Octave is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Octave; see the file COPYING. If not, see
19 # <http://www.gnu.org/licenses/>.
20
21 CLASSES="double single char logical int8 int16 int32 int64 \
22 uint8 uint16 uint32 uint64 struct cell function_handle"
23
24 for class in $CLASSES ; do
25 DIR=\@$class
26 test -d $DIR || mkdir $DIR || { echo "error: could not create $DIR" ; exit ; }
27 cat > $DIR/tbcover.m <<end
28 % DO NOT EDIT - generated automatically
29 function s = tbcover (x, y)
30 s = '$class';
31 end
32 done
33
34 cat > tbcover.m <<end
35 % DO NOT EDIT - generated automatically
36 function s = tbcover (x, y)
37 s = 'none';
38 end
39
40 if test "$1" == "overloads_only" ; then
41 exit
42 fi
43
44 cat > test_bc_overloads.m <<end
45 ## THIS IS AN AUTOMATICALLY GENERATED FILE --- DO NOT EDIT ---
46 ## instead modify build_bc_overload_tests.sh to generate the tests that you want.
47
48 %!shared ex
49 %! ex.double = 1;
50 %! ex.single = single(1);
51 %! ex.logical = true;
52 %! ex.char = 'char';
53 %! ex.int8 = int8 (1);
54 %! ex.int16 = int16 (1);
55 %! ex.int32 = int32 (1);
56 %! ex.int64 = int64 (1);
57 %! ex.uint8 = uint8 (1);
58 %! ex.uint16 = uint16 (1);
59 %! ex.uint32 = uint32 (1);
60 %! ex.uint64 = uint64 (1);
61 %! ex.cell = {};
62 %! ex.struct = struct ();
63 %! ex.function_handle = @numel;
64
65 end
66
67 cat bc_overloads_expected |\
68 while read cl1 cl2 clr ; do
69 cat >> test_bc_overloads.m <<end
70 %% Name call
71 %!assert (tbcover (ex.$cl1, ex.$cl2), "$clr")
72 %% Handle call
73 %!assert ((@tbcover) (ex.$cl1, ex.$cl2), "$clr")
74
75 end
76 done
77
78 cat >> test_bc_overloads.m <<end
79 %%test handles through cellfun
80 %!test
81 %! f = fieldnames (ex);
82 %! n = numel (f);
83 %! s = c1 = c2 = cell (n);
84 %! for i = 1:n
85 %! for j = 1:n
86 %! c1{i,j} = ex.(f{i});
87 %! c2{i,j} = ex.(f{j});
88 %! s{i,j} = tbcover (ex.(f{i}), ex.(f{j}));
89 %! endfor
90 %! endfor
91 %! assert (cellfun (@tbcover, c1, c2, "uniformoutput", false), s);
92 end