Mercurial > hg > octave-nkf
annotate test/range.tst @ 20777:5d31cd795c21 stable
methods.m: try Java class names if getMethods fails on Java objects (bug #46010)
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Fri, 02 Oct 2015 17:44:53 +0200 |
parents | ba032e57fd96 |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
1 ## Copyright (C) 2007-2015 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 | |
6938 | 19 ## Test values of range |
20 | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 %!assert (full (1:9), [ 1 2 3 4 5 6 7 8 9 ]) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
22 %!assert (full (1:0.4:3), [ 1.0 1.4 1.8 2.2 2.6 3.0 ]) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
23 %!assert (full (9:1), zeros (1,0)) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
24 %!assert (full (9:-1:1), [ 9 8 7 6 5 4 3 2 1 ]) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
25 %!assert (full (1:-1:9), zeros (1,0)) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
26 %!assert (full (1:1:1), 1) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
27 %!assert (full (i:2i:10i), zeros (1,0)) |
6938 | 28 |
29 ## Test mixing integer range with other types | |
30 | |
31 %!shared expect, r, z | |
32 %! expect = [ 1 2 3 4 5 6 7 8 9 | |
33 %! 0 0 0 0 0 0 0 0 0 ]; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
34 %! z = zeros (1,9); |
6938 | 35 %! r = 1:9; |
36 | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
37 %!assert ([ r ; z ], expect) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
38 %!assert ([ r ; single(z) ], single (expect)) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
39 %!assert ([ r ; logical(z) ], expect) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
40 %!assert ([ r ; sparse(z) ], sparse (expect)) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
41 %!assert ([ r ; sparse(logical(z)) ], sparse (expect)) |
6938 | 42 |
16213
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
43 %!assert ([ r ; int8(z) ], int8 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
44 %!assert ([ r ; int16(z) ], int16 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
45 %!assert ([ r ; int32(z) ], int32 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
46 %!assert ([ r ; int64(z) ], int64 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
47 %!assert ([ r ; uint8(z) ], uint8 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
48 %!assert ([ r ; uint16(z) ], uint16 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
49 %!assert ([ r ; uint32(z) ], uint32 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
50 %!assert ([ r ; uint64(z) ], uint64 (expect)) |
6938 | 51 |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
52 ## Test mixing non-integer range with other types |
6938 | 53 |
54 %!shared expect, r, z | |
55 %! expect = [ 1.0 1.4 1.8 2.2 2.6 3.0 | |
56 %! 0 0 0 0 0 0 ]; | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
57 %! z = zeros (1,6); |
6938 | 58 %! r = 1:0.4:3; |
59 | |
14131
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
60 %!assert ([ r ; z ], expect) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
61 %!assert ([ r ; single(z) ], single (expect)) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
62 %!assert ([ r ; logical(z) ], expect) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
63 %!assert ([ r ; sparse(z) ], sparse (expect)) |
c3309e1ec50d
test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
64 %!assert ([ r ; sparse(logical(z)) ], sparse (expect)) |
6938 | 65 |
16213
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
66 %!assert ([ r ; int8(z) ], int8 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
67 %!assert ([ r ; int16(z) ], int16 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
68 %!assert ([ r ; int32(z) ], int32 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
69 %!assert ([ r ; int64(z) ], int64 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
70 %!assert ([ r ; uint8(z) ], uint8 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
71 %!assert ([ r ; uint16(z) ], uint16 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
72 %!assert ([ r ; uint32(z) ], uint32 (expect)) |
b1283d4c06c2
test: Use Octave coding standards for scripts in test/ directory.
Rik <rik@octave.org>
parents:
16179
diff
changeset
|
73 %!assert ([ r ; uint64(z) ], uint64 (expect)) |
6938 | 74 |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
75 ## Test corner cases of ranges (base and limit) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
76 |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
77 %!shared r, rrev, rneg |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
78 %! r = -0:3; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
79 %! rrev = 3:-1:-0; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
80 %! rneg = -3:-0; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
81 |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
82 %!assert (full (r), [-0 1 2 3]) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
83 %!assert (signbit (full (r)), logical ([1 0 0 0])) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
84 %!assert (r(1), -0) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
85 %!assert (signbit (r(1)), true) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
86 %!assert (signbit (r(1:2)), logical ([1 0])) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
87 %!assert (signbit (r(2:-1:1)), logical ([0 1])) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
88 %!assert (signbit (r([2 1 1 3])), logical ([0 1 1 0])) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
89 |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
90 %!assert (full (rrev), [3 2 1 -0]) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
91 %!assert (signbit (full (rrev)), logical ([0 0 0 1])) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
92 %!assert (rrev(4), -0) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
93 %!assert (signbit (rrev(4)), true) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
94 %!assert (signbit (rrev(3:4)), logical ([0 1])) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
95 %!assert (signbit (rrev(4:-1:3)), logical ([1 0])) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
96 %!assert (signbit (rrev([1 4 4 2])), logical ([0 1 1 0])) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
97 |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
98 %!assert (min (r), -0) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
99 %!assert (signbit (min (r)), true) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
100 %!assert (min (rrev), -0) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
101 %!assert (signbit (min (rrev)), true) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
102 |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
103 %!assert (max (rneg), -0) |
16179
025393bef399
range.tst: Correct typo min -> max in test.
Rik <rik@octave.org>
parents:
16169
diff
changeset
|
104 %!assert (signbit (max (rneg)), true) |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
105 |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
106 %!assert (sort (r, "descend"), [3 2 1 -0]) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
107 %!assert (signbit (sort (r, "descend")), logical ([0 0 0 1])) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
108 %!assert (signbit (sort (rrev, "ascend")), logical ([1 0 0 0])) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
16030
diff
changeset
|
109 |
20668
ba032e57fd96
range.tst: Add tests for bug #45739.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
110 ## Test sorting of ranges (bug #45739) |
ba032e57fd96
range.tst: Add tests for bug #45739.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
111 |
ba032e57fd96
range.tst: Add tests for bug #45739.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
112 %!shared r, rrev |
ba032e57fd96
range.tst: Add tests for bug #45739.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
113 %! r = 1:2:10; |
ba032e57fd96
range.tst: Add tests for bug #45739.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
114 %! rrev = 10:-2:1; |
ba032e57fd96
range.tst: Add tests for bug #45739.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
115 |
ba032e57fd96
range.tst: Add tests for bug #45739.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
116 %!assert (sort (r, "descend"), [9 7 5 3 1]) |
ba032e57fd96
range.tst: Add tests for bug #45739.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
117 %!assert (sort (rrev, "ascend"), [2 4 6 8 10]) |
ba032e57fd96
range.tst: Add tests for bug #45739.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
118 |