/[ascend]/trunk/models/test/defaultmethods.a4c
ViewVC logotype

Contents of /trunk/models/test/defaultmethods.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1290 - (show annotations) (download) (as text)
Mon Feb 26 04:54:45 2007 UTC (17 years, 5 months ago) by johnpye
File MIME type: text/x-ascend
File size: 1778 byte(s)
Added new 'default' functionality plus test case
1 REQUIRE "system.a4l";
2
3 ATOM var_default_one REFINES solver_var
4 DIMENSIONLESS
5 DEFAULT 1.0;
6 nominal := 100;
7 lower_bound := 0.0;
8 upper_bound := 10000;
9 END var_default_one;
10
11 ATOM var_default_two REFINES solver_var
12 DIMENSIONLESS
13 DEFAULT 2.0;
14 nominal := 100;
15 lower_bound := 0.0;
16 upper_bound := 10000;
17 END var_default_two;
18
19 (* check that the on_load method sets 'x' to 1.0 *)
20 MODEL testdefault1;
21 x IS_A var_default_one;
22 METHODS
23 METHOD self_test;
24 ASSERT x == 1.0;
25 END self_test;
26 END testdefault1;
27
28 (*
29 check that the 'default_self' default method sets x DEFAULT to 2.0,
30 even if we override on_load
31 *)
32 MODEL testdefault2;
33 x IS_A var_default_two;
34 METHODS
35 METHOD on_load;
36 RUN default_self;
37 END on_load;
38 METHOD self_test;
39 ASSERT x == 2.0;
40 END self_test;
41 END testdefault2;
42
43 (* check the 'default' method gets called by on_load *)
44 MODEL testdefault3;
45 x IS_A var_default_one;
46 y IS_A var_default_one;
47 METHODS
48 METHOD default;
49 x := 3.0;
50 END default;
51 METHOD self_test;
52 ASSERT x == 3.0;
53 END self_test;
54 END testdefault3;
55
56 (* test that 'default' gets called even if defined in a parent model *)
57 MODEL testdefault4 REFINES testdefault3;
58 METHODS
59 METHOD self_test;
60 ASSERT x == 3.0;
61 END self_test;
62 END testdefault4;
63
64 (* test that we can override a 'default' method defined in a parent model *)
65 MODEL testdefault5 REFINES testdefault4;
66 METHODS
67 METHOD default;
68 x := 4.0;
69 END default;
70 METHOD self_test;
71 ASSERT x == 4.0;
72 END self_test;
73 END testdefault5;
74
75 (* test that a new 'default_self' method will kill the call to 'default' *)
76 MODEL testdefault6 REFINES testdefault4;
77 METHODS
78 METHOD default_self;
79 x := 5.0;
80 y := 6.0;
81 END default;
82 METHOD self_test;
83 ASSERT x == 5.0;
84 ASSERT y == 6.0;
85 END self_test;
86 END testdefault5;

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22