Practice Project

A practice project is available on Github to make it easier to play with pattern matching in increasingly advanced scenarios.

Download Elixir code

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!

Comments are closed

This is a static version of the site. Comments are not available.

11 Comments

  1. Jaison Vieira on October 3, 2021 at 8:34 am

    I did all this using the previous lessons and some google for things I couldn’t figure out and only realized that I should go along with the next lessons when I got to binaries and it got extremely hard. 🤦🏽‍♂️

    I gotta say I learned a lot. Will keep with the next lessons and brush up on what I did so far. I’ve never seen a course like this. It’s very good and I will definitely do the next one.

    Great job, Mark!

  2. Maksym Kosenko on October 28, 2021 at 3:05 pm

    I like TDD, it’s like an old school Ruby Way.
    Awesome!!! 🔥 🔥 🔥
    Thanks Mark

  3. Larry Rix on October 28, 2022 at 3:09 pm

    PS D:\dev\edu\pattern_matching> iex.bat -S mix
    warning: use Mix.Config is deprecated. Use the Config module instead
    config/config.exs:12

    Interactive Elixir (1.14.1) – press Ctrl+C to exit (type h() ENTER for help)
    iex(1)>

    • Caleb Josue Ruiz Torres on August 24, 2023 at 4:57 pm

      Most likely you have already figured this out.

      But in case any other person wants to get rid of this warning.

      One shall change Line of Code # 12 at `config/config.exs` as follows.

      `use Mix.Config` will become `import Config`.


      Caleb

    • Mark Ericksen on September 28, 2023 at 8:14 am

      I updated the downloads to not give this warning any more. Thanks!

  4. Marko Kosir on November 7, 2023 at 2:27 pm

    If I run “mix test” in unzipped folder I get 0 failures:

    mix test
    …………………………………………
    Finished in 0.1 seconds (0.00s async, 0.1s sync)
    48 tests, 0 failures

    Shouldn’t there be lots of errors?

    • Mark Ericksen on November 7, 2023 at 8:41 pm

      Hi Marko!

      Yes, there should have been errors. I corrected the issue. A recent update to the project file accidentally left it on the “solutions” branch instead of the “main” branch. You can re-download the file to have it correct.

  5. Marcus West on June 25, 2024 at 3:40 pm

    I can see all the tasks in lib/pattern_matching but there are no instructions

    • Mark Ericksen on June 25, 2024 at 5:06 pm

      Hi Marcus! Sorry for the confusion, the instructions are part of the course. After downloading the project, continue to the next lesson for the instructions.

  6. Benjamin Li on November 24, 2024 at 1:33 pm

    Hi Mark, getting a “Request Denied”, “Access has expired” error from s3 when trying to download the project

    • Mark Ericksen on November 24, 2024 at 1:40 pm

      Hi Benjamin!

      Refresh the page and try downloading it again. The link is a time-based authenticated S3 file link. If the page is open too long before downloading, the link will have expired. Sorry for the inconvenience! Hope that helps!

Comments are closed on this static version of the site.