def test_finding_totals(): rab = Rabbit() assert rab.males == 1 assert rab.females == 1 rab.list.append({'Males': 2, 'Females': 1}) rab.calc_gender_totals() assert rab.males == 3 assert rab.females == 2
def test_assign_gender(): roger = Rabbit() # Given inputs for testing roger.list = [{'Males': 1, 'Females': 1}, {'Males': 0, 'Females': 0}, {'Males': 0, 'Females': 0}, {'Males': 2, 'Females': 3}, {'Males': 0, 'Females': 0}] roger.new_babies = 12 roger.assign_genders() # Test to ensure previous data has not been modified assert roger.list[0:-1] == [{'Males': 1, 'Females': 1}, {'Males': 0, 'Females': 0}, {'Males': 0, 'Females': 0}, {'Males': 2, 'Females': 3}, {'Males': 0, 'Females': 0}] # Tests to check assigned genders are equal to number of babies assert 0 <= roger.list[-1]['Males'] <= 12 assert roger.list[-1]['Males'] + roger.list[-1]['Females'] == 12 # Tests to ensure that outputs are not none roger.assign_genders() assert roger.list[-1]['Males'] is not None assert roger.list[-1]['Females'] is not None
def test_birth_children(): test = Rabbit() assert test.pregnancies == [ 0, 1 ] # Assert assumes that variable is already set as that number test.birth_children() assert test.new_babies == 0 test.pregnancies = [0, 5] test.birth_children() assert test.new_babies == 0 test.pregnancies = [7, 0] test.birth_children() assert 7 <= test.new_babies <= 98 test.pregnancies = [10, 8] test.birth_children() assert 10 <= test.new_babies <= 140
def test_calculate_total_pop(): r = Rabbit() r.list = r.init_list() assert r.calculate_total_pop() == 2 r.list = [{"Males": 0, "Females": 0}] assert r.calculate_total_pop() == 0 r.list = [{"Males": 1, "Females": 1}] assert r.calculate_total_pop() == 2 r.list = [{"Males": 10, "Females": 9}, {"Males": 17, "Females": 22}] assert r.calculate_total_pop() == 58
from rabbit_project.classes.rabbit import Rabbit from scipy import stats test = Rabbit() def test_pregnant_rabbits(): <<<<<<< HEAD:rabbit_project/tests/test_pregnant_rabbits.py assert test.males == 1 assert test.females == 1 assert test.pregnancies == [0, 1] assert stats.binom_test(test.pregnancies, test.females, 0.5, 'two-sided') ======= test.pregnant_rabbits() assert test.pregnancies == [0, 1, 0] test.males = 60 test.females = 60 test.list = [] for each in range(0, 60): test.list.append({"Males": 1, "Females": 1}) test.pregnancies = [0, 0] test.pregnant_rabbits() assert test.pregnancies == [0, 0, 58] test.males = 60 test.females = 600 test.list = [] for each in range(0, 60): test.list.append({"Males": 1, "Females": 10}) test.pregnancies = [0, 0]
import time as t from rabbit_project.classes.rabbit import Rabbit rabbit_population_model = Rabbit() def time_passing(final_month): month = 1 while month <= final_month: print(f"We are in month {month}") rabbit_one_month() print(f"Population: {rabbit_population_model.total_population}") print(f"Deaths: {rabbit_population_model.deaths_total}") print(f"Males: {rabbit_population_model.males}") print(f"Females: {rabbit_population_model.females}\n") t.sleep(1) month += 1 def rabbit_one_month(): rabbit_population_model.pregnant_rabbits() rabbit_population_model.birth_children() rabbit_population_model.assign_genders() rabbit_population_model.calc_gender_totals() rabbit_population_model.rabbits_dead() rabbit_population_model.calculate_total_pop()
def test_initial_breeding_pair(): rab = Rabbit() assert rab.males == 1 assert rab.females == 1
from rabbit_project.classes.rabbit import Rabbit test = Rabbit() def test_rabbits_dead(): assert test.list == test.init_list() test.rabbits_dead() assert test.deaths_total == 0 # Checking deaths from initial list test.list = [] for i in range(0, 60): test.list.append({"Males": 3, "Females": 9}) test.rabbits_dead() assert test.deaths_total == 12 # Checking total deaths from a made up list assert len( test.list) == 59 # Checking the list has been shortened by 1 element test.list = [] for i in range(0, 60): test.list.append({"Males": 0, "Females": 4}) test.rabbits_dead() assert test.deaths_total == 16 # Checking total deaths when added on previous total deaths