Tests for Task 5: Run the simulation

This page describes the tests for Task 5. For each task, we provide a short description of the test, information about how to recreate the test in ipython3, and the expected result.

To run the tasks for Task 5, run the following command at the Linux command-line:

$ py.test -xvk run

When you run this command, you’ll see that some tests are labelled as SKIPPED. You can ignore these tests for now,we’ll come back to them later when we introduce vaccines into our simulation.

Test 0

Description: No one is infected. The simulation stops immediately.

To run this test in ipython3 :

city = [('S', 0),    # loc: 0
        ('S', 0),    # loc: 1
        ('S', 0),    # loc: 2
        ('R', 0)]    # loc: 3
sir.run_simulation(city, 3, 0)

Expected result:

([['S', 0],    # loc: 0
  ['S', 0],    # loc: 1
  ['S', 0],    # loc: 2
  ['R', 0]],    # loc: 3
 0)

Test 1

Description: No one is susceptible. The simulation stops immediately.

To run this test in ipython3 :

city = [('I', 0),    # loc: 0
        ('I', 0),    # loc: 1
        ('R', 0),    # loc: 2
        ('R', 0)]    # loc: 3
sir.run_simulation(city, 3, 0)

Expected result:

([['I', 0],    # loc: 0
  ['I', 0],    # loc: 1
  ['R', 0],    # loc: 2
  ['R', 0]],    # loc: 3
 0)

Test 2

Description: Susceptible folks get infected on the first day.

To run this test in ipython3 :

city = [('S', 0),    # loc: 0
        ('S', 0),    # loc: 1
        ('I', 0)]    # loc: 2
sir.run_simulation(city, 3, 0)

Expected result:

([['I', 0],    # loc: 0
  ['I', 0],    # loc: 1
  ['I', 1]],    # loc: 2
 1)

Test 3

Description: Susceptible person gets infected on the first day. Infected person, recovers

To run this test in ipython3 :

city = [('S', 0),    # loc: 0
        ('R', 0),    # loc: 1
        ('I', 0)]    # loc: 2
sir.run_simulation(city, 1, 0)

Expected result:

([['I', 0],    # loc: 0
  ['R', 1],    # loc: 1
  ['R', 0]],    # loc: 2
 1)

Test 4

Description: Medium city: The suspectible person in the middle gets infected, while the susceptible person at the end is protected by recovered neighbors.

To run this test in ipython3 :

city = [('R', 0),    # loc: 0
        ('I', 0),    # loc: 1
        ('S', 0),    # loc: 2
        ('I', 1),    # loc: 3
        ('S', 0),    # loc: 4
        ('R', 0),    # loc: 5
        ('S', 0)]    # loc: 6
sir.run_simulation(city, 5, 0)

Expected result:

([['R', 1],    # loc: 0
  ['I', 1],    # loc: 1
  ['I', 0],    # loc: 2
  ['I', 2],    # loc: 3
  ['I', 0],    # loc: 4
  ['R', 1],    # loc: 5
  ['S', 1]],    # loc: 6
 1)

Test 5

Description: Medium city: infection ripples through the city. Recovered person at the end prevents wrap-around infections

To run this test in ipython3 :

city = [('I', 0),    # loc: 0
        ('S', 0),    # loc: 1
        ('S', 0),    # loc: 2
        ('S', 1),    # loc: 3
        ('S', 0),    # loc: 4
        ('S', 0),    # loc: 5
        ('S', 0),    # loc: 6
        ('R', 0)]    # loc: 7
sir.run_simulation(city, 3, 0)

Expected result:

([['R', 3],    # loc: 0
  ['R', 2],    # loc: 1
  ['R', 1],    # loc: 2
  ['R', 0],    # loc: 3
  ['I', 2],    # loc: 4
  ['I', 1],    # loc: 5
  ['I', 0],    # loc: 6
  ['R', 6]],    # loc: 7
 6)

Test 6

Description: Medium city: infection ripples through the city from both directions due to wrap-around

To run this test in ipython3 :

city = [('I', 0),    # loc: 0
        ('S', 0),    # loc: 1
        ('S', 0),    # loc: 2
        ('S', 1),    # loc: 3
        ('S', 0),    # loc: 4
        ('S', 0),    # loc: 5
        ('S', 0),    # loc: 6
        ('S', 0)]    # loc: 7
sir.run_simulation(city, 3, 0)

Expected result:

