3. Writing unit tests
For assignment 3 of the 2026 Winter PHY1610 course, we will look at a one-dimensional variant of Conway's Game of Life, as conceived by Jonathan K. Millen and published in BYTE magazine in December, 1978.
This system is a linear set of cells that are either "alive" or "dead", and time progresses in discrete steps.
The state of each cell at the next time step depends on its present state and that of its neighbours, in the following way:
- First, count the number of alive neighbours at most 2 cells away
- An alive cell stays alive if that count is 2 or 4, else it dies
- A dead cell becomes alive if that count is 2 or 3, else it stays dead.
Since the first two and the last two cells would not have enough neighbours to apply this rule, we will use cells on the other side as neighbours, i.e., we use 'periodic boundary conditions'.
The initial state of this system will be constructed with a given fraction of alive cells which are (nearly) equally spaced among dead cells.
Code
You are given a modular code that computes the time evolution of this system, and for each time step, prints out a line with a representation of the state and fraction of alive cells. The program can take parameters from the command line to set the number of cells, the number of time steps, and the initial fraction of alive cells. This code can be cloned on the Teach cluster as follows:
git clone /home/l/lcl_uotphy1610/lcl_uotphy1610s1466/gameof1d
To compile with make, and to do the assignment, you will have to load the gcc and catch2 modules
module load gcc/14.3 rarray/2.8.2 catch2/3.3.1Start by studying the code, make sure you understand what's going on. Make sure you can compile and run it on the Teach cluster.
Assignment task
Your task is to write an integrated test and unit tests for the modules in the code repository, The integrated test should use the monolythic ""originalgameof1d.cpp" as a base-line reference. You are to implement unit tests using the Catch2 library for at least three modules: the "fillcells" module, the "outputcells" module, and the "updatecells" module. In particular:
- For the fillcells module, this should test, for a few small number of cells (come up with about 5 cases), that cells uniformly filled by the initial_cells function.
- For the outputcells module, create 5 tests that create a few known configuration of cells, writes that out, and checks that the output is as expected.
- For the updatecells module, write a test to see that a state with all cells alive remains the same, as does a state with all dead cells. Come up with one more interesting case.
Write separate rules in the Makefile to compile and run the unit tests of each module and a 'super' rule called "check" to run all three unit test programs and the integrated test.
Note that we expect to see several commits, and meaningful comments, and that all source files in that directory are added to the repo.
To submit your assignment, you should pack up your repository into a zip file using the "git2zip" command that is available on the Teach cluster. To use this command, simply type "git2zip" on the command line from the directory which contains your git repo (See https://education.scinet.utoronto.ca/mod/page/view.php?id=4284for more info). Then copy the resulting .zip file over to your computer and submit it here.
The deadline for the assignment is Ferbruary 5th, at 23:59 PM. The late policy can be found in the syllabus.