diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /python/altgraph/altgraph_tests/test_graphstat.py | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'python/altgraph/altgraph_tests/test_graphstat.py')
-rw-r--r-- | python/altgraph/altgraph_tests/test_graphstat.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/python/altgraph/altgraph_tests/test_graphstat.py b/python/altgraph/altgraph_tests/test_graphstat.py new file mode 100644 index 000000000..b628b6f24 --- /dev/null +++ b/python/altgraph/altgraph_tests/test_graphstat.py @@ -0,0 +1,70 @@ +import unittest + +from altgraph import GraphStat +from altgraph import Graph +import sys + +class TestDegreesDist (unittest.TestCase): + + def test_simple(self): + a = Graph.Graph() + self.assertEqual(GraphStat.degree_dist(a), []) + + a.add_node(1) + a.add_node(2) + a.add_node(3) + + self.assertEqual(GraphStat.degree_dist(a), GraphStat._binning([0, 0, 0])) + + for x in range(100): + a.add_node(x) + + for x in range(1, 100): + for y in range(1, 50): + if x % y == 0: + a.add_edge(x, y) + + counts_inc = [] + counts_out = [] + for n in a: + counts_inc.append(a.inc_degree(n)) + counts_out.append(a.out_degree(n)) + + self.assertEqual(GraphStat.degree_dist(a), GraphStat._binning(counts_out)) + self.assertEqual(GraphStat.degree_dist(a, mode='inc'), GraphStat._binning(counts_inc)) + +class TestBinning (unittest.TestCase): + def test_simple(self): + + # Binning [0, 100) into 10 bins + a = list(range(100)) + out = GraphStat._binning(a, limits=(0, 100), bin_num=10) + + self.assertEqual(out, + [ (x*1.0, 10) for x in range(5, 100, 10) ]) + + + # Check that outliers are ignored. + a = list(range(100)) + out = GraphStat._binning(a, limits=(0, 90), bin_num=9) + + self.assertEqual(out, + [ (x*1.0, 10) for x in range(5, 90, 10) ]) + + + out = GraphStat._binning(a, limits=(0, 100), bin_num=15) + binSize = 100 / 15.0 + result = [0]*15 + for i in range(100): + bin = int(i/binSize) + try: + result[bin] += 1 + except IndexError: + pass + + result = [ (i * binSize + binSize/2, result[i]) for i in range(len(result))] + + self.assertEqual(result, out) + +if __name__ == "__main__": # pragma: no cover + unittest.main() |