# Memory and Testing
<i>This lecture was also supplemented by some discussion of VSCode and the terminal; see [A "Quick" Guide to VSCode](https://hackmd.io/sh1NKYrpTi6-8d29znnncw) for more on that.</i>
## Table of Contents
1. [Data Structures and Memory](#memory)
1. [(More about) Testing](#testing)
## Data Structures and Memory <a name="memory"></a>
Let's talk a bit more about how Python sets, etc. work.
If I create a new list, and then immediately update it, like so:
```
dry_ingredients = ['flour', 'baking powder']
dry_ingredients = dry_ingredients + ['cinnamon']
```
The contents of `dry_ingredients` have changed! The list now contains `['flour', 'baking powder', 'cinnamon']`.
Sets work the same: they aren't "atomic" values like integers; they are storage containers for collections. This can sometimes have unintended consequences!
Let’s look at this Python program:
```
recipes = {'pbj': {'peanut butter', 'jelly', 'bread'},
'smoothie': {'peanut butter', 'banana', 'oat milk'}}
smoothie = recipes['smoothie']
chocolate_smoothie.add('cocoa powder')
berry_smoothie = recipes['smoothie'] | {'berries'}
```
What do all of these collections look like at the end of the program? (Try it!)
## (More about) Testing <a name="testing"></a>
Let’s test our word count code from last week, as a review of testing in Python. Since our Python code lives in `wordcount.py`, we’ll put testing code in wordcount_test.py. At the top of that file, we can put:
`from wordcount import *`.
We'll see more examples of this later. For now, the only thing to remember is that this lets us refer to all of the functions we have written in `wordcount.py`. That will be useful if we want to test them.
The convention we’ll use for this class (and which is often used in practice) is each function in the file we’re testing (`wordcount.py`) corresponds to a function in the test file whose name starts with `test_`. So, we’ll write tests like this:
```
def test_count_words():
pass
```
What would be a good set of test cases for `count_words`?
Here's an example set of tests:
```
def test_count_words():
assert count_words("") == {}
assert count_words("word") == {"word": 1}
assert count_words("word word") == {"word": 2}
assert count_words("word other word") == {"word": 2, "other": 1}
```
Of course, unless we actually <i>call</i> `test_count_words`, the tests will never be run! We could do that explicitly, like last time, but today we'll start using a more professional tool called `pytest`.
You might already have `pytest` installed! You can test by running it (instead of `python3`) on your test file.
If you don't have it installed, there are a few ways to get it. One is to type `python3 -m pip install pytest` into the terminal. (If you experience issues with this, definitely reach out!)