Motivated by the reading of "The Pragmatic Programmer (20th Anniversary Edition)", I am trying to experiment with Property-Based Testing.
I think that the post Diamond kata with FsCheck by Mark Seemann could be a good start, but I want to use C# in place of F#.
Let's see what happens...
Maybe I had to should have read the complete blog post before the start because I think that I did not do it as progressively as I could, I did not take enough advantage of testing the properties.
I did it considering the capacity of dealing with each letter (A
, B
, etc.) as a feature. So, I started with A
(tests, and ugly implementation), B
(tests, and ugly implementation), and with C
I had the same problem as Mark and Seb.
Here, maybe I had to start from the beginning in order to take advantage of the properties, it would be nice considering each property as a feature as Mark did:
- First and last rows contain A
- All rows must have a symmetric contour
- Rows must contain the correct letters, in the correct order (without paying attention to the spaces)
- Diamond is as wide as it's high
- All rows except top and bottom have two identical letters
- Lower left space is a triangle
- Figure is symmetric around the horizontal axis
In place of that, I did it in the following order:
- Support
A
andB
- First and last rows contain
A
- All rows must have a symmetric contour
- All lines have the same length
- All lines have the same length on its leading and trailing spaces
- The first and the last letter in a line is the same
- Figure is symmetric around the horizontal axis
But, at that moment I had only support for A
and B
, and the same problem with the rest, but in the course, I learned to parse the lines and started to understand the logic to generate the diamond, so I could complete the kata in an only atomical step when I tried to meet Mark's 3rd step: "Rows must contain the correct letters, in the correct order" but in my case I payed attention to the spaces because I had already mature that.
It was a nice experience, I learned what a property is and I will try to use the concept of properties and testing properties (with or without a Property-Based Testing framework) in further opportunities.