| Import |
| com.greenpepper.samples.application.calculator |
The objective of this example is to present the basic behaviors of GreenPepper through the implementation of a Calculator. The simplicity of the Calculator example allows to avoid confusion between the system context and the specific behavior of GreenPepper Software.
 | The first executable specification:
- Our business expert on Calculators explained to the developer the rules for calculation. He started with the sum operation for only two numbers.
- The first line of the specification explains that we have particular rule for a Calculator. The calculator receives two numbers and it gives you back the sum of those two numbers.
- Once we hit the Execute button, GreenPepper calls the actual software containing the code for the Calculator. GreenPepper sends the parameters x (equal to 6) and y (equal to 3) to the Calculator to obtain the resulting sum of those two numbers. The "?" symbol next to the word "sum" is a key-sign that indicates to GreenPepper that a test must be is performed.
- In that particular example, GreenPepper will query the calculator application and compare the value returned by the system with the value specified by the business expert (in the "sum?" column).
- Since the result returned by the system is the same as the expected result, the cell is colored in green by GreenPepper.
|
The Calculator will be able to add the value of two numbers.
| rule for |
Calculator |
| x |
y |
sum? |
| 6 |
3 |
9 |
 | Adding another example:
- The business expert may want to add some new examples and re-run the tests.
- When there is an error, GreenPepper colors the cell in red.
- In the new example, it is clear that the values provided by the business expert are not correct. But the error could have been in the system. The business expert should always be consulted before any changes are made in the executable specifications.
|
The Calculator will be able to add the value of two new numbers. |
| rule for |
Calculator |
| x |
y |
sum? |
| 6 |
3 |
9 |
| 7 |
1 |
8 |
 | Adding new specifications:
- Our business expert on Calculators has also explained two other rules for the calculator: product and quotient.
- The new rules can be written in a way similar to the "sum" specification.
- In case of an expected errors, the keyword error may be used in order to test those special cases.
|
The Calculator will also be able to support the product and the quotient of two numbers |
| rule for |
Calculator |
| x |
y |
sum? |
product? |
quotient? |
| 6 |
2 |
8 |
12 |
3 |
| 7 |
0 |
7 |
0 |
error |