def test_check_dist_normal(): sc.heading( 'Testing test_check_dist_normal() (statistical tests for a continuous distribution)...' ) # Normal tests np.random.seed(0) # set random seed for test n = 100 expected = 5 invalid = 15 std = 3 valid_ndata = np.random.randn(n) * std + expected invalid_ndata = np.random.randn(n) * std + invalid alpha = 1e-3 print( f"If any of test_check_dist_normal() tests fail, try to rerun this by resetting the random seed. With alpha: {alpha} we expect 1 out of {1/alpha:.0f} tests to fail." ) sp.check_normal(actual=valid_ndata, expected=expected, alpha=alpha, die=True) with pytest.raises(ValueError): sp.check_normal(actual=invalid_ndata, expected=expected, alpha=alpha, die=True)
def test_student_all_staff_ratio(average_student_all_staff_ratio, do_show, do_save, get_fig_dir, threshold=2): """ Test case to check average_student_all_staff_ratio by taking average of students contacts from teachers and staff Args: average_student_all_staff_ratio: The average number of students per staff members at school (including both teachers and non teachers) Returns: None """ testpars = dict( average_student_all_staff_ratio=average_student_all_staff_ratio, ) pop = sp.Pop(**pars, **testpars) ratios = get_teacher_staff_ratio(pop.popdict, "average_student_all_staff_ratio", average_student_all_staff_ratio, do_show, do_save, get_fig_dir) sp.check_normal(actual=ratios, expected=average_student_all_staff_ratio, label='average_student_all_staff_ratio', check='mean') return
def test_average_student_teacher_ratio(average_student_teacher_ratio, do_show, do_save, get_fig_dir, threshold=2): """ Test case for average_student_teacher_ratio by taking average of student contacts per teacher Args: average_student_teacher_ratio: The average number of students per teacher Returns: None """ testpars = dict( average_student_teacher_ratio=average_student_teacher_ratio, ) pop = sp.Pop(**pars, **testpars) ratios = get_teacher_staff_ratio(pop.popdict, "average_student_teacher_ratio", average_student_teacher_ratio, do_show, do_save, get_fig_dir) sp.check_normal(actual=ratios, expected=average_student_teacher_ratio, label='average_student_teacher_ratio', check='mean') return
def test_average_teacher_teacher_degree(average_teacher_teacher_degree, do_show, do_save, get_fig_dir, threshold=2): """ Test case for average_teacher_teacher_degree by taking average of teachers' contacts per teacher Args: average_teacher_teacher_degree: The average number of contacts per teacher with other teachers Returns: None """ testpars = dict( average_teacher_teacher_degree=average_teacher_teacher_degree, with_school_types=1, school_mixing_type={ 'pk': 'age_and_class_clustered', # average_teacher_teacher_degree will not be used in school_mixing_type == 'random' scenario 'es': 'age_and_class_clustered', 'ms': 'age_and_class_clustered', 'hs': 'age_clustered', 'uv': 'age_clustered' }) pop = sp.Pop(**pars, **testpars) plotting_kwargs = sc.objdict(do_show=do_show, do_save=do_save, figdir=get_fig_dir) contacts = sp.get_contact_counts_by_layer(pop.popdict, with_layer_ids=1)[0] plotting_kwargs.append( "title_prefix", f"Average Teacher-Teacher Degree = {average_teacher_teacher_degree}") plotting_kwargs.append( "figname", f"contact_average_teacher_teacher_degree_{average_teacher_teacher_degree}" ) sp.plot_contact_counts(contacts, **plotting_kwargs) counts = contacts['sc_teacher']['sc_teacher'] sp.check_normal(actual=counts, expected=average_teacher_teacher_degree, label='teacher degree', check='mean') return
def test_average_additional_staff_degree(average_additional_staff_degree, do_show, do_save, get_fig_dir, threshold=2): """ Test case to check average_additional_staff_degree by taking average of all contacts per staff Args: average_additional_staff_degree: The average number of contacts per additional non teaching staff in schools Returns: None """ # note this must be greater than default average_student_all_staff_ratio (20) testpars = dict( average_additional_staff_degree=average_additional_staff_degree, with_school_types=1, ) pop = sp.Pop(**pars, **testpars) plotting_kwargs = sc.objdict(do_show=do_show, do_save=do_save, figdir=get_fig_dir) contacts = sp.get_contact_counts_by_layer(pop.popdict, with_layer_ids=1)[0] plotting_kwargs.append( "title_prefix", f"Average Additional Staff Degree = {average_additional_staff_degree}") plotting_kwargs.append( "figname", f"contact_average_additional_staff_degree_{average_additional_staff_degree}" ) sp.plot_contact_counts(contacts, **plotting_kwargs) counts = contacts['sc_staff']['all'] sp.check_normal(actual=counts, expected=average_additional_staff_degree, label='staff degree', check='mean') return