([['R', 1],    # loc: 0
  ['R', 0],    # loc: 1
  ['I', 2],    # loc: 2
  ['I', 1],    # loc: 3
  ['I', 0],    # loc: 4
  ['I', 1],    # loc: 5
  ['I', 2],    # loc: 6
  ['R', 0]],    # loc: 7
 4)

Test 7

Description: Large city. Some susceptible people get infected. Others are protected by recovered people.

To run this test in ipython3 :

city = [('I', 1),    # loc: 0
        ('R', 0),    # loc: 1
        ('S', 0),    # loc: 2
        ('S', 0),    # loc: 3
        ('S', 0),    # loc: 4
        ('R', 0),    # loc: 5
        ('S', 0),    # loc: 6
        ('S', 0),    # loc: 7
        ('S', 0),    # loc: 8
        ('I', 1),    # loc: 9
        ('I', 1),    # loc: 10
        ('R', 0),    # loc: 11
        ('S', 0),    # loc: 12
        ('S', 0),    # loc: 13
        ('S', 0),    # loc: 14
        ('R', 0),    # loc: 15
        ('S', 0),    # loc: 16
        ('S', 0),    # loc: 17
        ('S', 0),    # loc: 18
        ('I', 1),    # loc: 19
        ('S', 0),    # loc: 20
        ('S', 0),    # loc: 21
        ('S', 0),    # loc: 22
        ('I', 1),    # loc: 23
        ('R', 0),    # loc: 24
        ('S', 0),    # loc: 25
        ('S', 0),    # loc: 26
        ('S', 0),    # loc: 27
        ('R', 0),    # loc: 28
        ('S', 0),    # loc: 29
        ('S', 0),    # loc: 30
        ('S', 0),    # loc: 31
        ('I', 1),    # loc: 32
        ('I', 1),    # loc: 33
        ('R', 0),    # loc: 34
        ('S', 0),    # loc: 35
        ('S', 0),    # loc: 36
        ('S', 0),    # loc: 37
        ('R', 0),    # loc: 38
        ('S', 0),    # loc: 39
        ('S', 0),    # loc: 40
        ('S', 0),    # loc: 41
        ('I', 1),    # loc: 42
        ('S', 0),    # loc: 43
        ('S', 0),    # loc: 44
        ('S', 0),    # loc: 45
        ('S', 0),    # loc: 46
        ('S', 0),    # loc: 47
        ('S', 0)]    # loc: 48
sir.run_simulation(city, 2, 0)

Expected result:

([['R', 2],    # loc: 0
  ['R', 3],    # loc: 1
  ['S', 3],    # loc: 2
  ['S', 3],    # loc: 3
  ['S', 3],    # loc: 4
  ['R', 3],    # loc: 5
  ['I', 0],    # loc: 6
  ['I', 1],    # loc: 7
  ['R', 0],    # loc: 8
  ['R', 2],    # loc: 9
  ['R', 2],    # loc: 10
  ['R', 3],    # loc: 11
  ['S', 3],    # loc: 12
  ['S', 3],    # loc: 13
  ['S', 3],    # loc: 14
  ['R', 3],    # loc: 15
  ['I', 0],    # loc: 16
  ['I', 1],    # loc: 17
  ['R', 0],    # loc: 18
  ['R', 2],    # loc: 19
  ['R', 0],    # loc: 20
  ['I', 1],    # loc: 21
  ['R', 0],    # loc: 22
  ['R', 2],    # loc: 23
  ['R', 3],    # loc: 24
  ['S', 3],    # loc: 25
  ['S', 3],    # loc: 26
  ['S', 3],    # loc: 27
  ['R', 3],    # loc: 28
  ['I', 0],    # loc: 29
  ['I', 1],    # loc: 30
  ['R', 0],    # loc: 31
  ['R', 2],    # loc: 32
  ['R', 2],    # loc: 33
  ['R', 3],    # loc: 34
  ['S', 3],    # loc: 35
  ['S', 3],    # loc: 36
  ['S', 3],    # loc: 37
  ['R', 3],    # loc: 38
  ['I', 0],    # loc: 39
  ['I', 1],    # loc: 40
  ['R', 0],    # loc: 41
  ['R', 2],    # loc: 42
  ['R', 0],    # loc: 43
  ['I', 1],    # loc: 44
  ['I', 0],    # loc: 45
  ['I', 0],    # loc: 46
  ['I', 1],    # loc: 47
  ['R', 0]],    # loc: 48
 3)

Tests for Part 2: Adding vaccinated people

This section describes tests for Part 2, which includes vaccinated people. Work through these tests after you have completed Part 1 (Tasks 1-5).

