Now it’s time to create the first test. We’ll start with a failing test, and do something simple to get it to work.
Create a new file called Tokenizer.Tests.ps1:
Run your (now failing tests):
This failed, and it seems it failed for a reasonable reason. It doesn’t know about the type Tokenizer. To remedy this, we’ll create a module and import it into the test.
Create a new filed called Tokenizer.psm1:
At the top of Tokenizer.Tests.ps1, add the following line:
Run your tests and see that the error has changed a bit:
Closer, let’s get to a passing test. Again, we’ll do just enough to get the test passing.
Update Tokenizer.psm1:
Run your test (expecting things to pass):
This might be unexpected. If so, that’s good because when unexpected thigns happen, we’re about to learn something.
In this case, running Pester directly as we are updates the current shell. There are several solutions, but a trivial one is to run “powershell invoke-pester”:
Summary
There are many common complaints about TDD in such a simple start:
This doesn’t do anything
How can such small steps accomplish anything?
I know so much more about what I need to do, why don’t I jump ahead and save time?
… Insert another 20 complaints here.
I’m not going to even try to convince you that this does or does not work. We’ll work through the problem taking an extremely incremental approach. We’ll build up a solid footing so we can experiment later. Even so, this trivial example has demonstrated several (possibly incorrect) decisions:
We have a class that does this work called Tokenizer
We have a single method that we call, called tokenize
It takes a String and returns an array of Strings, one element for each token
Now that we have an API, we can focus on trying to grow the algorithm to make it work with at least the examples listed above.
Initialize And Initial Push
Make your shunting_yard_algorithm directory a git repo
Now add all the things:
Verify only the things we want to add have been added:
Make your first commit into your local git repo:
And look at the results:
You can verify that there are no local changes remaining:
Comments