Regardless of how your requirements are written (or even if they are only in your mind), they include three parts. First is what the program/method must do: its business rules. Second, the program receives data as inputs. Inputs are a fundamental part of our reasoning, as it is through them that we can test the different cases. Third, reasoning about the output will help us better understand what the program does and how the inputs are converted to the expected output.
For the substringsBetween()
method, my reasoning would be
- The goal of this method is to collect all substrings in a string that are delimited by an
open
tag and aclose
tag (the user provides these). - The program receives three parameters:a)
str
, which represents the string from which the program will extract substringsb) Theopen
tag, which indicates the start of a substringc) Theclose
tag, which indicates the end of the substring - The program returns an array composed of all the substrings found by the program.
Such reflection is useful to think about what you want from the method.
Leave a Reply