Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: Add tests to increase coverage for ksample.py and npc.py files. #221

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aayshahwork
Copy link

test_ksample.py:

  • Added call to k_sample() with stat as a function, and keep_dist as True.
  • Verified that it's return has 3 elements, and 3rd element has 1000 entries.
  • Verified that the value is same as previous/existing result
  • Added call to bivariate_k_sample() with stat as a function, and keep_dist as True.

test_npc.py:

  • Added variations to test_sim_npc() function.
  • Also modified the whitespacing for parameters.

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.
@aayshahwork
Copy link
Author

Coverage for ksample.py is increased from 73% to 98%; and
Coverage for npc.py is increased from 73% to 88%.

@@ -15,6 +15,10 @@ def test_worms_ksample():
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)
Copy link
Author

@aayshahwork aayshahwork Jul 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -52,3 +56,7 @@ def test_testosterone_ksample():
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)
Copy link
Author

@aayshahwork aayshahwork Jul 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only white-space changes in this block of code. No real code change.

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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant