Skip to content

Commit

Permalink
Make tests more robust and increment version
Browse files Browse the repository at this point in the history
  • Loading branch information
ragibson committed Apr 23, 2022
1 parent 433c261 commit 6eda086
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='modularitypruning',
version='1.1.3',
version='1.2.0',
package_dir={'modularitypruning': 'utilities'},
packages=['modularitypruning'],
url='https://github.com/ragibson/ModularityPruning',
Expand Down
10 changes: 10 additions & 0 deletions tests/shared_testing_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import igraph as ig
from math import isnan
from modularitypruning.partition_utilities import num_communities
from random import randint, random, uniform

Expand Down Expand Up @@ -87,3 +88,12 @@ def generate_multilayer_intralayer_SBM(copying_probability, p_in, p_out, first_l
G_intralayer = ig.Graph(intralayer_edges, directed=False)

return G_intralayer, layer_membership


def assert_almost_equal_or_both_none_or_nan(self, first, second, places=10):
if first is None:
self.assertIsNone(second) # isnan only accepts floats
elif isnan(first):
self.assertTrue(isnan(second)) # NaN is != NaN according to IEEE-754
else:
self.assertAlmostEqual(first, second, places=places)
4 changes: 2 additions & 2 deletions tests/test_monolayer_parameter_estimation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .shared_testing_functions import generate_igraph_famous, generate_random_partition
from .shared_testing_functions import assert_almost_equal_or_both_none_or_nan, generate_igraph_famous, generate_random_partition
import igraph as ig
from math import log
from numpy import mean
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_directed_consistency_igraph_famous(self):
G.to_directed()
gamma_directed = gamma_estimate(G, random_membership)

self.assertAlmostEqual(gamma_undirected, gamma_directed, places=10)
assert_almost_equal_or_both_none_or_nan(self, gamma_undirected, gamma_directed, places=10)


if __name__ == "__main__":
Expand Down
7 changes: 4 additions & 3 deletions tests/test_multiplex_parameter_estimation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .shared_testing_functions import generate_random_partition, generate_multilayer_intralayer_SBM
from .shared_testing_functions import assert_almost_equal_or_both_none_or_nan, generate_random_partition, \
generate_multilayer_intralayer_SBM
import igraph as ig
from math import log
from numpy import mean
Expand Down Expand Up @@ -109,8 +110,8 @@ def test_directed_consistency_multiplex_SBM_louvain(self):
gamma_directed, omega_directed = gamma_omega_estimate(G_intralayer, G_interlayer, layer_membership,
partition, model="multiplex")

self.assertAlmostEqual(gamma_undirected, gamma_directed, places=10)
self.assertAlmostEqual(omega_undirected, omega_directed, places=10)
assert_almost_equal_or_both_none_or_nan(self, gamma_undirected, gamma_directed, places=10)
assert_almost_equal_or_both_none_or_nan(self, omega_undirected, omega_directed, places=10)


if __name__ == "__main__":
Expand Down
11 changes: 6 additions & 5 deletions tests/test_temporal_multilevel_parameter_estimation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .shared_testing_functions import generate_random_partition, generate_multilayer_intralayer_SBM
from .shared_testing_functions import assert_almost_equal_or_both_none_or_nan, generate_random_partition, \
generate_multilayer_intralayer_SBM
import igraph as ig
from math import log
from numpy import mean
Expand Down Expand Up @@ -112,8 +113,8 @@ def test_directed_consistency_temporal_SBM_louvain(self):
gamma_directed, omega_directed = gamma_omega_estimate(G_intralayer, G_interlayer, layer_membership,
partition, model="temporal")

self.assertAlmostEqual(gamma_undirected, gamma_directed, places=10)
self.assertAlmostEqual(omega_undirected, omega_directed, places=10)
assert_almost_equal_or_both_none_or_nan(self, gamma_undirected, gamma_directed, places=10)
assert_almost_equal_or_both_none_or_nan(self, omega_undirected, omega_directed, places=10)

# check multilevel parameter estimation as well
gamma_undirected, omega_undirected = gamma_omega_estimate(G_intralayer, G_interlayer, layer_membership,
Expand All @@ -123,8 +124,8 @@ def test_directed_consistency_temporal_SBM_louvain(self):
gamma_directed, omega_directed = gamma_omega_estimate(G_intralayer, G_interlayer, layer_membership,
partition, model="multilevel")

self.assertAlmostEqual(gamma_undirected, gamma_directed, places=10)
self.assertAlmostEqual(omega_undirected, omega_directed, places=10)
assert_almost_equal_or_both_none_or_nan(self, gamma_undirected, gamma_directed, places=10)
assert_almost_equal_or_both_none_or_nan(self, omega_undirected, omega_directed, places=10)


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion utilities/champ_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
membership_to_layered_communities
from collections import defaultdict
import numpy as np
from numpy import VisibleDeprecationWarning
from numpy.random import choice
from math import floor
from multiprocessing import Pool, cpu_count
Expand Down

0 comments on commit 6eda086

Please sign in to comment.