Practice Project
A practice project is available on Github to make it easier to play with pattern matching in increasingly advanced scenarios.
The project has no other dependencies so if you already have Elixir installed then you are ready.
Intro to TDD
TDD stands for “Test Driven Development“. The idea with TDD is that you spend some up-front time thinking about what your goal is with the code you will write. You first write a test that says, “given this situation and input, the code should cause this result or return this output.” The test is written to “assert” that the desired behavior happened. If the code doesn’t, then the test fails.
In this project the tests have already been written for you. The tests assert that a function behaves in a specific, desired way. Initially, all the tests are failing because the functions don’t behave correctly. The functions haven’t been implemented yet and that’s your job!
The value of the tests is they help validate and check that your solution satisfies the requirements. They are additionally helpful because they make it easy to continue to re-check your solution when you refactor or make other code changes.
Running Tests
Try running the tests for the whole project first. From a command-line terminal, go to the directory location where you downloaded the files and run the following command:
mix test
You should see a lot of errors. That’s expected. You are seeing all the failing tests for the whole project. Don’t worry about that, I’ll walk you through where to start working. We’ll focus on a single file at a time and within that file we’ll focus on just a couple tests at a time.
With the ability to run tests in the practice project, you’re ready to start really digging in to pattern matching!
11 Comments
Comments are closed on this static version of the site.
Comments are closed
This is a static version of the site. Comments are not available.