1 #!/usr/bin/env python 2 from nose.tools import * 3 from networkx.utils import uniform_sequence,powerlaw_sequence,\ 4 create_degree_sequence,zipf_rv,zipf_sequence,random_weighted_sample,\ 5 weighted_choice 6 import networkx.utils 7 8 def test_degree_sequences(): 9 seq=create_degree_sequence(10,uniform_sequence) 10 assert_equal(len(seq), 10) 11 seq=create_degree_sequence(10,powerlaw_sequence) 12 assert_equal(len(seq), 10) 13 14 def test_zipf_rv(): 15 r = zipf_rv(2.3) 16 assert_true(type(r),int) 17 assert_raises(ValueError,zipf_rv,0.5) 18 assert_raises(ValueError,zipf_rv,2,xmin=0) 19 20 def test_zipf_sequence(): 21 s = zipf_sequence(10) 22 assert_equal(len(s),10) 23 24 def test_random_weighted_sample(): 25 mapping={'a':10,'b':20} 26 s = random_weighted_sample(mapping,2) 27 assert_equal(sorted(s),sorted(mapping.keys())) 28 assert_raises(ValueError,random_weighted_sample,mapping,3) 29 30 def test_random_weighted_choice(): 31 mapping={'a':10,'b':0} 32 c = weighted_choice(mapping) 33 assert_equal(c,'a') 34