Mercurial > octave-dspies
annotate test/prefer.tst @ 19010:3fb030666878 draft default tip dspies
Added special-case logical-indexing function
* logical-index.h (New file) : Logical-indexing function. May be called on
octave_value types via call_bool_index
* nz-iterators.h : Add base-class nz_iterator for iterator types. Array has
template bool for whether to internally store row-col or compute on the fly
Add skip_ahead method which skips forward to the next nonzero after its
argument
Add flat_index for computing octave_idx_type index of current position (with
assertion failure in the case of overflow)
Move is_zero to separate file
* ov-base-diag.cc, ov-base-mat.cc, ov-base-sparse.cc, ov-perm.cc
(do_index_op): Add call to call_bool_index in logical-index.h
* Array.h : Move forward-declaration for array_iterator to separate header file
* dim-vector.cc (dim_max): Refers to idx-bounds.h (max_idx)
* array-iter-decl.h (New file): Header file for forward declaration of
array-iterator
* direction.h : Add constants fdirc and bdirc to avoid having to reconstruct
them
* dv-utils.h, dv-utils.cc (New files) :
Utility functions for querying and constructing dim-vectors
* idx-bounds.h (New file) :
Utility constants and functions for determining whether things will overflow
the maximum allowed bounds
* interp-idx.h (New function : to_flat_idx) : Converts row-col pair to linear
index of octave_idx_type
* is-zero.h (New file) : Function for determining whether an element is zero
* logical-index.tst : Add tests for correct return-value dimensions and large
sparse matrix behavior
author | David Spies <dnspies@gmail.com> |
---|---|
date | Fri, 25 Jul 2014 13:39:31 -0600 |
parents | d63878346099 |
children |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
16937
diff
changeset
|
1 ## Copyright (C) 2006-2013 John W. Eaton |
7016 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
5590 | 19 %!test |
20 %! m = [3 2]; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 %! assert (all (m == (3:-1:2))); |
5590 | 22 |
23 %!test | |
24 %! m = [3, | |
25 %! 2]; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
26 %! assert (all (m == (3:-1:2)')); |
5590 | 27 |
28 %!test | |
29 %! a = 2; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
30 %! assert ([a - 1], 1); |
5590 | 31 |
32 %!test | |
33 %! m = [3,2]; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
34 %! fail ("[m ']"); |
5590 | 35 |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
36 %!assert (all ([3 2] == (3:-1:2))); |
5590 | 37 |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
38 %!assert (all ([3, 2] == (3:-1:2))); |
5590 | 39 |
40 %!test | |
41 %! m = [3,2]; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
42 %! assert (all ([m (1)] == (3:-1:1))); |
5590 | 43 |
44 %!test | |
45 %! m = [3,2]; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
46 %! assert ([m(1)],3); |
5590 | 47 |
48 %!test | |
49 %! a = 2; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
50 %! assert ([a- 1], 1); |
5590 | 51 |
52 %!test | |
53 %! a = 1; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
54 %! assert (all ([a -1] == (1:-2:-1))); |
5590 | 55 |
56 %!test | |
5781 | 57 %! wsn = warning ("query", "Octave:str-to-num"); |
58 %! warning ("off", "Octave:str-to-num"); | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
59 %! assert ("d" + 0, 100); |
5781 | 60 %! warning (wsn.state, "Octave:str-to-num"); |
5590 | 61 |
62 %!test | |
5781 | 63 %! wsn = warning ("query", "Octave:str-to-num"); |
64 %! warning ("on", "Octave:str-to-num"); | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
65 %! fail ("'d' + 0", "warning"); |
5781 | 66 %! warning (wsn.state, "Octave:str-to-num"); |
5590 | 67 |
68 %!test | |
5781 | 69 %! wir = warning ("query", "Ocave:imag-to-real"); |
70 %! warning ("off", "Ocave:imag-to-real"); | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
71 %! assert (eye (1+i), 1); |
5781 | 72 %! warning (wir.state, "Ocave:imag-to-real"); |
5590 | 73 |
74 %!test | |
5781 | 75 %! wir = warning ("query", "Ocave:imag-to-real"); |
76 %! warning ("on", "Ocave:imag-to-real"); | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
77 %! fail ("eye (1+i)", "warning"); |
5781 | 78 %! warning (wir.state, "Ocave:imag-to-real"); |
5590 | 79 |
80 %!test | |
5781 | 81 %! wrre = warning ("query", "Octave:resize-on-range-error"); |
82 %! warning ("off", "Octave:resize-on-range-error"); | |
16215
6fe6ac8bbfdb
test: Remove trailing spaces from ends of lines in test/ directory.
Rik <rik@octave.org>
parents:
16213
diff
changeset
|
83 %! clear a; |
6fe6ac8bbfdb
test: Remove trailing spaces from ends of lines in test/ directory.
Rik <rik@octave.org>
parents:
16213
diff
changeset
|
84 %! a(2) = 1; a(3) = 2; |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
85 %! assert (all (a == [0,1,2])); |
5781 | 86 %! warning (wrre.state, "Octave:resize-on-range-error"); |
5590 | 87 |
88 %!test | |
16215
6fe6ac8bbfdb
test: Remove trailing spaces from ends of lines in test/ directory.
Rik <rik@octave.org>
parents:
16213
diff
changeset
|
89 %! clear a; |
5590 | 90 %! a(1) = 1; a(2) = 2; |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
91 %! assert (all (a == [1,2])); |
5590 | 92 |
93 %!test | |
5794 | 94 %! ped = print_empty_dimensions (); |
95 %! print_empty_dimensions (0); | |
5590 | 96 %! a = cell (1, 1); |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8583
diff
changeset
|
97 %! b = type ("-q", "a"); |
8583
27b2db6ff0d7
test/test_prefer.m: update test to reflect new API of the 'type' function.
sh@sh-t400
parents:
8281
diff
changeset
|
98 %! assert (!isempty (findstr (b{1}, "[]"))); |
27b2db6ff0d7
test/test_prefer.m: update test to reflect new API of the 'type' function.
sh@sh-t400
parents:
8281
diff
changeset
|
99 %! assert (isempty (findstr (b{1} ,"[](0x0)"))); |
5794 | 100 %! print_empty_dimensions (ped); |
5590 | 101 |
102 %!test | |
5794 | 103 %! ped = print_empty_dimensions (); |
104 %! print_empty_dimensions (1); | |
5590 | 105 %! a = cell (1, 1); |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8583
diff
changeset
|
106 %! b = type ("-q", "a"); |
8583
27b2db6ff0d7
test/test_prefer.m: update test to reflect new API of the 'type' function.
sh@sh-t400
parents:
8281
diff
changeset
|
107 %! assert (!isempty (findstr (b{1}, "[](0x0)"))); |
5794 | 108 %! print_empty_dimensions (ped); |
5590 | 109 |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
110 %!assert (all (size (inv ([])) == [0, 0])); |
5590 | 111 |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
112 %!assert (all (svd ([]) == zeros (0, 1))); |
5590 | 113 |
114 %!test | |
5794 | 115 %! sp = save_precision (); |
116 %! save_precision (1); | |
5590 | 117 %! x = pi; |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
118 %! nm = tmpnam (); |
16213
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
119 %! save ("-text", nm, "x"); |
5590 | 120 %! clear x; |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
121 %! load (nm); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
122 %! unlink (nm); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
123 %! assert (x,3); |
5794 | 124 %! save_precision (sp); |
5590 | 125 |
126 %!test | |
5794 | 127 %! sp = save_precision (); |
128 %! save_precision (5); | |
5590 | 129 %! x = pi; |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
130 %! nm = tmpnam (); |
16213
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
131 %! save ("-text", nm, "x"); |
5590 | 132 %! clear x; |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
133 %! load (nm); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
134 %! unlink (nm); |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
135 %! assert (x, 3.1416); |
5794 | 136 %! save_precision (sp); |
5590 | 137 |
16215
6fe6ac8bbfdb
test: Remove trailing spaces from ends of lines in test/ directory.
Rik <rik@octave.org>
parents:
16213
diff
changeset
|
138 %% FIXME: How to capture standard output for comparison? |
5590 | 139 %!function f () |
140 %! 1 | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
141 %!endfunction |
5590 | 142 %!#test |
5794 | 143 %! sf = silent_functions (); |
144 %! silent_functions (0); | |
5590 | 145 %! f |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
146 %! assert (??); |
5794 | 147 %! silent_functions (sf); |
5590 | 148 |
16215
6fe6ac8bbfdb
test: Remove trailing spaces from ends of lines in test/ directory.
Rik <rik@octave.org>
parents:
16213
diff
changeset
|
149 %% FIXME: Same problem as above!!! |
5590 | 150 %!function f () |
151 %! 1 | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
152 %!endfunction |
5590 | 153 %!#test |
5794 | 154 %! sf = silent_functions (); |
155 %! silent_functions (1); | |
5590 | 156 %! f |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
157 %! assert (??); |
5794 | 158 %! silent_functions (sf); |
5590 | 159 |
160 %!test | |
5781 | 161 %! wndz = warning ("query", "Octave:neg-dim-as-zero"); |
162 %! warning ("on", "Octave:neg-dim-as-zero"); | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
163 %! fail ("eye (-1) == []", "warning"); |
5781 | 164 %! warning (wndz.state, "Octave:neg-dim-as-zero"); |
5590 | 165 |
166 %!test | |
5781 | 167 %! wndz = warning ("query", "Octave:neg-dim-as-zero"); |
168 %! warning ("off", "Octave:neg-dim-as-zero"); | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
169 %! assert (all (size (eye (-1)) == [0, 0])); |
5781 | 170 %! warning (wndz.state, "Octave:neg-dim-as-zero"); |
5590 | 171 |
172 %!test | |
5781 | 173 %! watv = warning ("query", "Octave:assign-as-truth-value"); |
174 %! warning ("off", "Octave:assign-as-truth-value"); | |
5590 | 175 %! if (x = 1) 1; endif |
5781 | 176 %! warning (watv.state, "Octave:assign-as-truth-value"); |
5590 | 177 |
178 %!test | |
5781 | 179 %! watv = warning ("query", "Octave:assign-as-truth-value"); |
180 %! warning ("on", "Octave:assign-as-truth-value"); | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
181 %! fail ("if (x = 1) 1; endif", "warning"); |
5781 | 182 %! warning (watv.state, "Octave:assign-as-truth-value"); |
5590 | 183 |
184 %!test | |
5781 | 185 %! wdbz = warning ("query", "Octave:divide-by-zero"); |
186 %! warning ("off", "Octave:divide-by-zero"); | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
187 %! assert (isinf (1/0)); |
5781 | 188 %! warning (wdbz.state, "Octave:divide-by-zero"); |
5590 | 189 |
190 %!test | |
5781 | 191 %! wdbz = warning ("query", "Octave:divide-by-zero"); |
192 %! warning ("on", "Octave:divide-by-zero"); | |
5590 | 193 %! a = 1; |
194 %! b = 0; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
195 %! fail ("isinf (a/b);", "warning") |
5781 | 196 %! warning (wdbz.state, "Octave:divide-by-zero"); |
5590 | 197 |