Mercurial > hg > octave-nkf
changeset 15937:d19397deff43 classdef
Add basic tests for classdef
* test/classes/foo_payment.m: New file defing a class via classdef.
* test/classes/module.mk: Add Include foo_payment in classes_FCN_FILES.
* test/classes/test_classes.m: Add tests for classdef.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Sun, 13 Jan 2013 13:20:31 -0500 |
parents | da4cd4ab36db |
children | 32fe9f6f229a |
files | test/classes/foo_payment.m test/classes/module.mk test/classes/test_classes.m |
diffstat | 3 files changed, 48 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/test/classes/foo_payment.m @@ -0,0 +1,30 @@ +classdef foo_payment + properties + rate; + term; + principle; + end + methods + function obj = foo_payment (r, t, p) + if (nargin == 0) + obj = struct ('rate', 0, 'term', 0, 'principle', 0); + elseif (nargin == 3) + obj.rate = r; + obj.term = t; + obj.principle = p; + else + error ('foo_payment:SyntaxError', ... + 'foo_payment: Invalid syntax') + end + end + function amt = amount (obj) + i = obj.rate / (12 * 100); + if (i == 0 && obj.term == 0) + amt = obj.principle; + else + amt = (obj.principle * i) / (1 - (1 + i)^(-obj.term)); + end + end + end +end +
--- a/test/classes/module.mk +++ b/test/classes/module.mk @@ -4,6 +4,7 @@ classes/@Blork/display.m \ classes/@Blork/get.m \ classes/@Blork/set.m \ + classes/foo_payment.m \ classes/@Cork/Cork.m \ classes/@Cork/click.m \ classes/@Cork/display.m \
--- a/test/classes/test_classes.m +++ b/test/classes/test_classes.m @@ -199,3 +199,20 @@ %! assert(isa(grk,'Blork')) %! assert(isa(grk,'Snork')) %! assert(isa(grk,'Spork')) + +%% Basic classdef tests +%!shared p, i, amt +%! p = foo_payment (4, 4*12, 50e3); +%! i = p.rate / (12 * 100); +%! amt = (p.principle * i) / (1 - (1 + i)^(-p.term)); +%!assert (class (p), "foo_payment"); +%!assert (p.term, 48); +%!assert (p.rate, 4.0); +%!assert (p.principle, 50e3); +%!assert (p.amount, amt, eps ()) +%!xtest +%! assert (amount (p), amt, eps ()) +%!xtest +%! xassert (properties (p), {'rate'; 'term'; 'principle'}) +%!xtest +%! xassert (methods (p), {'amount'; 'foo_payment'})