To run the tasks for Part 2, run the following command at the Linux command-line:

$ py.test -xvk run --runvax

Test 0

Description: No one is infected. The simulation stops immediately.

To run this test in ipython3 :

random.seed(0)
city = [('V', 0),    # loc: 0
        ('S', 0),    # loc: 1
        ('S', 0),    # loc: 2
        ('R', 0)]    # loc: 3
sir.run_simulation(city, 3, 0)

Expected result:

([['V', 0],    # loc: 0
  ['S', 0],    # loc: 1
  ['S', 0],    # loc: 2
  ['R', 0]],    # loc: 3
 0)

Test 1

Description: Vaxxed person gets infected on the first.

To run this test in ipython3 :

random.seed(5)
city = [('V', 0),    # loc: 0
        ('I', 0),    # loc: 1
        ('R', 0),    # loc: 2
        ('R', 0)]    # loc: 3
sir.run_simulation(city, 3, 0.8)

Expected result:

([['I', 0],    # loc: 0
  ['I', 1],    # loc: 1
  ['R', 1],    # loc: 2
  ['R', 1]],    # loc: 3
 1)

Test 2

Description: Susceptible person and vaxxed person get infected on the first day. Infected person, recovers

To run this test in ipython3 :

random.seed(5)
city = [('S', 0),    # loc: 0
        ('V', 0),    # loc: 1
        ('I', 0)]    # loc: 2
sir.run_simulation(city, 1, 0.8)

Expected result:

([['I', 0],    # loc: 0
  ['I', 0],    # loc: 1
  ['R', 0]],    # loc: 2
 1)

Test 3

Description: One susceptible person get infected on the first day. The other susceptible and vaxxed person gets infected on the second day

To run this test in ipython3 :

random.seed(10)
city = [('S', 0),    # loc: 0
        ('S', 0),    # loc: 1
        ('I', 0),    # loc: 2
        ('V', 0)]    # loc: 3
sir.run_simulation(city, 3, 0.5)

Expected result:

([['I', 0],    # loc: 0
  ['I', 1],    # loc: 1
  ['I', 2],    # loc: 2
  ['I', 0]],    # loc: 3
 2)

Test 4

Description: One vaxxed person get infected on the first day. The other vaxxed person gets infected on the second day

To run this test in ipython3 :

random.seed(211)
city = [('I', 0),    # loc: 0
        ('S', 0),    # loc: 1
        ('I', 0),    # loc: 2
        ('V', 0),    # loc: 3
        ('V', 1)]    # loc: 4
sir.run_simulation(city, 5, 0.6)

Expected result:

([['I', 2],    # loc: 0
  ['I', 1],    # loc: 1
  ['I', 2],    # loc: 2
  ['I', 1],    # loc: 3
  ['I', 0]],    # loc: 4
 2)

Test 5

Description: Medium city: infection ripples through the city.

To run this test in ipython3 :

random.seed(8)
city = [('I', 0),    # loc: 0
        ('S', 0),    # loc: 1
        ('S', 0),    # loc: 2
        ('S', 1),    # loc: 3
        ('S', 0),    # loc: 4
        ('S', 0),    # loc: 5
        ('S', 0),    # loc: 6
        ('V', 0)]    # loc: 7
sir.run_simulation(city, 3, 0.5)

Expected result:

([['R', 1],    # loc: 0
  ['R', 0],    # loc: 1
  ['I', 2],    # loc: 2
  ['I', 1],    # loc: 3
  ['I', 0],    # loc: 4
  ['I', 1],    # loc: 5
  ['I', 2],    # loc: 6
  ['R', 0]],    # loc: 7
 4)

Test 6

Description: Medium city: infection ripples through the city.

To run this test in ipython3 :

random.seed(17)
city = [('I', 0),    # loc: 0
        ('S', 0),    # loc: 1
        ('S', 0),    # loc: 2
        ('V', 1),    # loc: 3
        ('S', 0),    # loc: 4
        ('S', 0),    # loc: 5
        ('V', 0),    # loc: 6
        ('S', 0)]    # loc: 7
sir.run_simulation(city, 3, 0.3)

Expected result:

([['R', 6],    # loc: 0
  ['R', 5],    # loc: 1
  ['R', 4],    # loc: 2
  ['R', 2],    # loc: 3
  ['R', 1],    # loc: 4
  ['R', 0],    # loc: 5
  ['I', 0],    # loc: 6
  ['R', 5]],    # loc: 7
 9)