A follow along workshop to introduce the idea and concepts of using TDD for Advent of Code problems.
Advent of Code is an annual coding contest run by Eric Wastl run during the Christmas advent period each year. The contest posts a new puzzle each day of advent and you're free to use whatever language you like to find a solution to the puzzles.
Each day is split into two parts, the second of which is only shown to you once you have solved the first part. And be warned, the puzzles can get hard fast!
Advent of Code is a great opportunity to try to learn a new language or hone your coding skills and we're going to use it as an opportunity to apply Test Driven Development techniques.
In this workshop you will use the Day 1 problem from Advent of Code 2022. In the following exercises you will review the day 1 instructions, design and implement your tests first. We will guide you on some of the design and thought process behind each exercise.
The workshop is split up by branches, each branch will provide you with the next exercise which you will work through yourself to try and solve. In each subsequent exercise we will also provide a possible solution for the prior exercise, so you if you do get stuck you can look at what you may have missed.
You are currently in the main
branch. You will see other branches called exercise-1
to exercise-4 and final
you should work you way through these branches in numerical order to work your way through the tutorial.
Whilst you're welcome to follow these exercises in any language of your choosing and the lessons should be equally applicable from a problem solving perspective, the code provided here is written using Java.
We've tried to make this workshop as accessible as possible. Every branch contains a .devcontainer
folder which is a preconfigured development environment.
To get started we recommend you fork
this repo so you have your own copy to work on, when forking the repo select the option to fork all branches, if you forget to choose that then you can run git fetch --all
. You can either clone your fork to your local computer and work with any IDE or text editor of your choice, but if you use one which supports devcontainers such as VS Code then the .devcontainers
configuration in this repo will suggest you install the devcontainers extension and if you do so then it can use that information to automatically install the tools you will need including the JDK and Maven.
If you want to make it even easier you can use GitHub Codespaces which are cloud hosted development environments. Every GitHub account comes with a number of free devcontainer hours, even the free ones, so if you would like to do that take a look at the codespaces branch which will explain in detail how to use them.
The recommended approach for completing the exercises is to start working from exercise-1 and read the instructions via the browser so you don't need to keep checking out each branch. However, if you really get stuck and can't get your code to work, you can checkout the next exercise branch which will provide you with a complete working solution up to the prior exercise.
If you're ready to go, switch to the exercise-1 branch and get moving. Happy coding!