diff options
| author | manuel <manuel@mausz.at> | 2011-06-29 03:01:35 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-06-29 03:01:35 +0200 |
| commit | 04c19bc7ccae1ce8e20733c075df5e9d6c448fc4 (patch) | |
| tree | 8957ab770ce6ea7a17d121c829a71eef781833e4 /eiffel-fragen/replaceability | |
| parent | 28d807be719079971d2af7c3d2b62199f490a7e0 (diff) | |
| download | foop-04c19bc7ccae1ce8e20733c075df5e9d6c448fc4.tar.gz foop-04c19bc7ccae1ce8e20733c075df5e9d6c448fc4.tar.bz2 foop-04c19bc7ccae1ce8e20733c075df5e9d6c448fc4.zip | |
add replaceabality test
Diffstat (limited to 'eiffel-fragen/replaceability')
| -rw-r--r-- | eiffel-fragen/replaceability/base.e | 13 | ||||
| -rw-r--r-- | eiffel-fragen/replaceability/derived.e | 25 | ||||
| -rw-r--r-- | eiffel-fragen/replaceability/derived2.e | 28 | ||||
| -rw-r--r-- | eiffel-fragen/replaceability/replaceability.ecf | 21 | ||||
| -rw-r--r-- | eiffel-fragen/replaceability/test.e | 26 |
5 files changed, 113 insertions, 0 deletions
diff --git a/eiffel-fragen/replaceability/base.e b/eiffel-fragen/replaceability/base.e new file mode 100644 index 0000000..61f0eb9 --- /dev/null +++ b/eiffel-fragen/replaceability/base.e | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | class | ||
| 2 | BASE | ||
| 3 | |||
| 4 | feature | ||
| 5 | add10(num: INTEGER): INTEGER | ||
| 6 | require | ||
| 7 | base_always_false: false -- always false | ||
| 8 | do | ||
| 9 | RESULT := num + 10 | ||
| 10 | ensure | ||
| 11 | base_always_true: true | ||
| 12 | end | ||
| 13 | end | ||
diff --git a/eiffel-fragen/replaceability/derived.e b/eiffel-fragen/replaceability/derived.e new file mode 100644 index 0000000..9a409bd --- /dev/null +++ b/eiffel-fragen/replaceability/derived.e | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | class | ||
| 2 | DERIVED | ||
| 3 | |||
| 4 | inherit | ||
| 5 | BASE | ||
| 6 | redefine add10 | ||
| 7 | end | ||
| 8 | |||
| 9 | feature | ||
| 10 | add10(num: INTEGER): INTEGER | ||
| 11 | require else | ||
| 12 | -- my precondition | ||
| 13 | derived_num_positive: num > 0 | ||
| 14 | do | ||
| 15 | RESULT := num + 10 | ||
| 16 | ensure then | ||
| 17 | -- my postcondition | ||
| 18 | derived_result_equals_myresult: RESULT = myresult | ||
| 19 | end | ||
| 20 | |||
| 21 | myresult: INTEGER | ||
| 22 | do | ||
| 23 | RESULT := 110 | ||
| 24 | end | ||
| 25 | end | ||
diff --git a/eiffel-fragen/replaceability/derived2.e b/eiffel-fragen/replaceability/derived2.e new file mode 100644 index 0000000..232ea6c --- /dev/null +++ b/eiffel-fragen/replaceability/derived2.e | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | class | ||
| 2 | DERIVED2 | ||
| 3 | |||
| 4 | inherit | ||
| 5 | BASE | ||
| 6 | redefine add10 select add10 | ||
| 7 | end | ||
| 8 | DERIVED | ||
| 9 | rename add10 as derived_add10 | ||
| 10 | redefine myresult | ||
| 11 | end | ||
| 12 | |||
| 13 | feature | ||
| 14 | add10(num: INTEGER): INTEGER | ||
| 15 | require else | ||
| 16 | -- stronger precondition | ||
| 17 | derived2_num_between_1_and_10: num >= 1 and num <= 10 | ||
| 18 | do | ||
| 19 | RESULT := derived_add10(num) | ||
| 20 | ensure then | ||
| 21 | -- weaken postcondition | ||
| 22 | end | ||
| 23 | |||
| 24 | myresult: INTEGER | ||
| 25 | do | ||
| 26 | RESULT := 20 | ||
| 27 | end | ||
| 28 | end | ||
diff --git a/eiffel-fragen/replaceability/replaceability.ecf b/eiffel-fragen/replaceability/replaceability.ecf new file mode 100644 index 0000000..1cd86ef --- /dev/null +++ b/eiffel-fragen/replaceability/replaceability.ecf | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | <?xml version="1.0" encoding="ISO-8859-1"?> | ||
| 2 | <system xmlns="http://www.eiffel.com/developers/xml/configuration-1-7-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-7-0 http://www.eiffel.com/developers/xml/configuration-1-7-0.xsd" name="replaceability" uuid="ABD750A4-A528-4FEE-A7EA-37791A0D0F37"> | ||
| 3 | <target name="replaceability"> | ||
| 4 | <description>replaceability test</description> | ||
| 5 | <root class="TEST" feature="run"/> | ||
| 6 | <version major="0" minor="1" release="0" build="0" product="TEST"/> | ||
| 7 | <option warning="true" is_attached_by_default="true" void_safety="all"> | ||
| 8 | <assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/> | ||
| 9 | </option> | ||
| 10 | <setting name="console_application" value="true"/> | ||
| 11 | <precompile name="precompile" location="$ISE_PRECOMP\base.ecf"/> | ||
| 12 | <library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/> | ||
| 13 | <cluster name="replaceability" location=".\" recursive="true"> | ||
| 14 | <file_rule> | ||
| 15 | <exclude>/EIFGENs$</exclude> | ||
| 16 | <exclude>/CVS$</exclude> | ||
| 17 | <exclude>/.svn$</exclude> | ||
| 18 | </file_rule> | ||
| 19 | </cluster> | ||
| 20 | </target> | ||
| 21 | </system> | ||
diff --git a/eiffel-fragen/replaceability/test.e b/eiffel-fragen/replaceability/test.e new file mode 100644 index 0000000..09a0821 --- /dev/null +++ b/eiffel-fragen/replaceability/test.e | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | class | ||
| 2 | TEST | ||
| 3 | |||
| 4 | create | ||
| 5 | run | ||
| 6 | |||
| 7 | feature {NONE} -- Initialization | ||
| 8 | |||
| 9 | run | ||
| 10 | local | ||
| 11 | base: BASE | ||
| 12 | derived: DERIVED | ||
| 13 | derived2: DERIVED2 | ||
| 14 | ret: INTEGER | ||
| 15 | do | ||
| 16 | create base | ||
| 17 | create derived | ||
| 18 | create derived2 | ||
| 19 | |||
| 20 | ret := derived.add10(100) -- works | ||
| 21 | --ret := derived2.add10(100) -- fails due to stronger preconditions | ||
| 22 | |||
| 23 | --ret := derived.add10(10) -- fails due to precondition | ||
| 24 | ret := derived2.add10(10) -- works due to weaker preconditions | ||
| 25 | end | ||
| 26 | end | ||
