Mercurial > octave
comparison scripts/miscellaneous/methods.m @ 32056:d98157d51a97
methods.m: Overhaul BIST testing.
* methods.m: Re-order BIST tests to reflect the order in the code.
Add BIST test for a classdef object and recode expected value for
classdef classname test. Add further assert() statement to test
for old-style @classnames. Add test for ordinary Java objects.
Remove %!error test for exceeding maximum number of inputs as
the interpreter now does that.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 26 Apr 2023 08:13:49 -0700 |
parents | dfd2b1a268a0 |
children | 2e484f9f1f18 |
comparison
equal
deleted
inserted
replaced
32055:dfd2b1a268a0 | 32056:d98157d51a97 |
---|---|
113 endif | 113 endif |
114 | 114 |
115 endfunction | 115 endfunction |
116 | 116 |
117 | 117 |
118 ## test classdef object | |
119 %!test | |
120 %! ip = inputParser (); | |
121 %! assert (methods (ip), | |
122 %! {"addOptional"; "addParamValue"; "addParameter"; "addRequired"; | |
123 %! "addSwitch"; "delete"; "disp"; "parse"; }); | |
124 | |
125 ## test classdef classname | |
126 %!assert (methods ("inputParser"), | |
127 %! {"addOptional"; "addParamValue"; "addParameter"; "addRequired"; | |
128 %! "addSwitch"; "delete"; "disp"; "parse"; }); | |
129 | |
118 ## test old-style @classname | 130 ## test old-style @classname |
119 %!test | 131 %!test |
120 %! mtds = methods ("ftp"); | 132 %! mtds = methods ("ftp"); |
121 %! assert (mtds{1}, "ascii"); | 133 %! assert (mtds{1}, "ascii"); |
134 %! assert (numel (mtds), 15); | |
122 | 135 |
123 ## test Java classname | 136 ## test Java classname |
124 %!testif HAVE_JAVA; usejava ("jvm") | 137 %!testif HAVE_JAVA; usejava ("jvm") |
125 %! mtds = methods ("java.lang.Double"); | 138 %! mtds = methods ("java.lang.Double"); |
126 %! search = strfind (mtds, "valueOf"); | 139 %! search = strfind (mtds, "valueOf"); |
130 %!testif HAVE_JAVA; usejava ("jvm") | 143 %!testif HAVE_JAVA; usejava ("jvm") |
131 %! mtds = methods ("java.lang.Double", "-full"); | 144 %! mtds = methods ("java.lang.Double", "-full"); |
132 %! search = strfind (mtds, "java.lang.Double valueOf"); | 145 %! search = strfind (mtds, "java.lang.Double valueOf"); |
133 %! assert (! isempty ([search{:}])); | 146 %! assert (! isempty ([search{:}])); |
134 | 147 |
135 ## test that methods does the right thing when passed a String object | 148 ## test Java object |
149 %!testif HAVE_JAVA; usejava ("jvm") | |
150 %! jobject = javaObject ("java.lang.Double", pi); | |
151 %! assert (methods (jobject), methods ("java.lang.Double")); | |
152 | |
153 ## test exceptional case of Java String object | |
136 %!testif HAVE_JAVA; usejava ("jvm") <*48758> | 154 %!testif HAVE_JAVA; usejava ("jvm") <*48758> |
137 %! object = javaObject ("java.lang.String", "java.lang.Integer"); | 155 %! jobject = javaObject ("java.lang.String", "java.lang.Integer"); |
138 %! assert (methods (object), methods ("java.lang.String")); | 156 %! assert (methods (jobject), methods ("java.lang.String")); |
139 | |
140 ## test classdef classname | |
141 %!assert (methods ("inputParser"), | |
142 %! {"addOptional"; "addParamValue"; "addParameter"; | |
143 %! "addRequired"; "addSwitch"; "add_missing"; "delete"; | |
144 %! "disp"; "error"; "is_argname"; "parse"; "validate_arg"; | |
145 %! "validate_name"}); | |
146 | 157 |
147 ## Test input validation | 158 ## Test input validation |
148 %!error <Invalid call> methods () | 159 %!error <Invalid call> methods () |
149 %!error methods ("a", "b", "c") | |
150 %!error <invalid option> methods ("ftp", "option1") | 160 %!error <invalid option> methods ("ftp", "option1") |
151 %!error <invalid input argument> methods (1) | 161 %!error <invalid input argument> methods (1) |