Skip to content

Commit

Permalink
Scenario with output parameters (alpha)
Browse files Browse the repository at this point in the history
  • Loading branch information
six42 committed Oct 16, 2014
1 parent 755aca3 commit bd77e26
Show file tree
Hide file tree
Showing 22 changed files with 438 additions and 48 deletions.
Expand Up @@ -27,7 +27,7 @@ beat Bill with a noodle
|login user with password;|Bob|xyzzy|

!3 Scenarios can be defined without a filler name between the underscores
|scenario | myDivision _ _ _|numerator, denominator, quotient|
|scenario | my division _ _ _|numerator, denominator, quotient|
|setNumerator| @numerator|
|setDenominator| @denominator|
|check | quotient| @quotient|
Expand All @@ -36,16 +36,22 @@ Use the Division class from the eg library to implement the scenario
|Library|
|eg.Division|

Test the scenario with a decision table
| myDivision |
!4 Test the scenario with a decision table
| my division |
| # | numerator | denominator | quotient |
| any comment| 10 | 2 | 5.0 |

You can change the order of the columns
| my division |
|quotient | # | numerator | denominator |
| 5.0| any comment| 10 | 2 |

Test the scenario with a script

!4 Test the scenario with a script
the order of the parameters can't be changed!
|script|
|myDivision 20 5 4.0|
|myDivision |6|| 3|| 2.0|
|#| open Bug: The next syntax fails|
|#|myDivision; |10 2 5.0|
|my division 20 5 4.0|
|my division |6|| 3|| 2.0|
|my division; |35 |5| 7.0 |


Expand Up @@ -2,12 +2,11 @@
<properties>
<Edit/>
<Files/>
<Help/>
<LastModifyingUser>six42</LastModifyingUser>
<Properties/>
<RecentChanges/>
<Refactor/>
<Search/>
<Suites/>
<Test/>
<Versions/>
<WhereUsed/>
Expand Down
@@ -0,0 +1,43 @@
Output parameters in scenarios are flagged with a question mark in the header row, like in decision tables.
For each output parameter a symbol with the same name must be assigned a value in the scenario.

See below a sample of a division scenario with output parameter "result"

|scenario | my division |numerator| | denominator| | result?|
|setNumerator| @numerator|
|setDenominator| @denominator|
|$result= | quotient|


Get the Division implementation from the eg package
|Library|
|eg.Division|



| my division |
| numerator | denominator | result? |
| 10 | 2 | $x= |
| $x | 1 | 5.0 |


!3 A result calculated in one row and assigned to a symbol can be used in the next row
and the order of the columns doesn't matters

| my division |
| result? | numerator | denominator |
| $x= | 1000 | 2 |
| $x= | $x | 2 |
| $x= | $x | 2 |
| $x= | $x | 2 |
| $x= | $x | 2 |
| $x= | $x | 2 |
|7.8125 | $x | 2 |

!3 A result can be used in multiple columns in the decion table to do different checks
| my division |
| numerator | denominator | result? | result?|
| 10 | 2 | 5.0 | < 7.0|
| 12.6 | 3 | 4.2 | > 3.0|


@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<properties>
<Edit>true</Edit>
<Files>true</Files>
<LastModifyingUser>six42</LastModifyingUser>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
<Search>true</Search>
<Test>true</Test>
<Versions>true</Versions>
<WhereUsed>true</WhereUsed>
</properties>
@@ -0,0 +1,47 @@
!1 Scripts can call scenarios with output parameters

Output parameters in scenarios are flagged with a question mark in the header row, like in decision tables.
For each output parameter a symbol with the same name must be assigned a value in the scenario.

In the calling script you can than access the output parameter.
A scenario can have also more than one output parameter

See below a sample of a division scenario with output parameter "quotient"

|scenario | Mydivision |numerator| | denominator| | quotient?|
|setNumerator| @numerator|
|setDenominator| @denominator|
|$quotient= | quotient|


Get the Division implementation from the eg package
|Library|
|eg.Division|

The recommended syntax to call the scnario from a script is as below

|script|
|Mydivision; |35| 5 |
|check |echo| $quotient| 7.0|

|script|
| Mydivision |40| | 4| |
|check |echo| $quotient| 10.0|

The below is not recommended and might not work in the future
|script|
| Mydivision |40| | 10| | _|
|check |echo| $quotient| 4.0|

|script|
|Mydivision; |35 |5| _ |
|check |echo| $quotient| 7.0|


The following syntax is currently not working
!|script|
|# Mydivision 35 5 |
|# check |echo| $quotient| 7.0|



@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<properties>
<Edit>true</Edit>
<Files>true</Files>
<LastModifyingUser>six42</LastModifyingUser>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
<Search>true</Search>
<Test>true</Test>
<Versions>true</Versions>
<WhereUsed>true</WhereUsed>
</properties>
@@ -0,0 +1,64 @@
If a decision table is implemented with a class you can specify constructor arguments.
See .FitNesse.UserGuide.WritingAcceptanceTests.SliM.ConstructorArguments for details.

If a decision table is implemented with a scenario you can specify constructor arguments as well they have the following meaning:

|scenario | Division _ _ _|numerator, denominator, quotient?|
|setNumerator| @numerator|
|setDenominator| @denominator|
|$quotient= | quotient|

|library|
|eg.Division|

!3 Calling a Scenario with Constructor Parameters

