Mercurial > octave-nkf
changeset 15962:a3d7b927ce47 classdef
Add classdef tests for static methods and constant properties.
* test/classdef/foo_static_method_constant_property.m: New file.
* test/classdef/module.mk: Include new file.
* test/classdef/test_classdef.m: Add tests.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Thu, 17 Jan 2013 18:11:48 -0500 |
parents | 3e782e337f8d |
children | 24ceda35d146 |
files | test/classdef/foo_static_method_constant_property.m test/classdef/module.mk test/classdef/test_classdef.m |
diffstat | 3 files changed, 43 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/classdef/foo_static_method_constant_property.m Thu Jan 17 18:11:48 2013 -0500 @@ -0,0 +1,30 @@ +classdef foo_static_method_constant_property + properties + frequency; + end + properties (Constant = true) + pie = pi; + end + methods + function obj = foo_static_method_constant_property (f) + if (nargin == 1) + obj.frequency = f; + elseif (nargin ~= 0) + error ('foo_static_method_constant_property:SyntaxError', ... + 'foo_static_method_constant_property: Invalid syntax') + end + end + function res = cosine (obj, t) + res = cos (obj.radians_per_cycle () * obj.frequency * t); + end + function res = sine (obj, t) + res = sin (obj.radians_per_cycle () * obj.frequency * t); + end + end + methods (Static) + function res = radians_per_cycle () + res = 2 * foo_static_method_constant_property.pie; + end + end +end +
--- a/test/classdef/module.mk Thu Jan 17 17:23:58 2013 -0500 +++ b/test/classdef/module.mk Thu Jan 17 18:11:48 2013 -0500 @@ -1,5 +1,6 @@ classdef_FCN_FILES = \ classdef/foo_value_class.m \ + classdef/foo_static_method_constant_property.m \ classdef/test_classdef.m FCN_FILES += $(classdef_FCN_FILES)
--- a/test/classdef/test_classdef.m Thu Jan 17 17:23:58 2013 -0500 +++ b/test/classdef/test_classdef.m Thu Jan 17 18:11:48 2013 -0500 @@ -55,3 +55,15 @@ %! assert (methods (p), {'amount'; 'foo_value_class'}) %!assert (isempty (foo_value_class().rate)) %!error <property `rate' is not constant> foo_value_class.rate + +%% Static method and Constant Property +%!assert (foo_static_method_constant_property.radians_per_cycle, 2*pi); +%!assert (foo_static_method_constant_property().radians_per_cycle, 2*pi); +%!assert (foo_static_method_constant_property().pie, pi); +%!error <property `frequency' is not constant> foo_static_method_constant_property.frequency +%!error <method `cosine' is not static> foo_static_method_constant_property.cosine +%!test +%! obj = foo_static_method_constant_property; +%! obj.frequency = 10; +%! assert (obj.cosine (0.1), cos (2 * pi * 10 * 0.1), eps ()) +%! assert (obj.sine (0.1), sin (2 * pi * 10 * 0.1), eps ())