Mercurial > octave-nkf
annotate test/classdef/test_classdef.m @ 16049:ebd2259c5df1 classdef
Fix classdef tests.
* test/classdef/foo_method_changes_property_size.m: Use correct
constructor name.
* test/classdef/test_classdef.m: Likewise.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Mon, 11 Feb 2013 15:24:56 -0500 |
parents | 10142aad4b9f |
children |
rev | line source |
---|---|
15951
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
1 ## Copyright (C) 2013 Ben Abbott |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
2 ## |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
4 ## |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
8 ## your option) any later version. |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
9 ## |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
13 ## General Public License for more details. |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
14 ## |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
18 |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
19 %% Test script for classdef OOP. |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
20 %% Requires the path to contain the test classes. |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
21 %% |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
22 %% Note: This script and all classes are also intended to run |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
23 %% in MATLAB to test compatibility. Don't break that! |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
24 %% |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
25 %% To Do: This script tests to ensure that things done correctly work |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
26 %% corrrectly. It should also check that things done incorrectly |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
27 %% error properly. |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
28 %% |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
29 %% The classes used for the tests reside in the test/classdef with others |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
30 %% in the test directory. |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
31 %% |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
32 %% The classes provide the ability to test most of the major features |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
33 %% of the classdef OOP facilities. There are a number of classes, mostly |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
34 %% kind of the same, that create a hierarchy. |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
35 |
15959
de240df20290
Add tests to test_classdef.m
Ben Abbott <bpabbott@mac.com>
parents:
15952
diff
changeset
|
36 %% Basic classdef tests for value class |
de240df20290
Add tests to test_classdef.m
Ben Abbott <bpabbott@mac.com>
parents:
15952
diff
changeset
|
37 %!shared p, q, i, amt |
15961
3e782e337f8d
Rename classdef test class foo_payment to foo_value_class
Ben Abbott <bpabbott@mac.com>
parents:
15959
diff
changeset
|
38 %! q = foo_value_class (); |
3e782e337f8d
Rename classdef test class foo_payment to foo_value_class
Ben Abbott <bpabbott@mac.com>
parents:
15959
diff
changeset
|
39 %! p = foo_value_class (4, 4*12, 50e3); |
15951
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
40 %! i = p.rate / (12 * 100); |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
41 %! amt = (p.principle * i) / (1 - (1 + i)^(-p.term)); |
15959
de240df20290
Add tests to test_classdef.m
Ben Abbott <bpabbott@mac.com>
parents:
15952
diff
changeset
|
42 %!assert (isempty (q.rate)); |
de240df20290
Add tests to test_classdef.m
Ben Abbott <bpabbott@mac.com>
parents:
15952
diff
changeset
|
43 %!assert (isempty (q.principle)); |
de240df20290
Add tests to test_classdef.m
Ben Abbott <bpabbott@mac.com>
parents:
15952
diff
changeset
|
44 %!assert (isempty (q.term)); |
15961
3e782e337f8d
Rename classdef test class foo_payment to foo_value_class
Ben Abbott <bpabbott@mac.com>
parents:
15959
diff
changeset
|
45 %!assert (class (p), "foo_value_class"); |
15951
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
46 %!assert (p.term, 48); |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
47 %!assert (p.rate, 4.0); |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
48 %!assert (p.principle, 50e3); |
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
49 %!assert (p.amount, amt, eps ()) |
16048
10142aad4b9f
Implement indirect method call: fun(obj, ...).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15967
diff
changeset
|
50 %!assert (amount (p), amt, eps ()) |
15951
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
51 %!xtest |
15959
de240df20290
Add tests to test_classdef.m
Ben Abbott <bpabbott@mac.com>
parents:
15952
diff
changeset
|
52 %! assert (properties (p), {'rate'; 'term'; 'principle'}) |
15951
dd4258398a59
Move tests for classdef from test/classes.
Ben Abbott <bpabbott@mac.com>
parents:
diff
changeset
|
53 %!xtest |
15961
3e782e337f8d
Rename classdef test class foo_payment to foo_value_class
Ben Abbott <bpabbott@mac.com>
parents:
15959
diff
changeset
|
54 %! assert (methods (p), {'amount'; 'foo_value_class'}) |
3e782e337f8d
Rename classdef test class foo_payment to foo_value_class
Ben Abbott <bpabbott@mac.com>
parents:
15959
diff
changeset
|
55 %!assert (isempty (foo_value_class().rate)) |
3e782e337f8d
Rename classdef test class foo_payment to foo_value_class
Ben Abbott <bpabbott@mac.com>
parents:
15959
diff
changeset
|
56 %!error <property `rate' is not constant> foo_value_class.rate |
15962
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
57 |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
58 %% Static method and Constant Property |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
59 %!assert (foo_static_method_constant_property.radians_per_cycle, 2*pi); |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
60 %!assert (foo_static_method_constant_property().radians_per_cycle, 2*pi); |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
61 %!assert (foo_static_method_constant_property().pie, pi); |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
62 %!error <property `frequency' is not constant> foo_static_method_constant_property.frequency |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
63 %!error <method `cosine' is not static> foo_static_method_constant_property.cosine |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
64 %!test |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
65 %! obj = foo_static_method_constant_property; |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
66 %! obj.frequency = 10; |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
67 %! assert (obj.cosine (0.1), cos (2 * pi * 10 * 0.1), eps ()) |
a3d7b927ce47
Add classdef tests for static methods and constant properties.
Ben Abbott <bpabbott@mac.com>
parents:
15961
diff
changeset
|
68 %! assert (obj.sine (0.1), sin (2 * pi * 10 * 0.1), eps ()) |
15967
24ceda35d146
Add classdef tests for method changing the size of a property.
Ben Abbott <bpabbott@mac.com>
parents:
15962
diff
changeset
|
69 |
24ceda35d146
Add classdef tests for method changing the size of a property.
Ben Abbott <bpabbott@mac.com>
parents:
15962
diff
changeset
|
70 %!xtest |
16049
ebd2259c5df1
Fix classdef tests.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
16048
diff
changeset
|
71 %! obj = foo_method_changes_property_size (3); |
15967
24ceda35d146
Add classdef tests for method changing the size of a property.
Ben Abbott <bpabbott@mac.com>
parents:
15962
diff
changeset
|
72 %! obj = obj.move_element_to_end (2); |
24ceda35d146
Add classdef tests for method changing the size of a property.
Ben Abbott <bpabbott@mac.com>
parents:
15962
diff
changeset
|
73 %! assert (obj.element, [1 3 2]) |