MAS2008 Scientific Computing: Lab 7
Version control, testing, debugging


The following notebooks and videos are relevant for this lab:
Counting anagrams View Download
Noughts and crosses View Download
Permutations View Download
Listing subsets View Download

For the noughts and crosses notebook to work, you will first need to clone the repository at The procedure for this is the same as in Task 3.

Task 1: Unit test for anagrams

Download and open the notebook anagram_tests.ipynb. This defines a function list_anagrams(word) that returns a list of all the anagrams of a given word, and another function count_anagrams(word) that uses a different method to calculate the number of anagrams of a given word without actually listing them. (Here a "word" just means a string of letters, not necessarily a real word.) Your task is to write unit tests to check that these functions are working correctly. Things that you could check include the following: See the notebook subsets.ipynb for an example of how to write and run unit tests in Python.

Task 2: Debugging lists of subsets

Downoad and open the notebook subsets.ipynb. At the bottom, change the line list_subsets = list_subsets_a to list_subsets = list_subsets_b or list_subsets = list_subsets_c or list_subsets = list_subsets_d, then run the notebook from the beginning. You should see that the code runs without error for list_subsets_a, but that it fails for the other three functions. Read the output from the unit tests carefully to see which tests are failing for which values of $n$ and $m$. Then try to work out why they are failing, using the VS Code debugger if necessary. The functions list_subsets_b and list_subsets_c can be fixed by quite small changes. The function list_subsets_d only fails one test, but it is not so easy to correct that.

Task 3: Cloning a repository

First, make sure that Git is installed and configured. Click "Terminal" at the top of the VS Code window to open a new terminal. By default, this will give you a cmd window or a PowerShell window, which may not allow you to run Git. At the top right of the terminal window you should see something like this: . Clicking the downward arrow next to the plus will open a menu like this:

If "Git Bash" is an option, then select it. If "Git Bash" is not an option, then you probably do not have Git installed, so you should do that, restart VS Code, and try again. Once you have a git bash window, type the following commands, replacing my details with your own:

     git config --global "Neil Strickland"
     git config --global ""

You should also install the GitLens extension in VS Code. Click on the icon on the left hand side of the screen, type "GitLens" in the search box, then click "Install".

Now visit the zoopy repository at You will see that there are just four files there, which you can look at in your browser. Now clone the repository to your computer. To do this, first click the green "Code" button on the web page, which will expand a menu like this:

Make sure that you have selected "HTTPS", and copy the URL shown in the box.

Now open your main Python folder in VS Code. Click on "Terminal" in the menu at the top of the screen, and then "New Terminal". This will open a terminal window at the bottom of the screen. In that window, type the following command:

     git clone
This will create a new subfolder called zoopy in your main Python folder. Use the File menu to open this subfolder (instead of your main Python folder) in VS Code. You should see that it contains copies of the four files that you saw on the web page.

Now go back to your terminal window and type

     pip install Pillow tk customtkinter
Then open the file in VS Code, and run it by clicking the icon at the top right of the screen. A new window should pop up, and you can interact with is as described on the zoopy web page.

Now click the icon on the left hand side of the screen to open the Source Control view. Next to the words "SOURCE CONTROL" you should see a smaller icon like . (You might need to hover over the words "SOURCE CONTROL" to make this icon appear.) Click on it to open the commit graph showing the history of the repository. Click around to see what you can understand.

Now edit one or more of the files. For example, you could change the list of emoji that are actually used at line 34 of, or the size of the window at line 40, or some other parameters. Alternatively, you could add to the list of spare emoji in the file emoji.txt. If you are more ambitious, you could work out how to make the window switch between a white background and a black background when the user presses the comma key (and modify the instructions in accordingly).

Now go back to the Source Control view. You should see that the files that you have changed are listed under "Changes", with an "M" to indicate that they have been modified. If you hover over the file names, you should see a "+" icon appear which you can click to stage the changes. Once you have staged all the changes that you want to commit, you can type a commit message in the box at the top of the screen and click the tick icon to commit the changes. You can then go back to the commit graph to see the new commit that you have created. (VS Code may invite you to push the changes to the repository on GitHub, but you do not have the required permissions to do that.)