def test_assert_crossingmatrix(self): anz_sim = 3 # wealth and religion is unrelated nearliy adj_m1 = adj_m out_dict = ugd.graph_hyp_test(adj_m=adj_m, var_dict=var_dict, test_variable=('wealth', 'rich', 'poor'), anz_sim=anz_sim, show_polt=False, controls=['wealth']) partition = constr_partition(controls=['wealth'], var_dict=var_dict, adj_m=adj_m) adj_m2 = out_dict['graph_list'][anz_sim - 1] _, ins1, outs1 = adj_to_in_out_sequences(adj_m1) _, ins2, outs2 = adj_to_in_out_sequences(adj_m2) crossing_matrix1 = generate_graph(adj_m1, partition, is_directed=False).crossing_matrix crossing_matrix2 = generate_graph(adj_m2, partition, is_directed=False).crossing_matrix assert np.array_equal(crossing_matrix1, crossing_matrix2) and np.array_equal(ins1, ins2)
def test_empty_graph(self): adj_m = np.zeros((4, 4)) with pytest.raises(ValueError) as e_info: _ = ugd.graph_hyp_test(adj_m=adj_m, var_dict=var_dict_1, test_variable=('gender', 'm', 'f'), mixing_time=100, anz_sim=100, show_polt=False)
def test_graph_no_rstrc(self): output_dict= ugd.graph_hyp_test(adj_m=adj_m_1, var_dict=var_dict_1, test_variable=('gender', 'm', 'f'), mixing_time=100, anz_sim=1000, show_polt=False) mue = np.mean(output_dict['stat_list']) true_mean = 0*1/3+ 2/3 * 2 # in this simple case the true mean can be calculated manually true_normalized_numb_graphs_same_as_observed = 1/3 true_quantil_with_50_50_rule = 1/6 assert output_dict["info_dict"]["normalized_numb_graphs_same_as_observed"] > true_normalized_numb_graphs_same_as_observed - 0.15 and output_dict["info_dict"]["normalized_numb_graphs_same_as_observed"] < true_normalized_numb_graphs_same_as_observed + 0.15 assert output_dict["info_dict"]["quantile"] > true_quantil_with_50_50_rule - 0.15 and output_dict["info_dict"]["quantile"] < true_quantil_with_50_50_rule + 0.15 assert mue > true_mean - 0.15 and mue < true_mean + 0.15
def test_matrix_with_vardict(self): _ = ugd.graph_hyp_test(adj_m_1, var_dict=var_dict_1, mixing_time=10) assert True
def test_with_control_misspeled(self): with pytest.raises(ValueError) as e_info: _ = ugd.graph_hyp_test(adj_m=adj_m_1, var_dict=var_dict_1, controls=['genderr'], mixing_time=10)
def test_controlls_in_vardict(self): _ = ugd.graph_hyp_test(adj_m=adj_m_1, var_dict=var_dict_1, stat_f=my_stat, mixing_time=10) assert True
def test__with_only_stat_and_vardict(self): _ = ugd.graph_hyp_test(adj_m=adj_m_1, var_dict=var_dict_1, stat_f=my_stat, mixing_time=10) assert True
def test__with_only_stat(self): _ = ugd.graph_hyp_test(adj_m=adj_m_1, stat_f=my_stat, mixing_time=10) assert True
def test_no_node_with_testvalue2(self): with pytest.raises(ValueError) as e_info: _ = ugd.graph_hyp_test(adj_m=adj_m_1, var_dict=var_dict_1, test_variable=('gender', 'm', 'female'))
def test_spelling_error(self): with pytest.raises(ValueError) as e_info: _ = ugd.graph_hyp_test(adj_m=adj_m_1, var_dict=var_dict_1, test_variable=('genderr', 'm', 'f'))
def test_only_matrix(self): _ = ugd.graph_hyp_test(adj_m_1, mixing_time=10) # should not rise an error assert True