This challenge was about examples and how we can better represent them.

“…consider a volume discount rule that provides 10% off for purchases between 5 and 10 items, 15% for purchases between 10 and 20; and 20% above that. We can show this with the following scenario outline structure:

Given the purchase order contains <items>

When the user checks out

Then the discount offered should be <discount>”

The first thing that came to mind as soon as I read this is equivalence class partitioning. The only option that I liked was Option 1 (list ranges) because it is short but sweet. All the rest were either too vague (no idea of boundaries) or too much information (listing all values). I’m sure most people will choose that one.

|items            | discount |
|less than 5      |  0%      |
|between 5 and 10 | 10%      |
|between 10 and 20| 15%      |
|more than 20     | 20%      |

Doing this challenge made me think, aren’t there two types of rules here at play: discount or no discount? Lately I learned about the ‘Rule’ keyword from Gherkin v6, I did not know this until I stumbled upon the Gherkin reference page. Putting this into practice, I went ahead and put this together:

Rule: Discount does not apply

    Example: Volume discount does not apply
        Given the purchase order contains less than 5 items
        When the user checks out
        Then there is no discount offer

    Example: Membership discount does not apply
	...

Rule: Discount applies

    Example: Volume discount applies
        Given the purchase order contains <items>
        When the user checks out
        Then the discount offered should be <discount>
        Examples:
        |items            | discount |
        |between 5 and 10 | 10%      |
        |between 10 and 20| 15%      |
        |more than 20     | 20%      |

    Example: Special holiday offer
	...

This was not directly related to the challenge but it did made me think, sometimes the discount don’t just apply for volumes but also different types of situations. There could be discounts based on the season, type of membership, type of product bought. If you want to make the Gherkin more flexible then I can see how the Rule option would be immensely useful! Although I have no idea if I can put ‘Examples” within an ‘Example’, it feels weird.