TST: Add tests to increase coverage for ksample.py and npc.py files.#221
TST: Add tests to increase coverage for ksample.py and npc.py files.#221aayshahwork wants to merge 2 commits intostatlab:mainfrom
Conversation
test_ksample.py: o Added call to k_sample() with stat as a function, and keep_dist as True. o Verified that it's return has 3 elements, and 3rd element has 1000 entries. o Verified that the value is same as previous/existing result o Added call to bivariate_k_sample() with stat as a function, and keep_dist as True. test_npc.py: o Added variations to test_sim_npc() function. o Also modified the whitespacing for parameters. o Also removed1 unnecessary white space in parameters.
|
Coverage for ksample.py is increased from 73% to 98%; and |
| res = k_sample(worms.x, worms.y, stat='one-way anova', reps=1000, seed=1234) | ||
| np.testing.assert_array_less(0.006, res[0]) | ||
| np.testing.assert_array_less(res[0], 0.02) | ||
| res2 = k_sample(worms.x, worms.y, stat=one_way_anova, reps=1000, keep_dist=True, seed=1234) |
There was a problem hiding this comment.
For testing, I added prints for value of res from line 15 (printed as "Res1:") , and res2 (printed as "Res2:") from line 18. Values show up as following:
Res1: (0.01098901098901099, 17.58271428571427)
Res2: (0.01098901098901099, 17.58271428571427, array([9.28809524e+00, 3.30785714e+00, 1.67714286e-01, 7.86523810e-01,
1.88938095e+00, 1.10714286e-01, 2.46271429e+00, 5.63095238e-01,
5.70752381e+00, 1.53693810e+01, 1.91438095e+00, 7.90309524e+00,
6.19509524e+00, 4.54752381e+00, 4.09342857e+00, 3.04938095e+00,
1.65152381e+00, 1.15303810e+01, 1.31738095e+00, 7.42752381e+00,
4.84538095e+00, 6.41071429e+00, 6.76771429e+00, 4.37800000e+00,
1.02115238e+01, 2.26942857e+00, 1.53510952e+01, 1.22423810e+01,
:
:
So assert added in:
line 19: length is 1000 of array being printed in res2
line 20: res and res2 are same.
line 21: see values of array printed in res2.
Also the 'one_way_anova' method is the default method, so res and res2 have same results.
| assert len(x) == 55 | ||
| res = bivariate_k_sample(x, group1, group2, reps=5000, seed=5) | ||
| np.testing.assert_array_less(res[0], 0.0002) | ||
| res2 = bivariate_k_sample(x, group1, group2, reps=5000, stat=two_way_anova, keep_dist=True, seed=5) |
There was a problem hiding this comment.
For testing, I added prints of res variable (printed as "Res1: ....") and res2 variable (printed as "Res2: .....").
Res1: (0.0001999600079984003, 0.012142004602000753)
Res2: (0.0001999600079984003, 0.012142004602000753, array([0.00314784, 0.00107214, 0.00423246, ..., 0.00011875, 0.00354231,
0.00287068]))
.
Value printed are like above. So the asserts work fine that are added below at:
line 60: length of array is 5000.
line 61: values of res and res2 are same.
line 62: assert also works fine.
Also, the stat method 'two_way_anova' is the default method. So res2 has same result.
| np.testing.assert_almost_equal(res[0], 1) | ||
| res = sim_npc(data, test_array, combine=tippett, in_place=True, seed=None, reps=int(1000)) | ||
| np.testing.assert_almost_equal(res[0], 1) | ||
|
|
There was a problem hiding this comment.
In above code, I added prints for fisher, liptak, tippet combine methods.
So res in line 138 is printed as "Res1:".
res in line 140 is printed as "Res2:".
res in line 142 is printed as "Res3:".
Res1: (1.0, {0: -1.0, 1: -1.0}, {0: 1.0, 1: 1.0})
Res2: (1.0, {0: -1.0, 1: -1.0}, {0: 1.0, 1: 1.0})
Res3: (1.0, {0: -1.0, 1: -1.0}, {0: 1.0, 1: 1.0})
.
Have added the code that I used to print:
print("")
print("Res1: {}".format(res))
np.testing.assert_almost_equal(res[0], 1)
res = sim_npc(data, test_array, combine="liptak", seed=1234, reps=int(1000))
print("Res2: {}".format(res))
np.testing.assert_almost_equal(res[0], 1)
res = sim_npc(data, test_array, combine=tippett, in_place=True, seed=None, reps=int(1000))
print("Res3: {}".format(res))
np.testing.assert_almost_equal(res[0], 1)
| data = Experiment(group, responses, randomizer=my_randomizer) | ||
| res = sim_npc(data, test=Experiment.make_test_array(Experiment.TestFunc.mean_diff, [0, 1]), | ||
| combine="fisher", seed=None, reps=int(1000)) | ||
| np.testing.assert_almost_equal(res[0], 0.985, decimal=2) |
There was a problem hiding this comment.
Only white-space changes in this block of code. No real code change.
| res = sim_npc(data, test=Experiment.make_test_array(Experiment.TestFunc.one_way_anova, [0, 1]), | ||
| combine="fisher", seed=None, reps=int(1000)) | ||
| np.testing.assert_almost_equal(res[0], 0.985, decimal = 2) | ||
| np.testing.assert_almost_equal(res[0], 0.0209, decimal=2) |
There was a problem hiding this comment.
Here, at line 165 - have changed the test function to use 'one_way_anova' method. And I printed the value of 'res' as returned from 'sim_npc()' function.
Res:(0.02097902097902098, {0: 0.5, 1: 0.0}, {0: 0.48151848151848153, 1: 1.0})
Code used to print above value:
res = sim_npc(data, test=Experiment.make_test_array(Experiment.TestFunc.one_way_anova, [0, 1]),
combine="fisher", seed=None, reps=int(1000))
print("")
print("Res:{}".format(res))
np.testing.assert_almost_equal(res[0], 0.0209, decimal=2)
test_ksample.py:
test_npc.py: