ioftools / networkxMiCe / networkxmaster / networkx / utils / tests / test_random_sequence.py @ 5cef0f13
History  View  Annotate  Download (989 Bytes)
1 
#!/usr/bin/env python


2 
from nose.tools import * 
3 
from networkx.utils import powerlaw_sequence,\ 
4 
zipf_rv, random_weighted_sample,\ 
5 
weighted_choice

6 
import networkx.utils 
7  
8  
9 
def test_degree_sequences(): 
10 
seq = powerlaw_sequence(10, seed=1) 
11 
seq = powerlaw_sequence(10)

12 
assert_equal(len(seq), 10) 
13  
14  
15 
def test_zipf_rv(): 
16 
r = zipf_rv(2.3, xmin=2, seed=1) 
17 
r = zipf_rv(2.3, 2, 1) 
18 
r = zipf_rv(2.3)

19 
assert_true(type(r), int) 
20 
assert_raises(ValueError, zipf_rv, 0.5) 
21 
assert_raises(ValueError, zipf_rv, 2, xmin=0) 
22  
23  
24 
def test_random_weighted_sample(): 
25 
mapping = {'a': 10, 'b': 20} 
26 
s = random_weighted_sample(mapping, 2, seed=1) 
27 
s = random_weighted_sample(mapping, 2)

28 
assert_equal(sorted(s), sorted(mapping.keys())) 
29 
assert_raises(ValueError, random_weighted_sample, mapping, 3) 
30  
31  
32 
def test_random_weighted_choice(): 
33 
mapping = {'a': 10, 'b': 0} 
34 
c = weighted_choice(mapping, seed=1)

35 
c = weighted_choice(mapping) 
36 
assert_equal(c, 'a')