The input variable "numerator" is given on the table construction line and must not be repeated in each row.
This can make the decison tables more readable.

| Division | having |numerator| 9|
| denominator | quotient? |
| 3 | 3.0 |
| 2 | 4.5 |

The Syntax is - Scenario Name - [given|having] - 1. Variable Name - 1. Variable Value - 2. Variable Name - 2. Variable Value - ....

!5 To ensure backward compatibility constructor parameters are first checked if they are part of a scenario name
If a senario is found it will be used and no constructor values are passed.
Only if no such scenario is found the constructor parameters can be used.

Example:

Again a scenario with the same signature as above
|scenario | Division _ _ _|numerator, denominator, quotient?|
|check| echo | @numerator|7|

| Division | having |numerator| 7|
| denominator |
| 3 |

Now a higher priority scenario name
This new scenario has a name which matches the constructor parameter name "numerator".
Calling again the same decision table will use this scenario.
But numerator will not have a value.
|scenario | Division Numerator _ _ _| numerator, denominator, quotient?|
|check| echo | @numerator|@numerator|
|check not |echo| @numerator|12|


| Division | having |numerator| 12|
| denominator |
| 3 |

!3 Scenario without output parameters can be used as well with constructor parameters
In this case the full line will be collered with the scenario test result. In scenarios with output parameters only the output column cells are colored.
|scenario | myDivision _ _ _|numerator, denominator, quotient|
|setNumerator| @numerator|
|setDenominator| @denominator|
|check | quotient| @quotient |

| myDivision | having |numerator| 12|
| denominator |quotient|
| 3 | 4.0|
|6|2.0|
|4|3.0|
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<properties>
<Edit>true</Edit>
<Files>true</Files>
<LastModifyingUser>six42</LastModifyingUser>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
<Search>true</Search>
<Test>true</Test>
<Versions>true</Versions>
<WhereUsed>true</WhereUsed>
</properties>
@@ -0,0 +1,2 @@
!1 !help
!contents -R2 -g -p -f -h
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<properties>
<Edit>true</Edit>
<Files>true</Files>
<Help>Test suite for Scenario Defintions</Help>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
<Search>true</Search>
<Suite>true</Suite>
<Suites></Suites>
<Versions>true</Versions>
<WhereUsed>true</WhereUsed>
</properties>
Expand Up @@ -5,5 +5,5 @@
| 22 | 7 | ~=3.14 |
| 9 | 3 | <5 |
| 11 | 2 | 4<_<6 |
| 100 | 4 | 25.0 |
| 25.0 | 5 | 5.0|
| 100 | 4 | $R1= |
| $R1 | 5 | 5.0|
Expand Up @@ -3,11 +3,11 @@
<Edit>true</Edit>
<Files>true</Files>
<Help>A sub page with requirements for a calculator.</Help>
<LastModifyingUser>six42</LastModifyingUser>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
<Search>true</Search>
<Suites></Suites>
<Versions>true</Versions>
<WhereUsed>true</WhereUsed>
</properties>
Expand Up @@ -22,10 +22,8 @@ Generate an instance of the class used by the scenario:
| Library |
| eg.Division|

|script | Division|


We retest the requirements and get the same results.
Also the output is differently printed.

!include >CalculatorRequirements
Expand Up @@ -2,7 +2,7 @@
<properties>
<Edit>true</Edit>
<Files>true</Files>
<LastModifyingUser>sa</LastModifyingUser>
<LastModifyingUser>six42</LastModifyingUser>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
Expand Down
Expand Up @@ -26,7 +26,7 @@ This page tests the above functions
|check| echo |$copy| [[[n, 1], [2n, 2]], [[n, 2], [2n, 4]]]|
|check |echo|$q|[[[n, 1], [2n, 2]], [[n, 2], [2n, 4]], [[n, 3], [2n, 6]]]|

!3 Free the symbol again
!3 Free the symbol
!|script|
|check| echo |$copy| [[[n, 1], [2n, 2]], [[n, 2], [2n, 4]]]|
|check |echo|$q|[[[n, 1], [2n, 2]], [[n, 2], [2n, 4]], [[n, 3], [2n, 6]]]|
Expand Down Expand Up @@ -57,27 +57,9 @@ This page tests the above functions
|check | echo | $cell |[n, 2]|
|$cell= | getValuefromTableResultSymbol;| $copy| 1| 1|
|check | echo | $cell |[2n, 4]|
|check | getValuefromTableResultSymbol;| $copy| 1| 1| [2n, 4]|

!3 No index out of range is crashing the slim client or wiki server
Also after an exception the value of a variable stays in sync between clint and server

|script|
|$cell= | getValuefromTableResultSymbol;| $copy| 2| 1|
|show | echo | $cell ||
|$clientCell= | cloneSymbol| $cell|
|check | echo | $cell |$clientCell|

|script|
|$cell= | getValuefromTableResultSymbol;| $copy| 1| 2|
|show | echo | $cell ||

|script|
|$cell= | getValuefromQueryResultSymbol;| $copy| 4| 2n|
|show | echo | $cell ||

|script|
|$cell= | getValuefromQueryResultSymbol;| $copy| 1| nix|
|show | echo | $cell ||

!3 Free the $copy, the $cell value must not be impacted
|script|
Expand Down

0 comments on commit bd77e26

Please sign in to comment.