def test_contains(): generator = IDGenerator(init_val=10) gids = [generator.next() for _ in range(10)] assert(len(gids) == 10) assert(10 in generator) assert(19 in generator) assert(20 not in generator)
def test_remove(): generator = IDGenerator(init_val=101) assert (generator.next() == 101) generator.remove_id(102) generator.remove_id(104) generator.remove_id(106) assert (generator.next() == 103) assert (generator.next() == 105) assert (generator.next() == 107)
def test_call(): generator = IDGenerator() assert (len(generator(100)) == 100) assert (len(generator(N=10)) == 10) assert (isinstance(generator(), int)) with pytest.raises(ValueError): generator(1, 2, 3) with pytest.raises(ValueError): generator(bad_arg=0) with pytest.raises(ValueError): generator(a=0, b=1)
def test_contains(): generator = IDGenerator(init_val=10) gids = [generator.next() for _ in range(10)] assert (len(gids) == 10) assert (10 in generator) assert (19 in generator) assert (20 not in generator) generator.remove_id(54678) assert (54678 in generator) assert (54677 not in generator) assert (54679 not in generator) generator.remove_id(54677) assert (54677 in generator)
def test_node_set(): generator = IDGenerator() node_set = NodeSet(N=100, node_params={ 'p1': range(100), 'p2': range(0, 1000, 100) }, node_type_properties={ 'prop1': 'prop1', 'node_type_id': 1 }) nodes = node_set.build(generator) assert (len(nodes) == 100) assert (nodes[1]['p1'] == 1) assert (nodes[1]['p2'] == 100) assert (nodes[1]['prop1'] == 'prop1') assert (nodes[1]['node_type_id'] == 1)
def test_node(): node_set1 = NodeSet(N=100, node_params={'param1': range(100)}, node_type_properties={ 'prop1': 'prop1', 'node_type_id': 1 }) nodes = node_set1.build(IDGenerator()) node_1 = nodes[0] assert (node_1.node_id == 0) assert (node_1['node_id'] == 0) assert (node_1.node_type_id == 1) assert (node_1['node_type_id'] == 1) assert ('prop1' in node_1.node_type_properties) assert ('param1' in node_1.params) assert ('node_id' in node_1.params) assert ('param1' in node_set1.params_keys) assert (node_1.params_hash == node_set1.params_hash)
def test_node_set(): generator = IDGenerator() node_set = NodeSet(N=100, node_params={ 'p1': range(100), 'p2': range(0, 1000, 100) }, node_type_properties={ 'prop1': 'prop1', 'node_type_id': 1 }) print node_set.N print node_set.node_type_id print node_set.params_keys nodes = node_set.build(generator) print len(nodes) == 100 print nodes[1]['p1'] == 1 print nodes[1]['p2'] == 100 print nodes[1]['prop1'] == 'prop1' print nodes[1]['node_type_id'] == 1
def test_generator(): generator = IDGenerator() assert (generator.next() == 0) assert (generator.next() == 1) assert (generator.next() == 2)
def test_generator_initval(): generator = IDGenerator(101) assert (generator.next() == 101) assert (generator.next() == 102) assert (generator.next() == 103)
def test_get_ids(): generator = IDGenerator() assert (generator.get_ids(1) == [0]) assert (generator.get_ids(size=3) == [1, 2, 3]) assert (generator.get_ids(size=0) == [])