-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_edgelist_sparse6.py
More file actions
161 lines (108 loc) · 4.8 KB
/
Copy pathtest_edgelist_sparse6.py
File metadata and controls
161 lines (108 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import pytest
from jgrapht import create_graph
from jgrapht.io.edgelist import (
parse_edgelist_graph6sparse6,
read_edgelist_graph6sparse6,
)
def test_input_sparse6_from_file(tmpdir):
tmpfile = tmpdir.join("sparse6.out")
tmpfilename = str(tmpfile)
# write file json with escaped characters
with open(tmpfilename, "w") as f:
f.write(":Cca")
edgelist = read_edgelist_graph6sparse6(tmpfilename)
assert list(edgelist) == [('0', '1', 1.0), ('0', '2', 1.0), ('0', '3', 1.0), ('2', '3', 1.0)]
def test_input_sparse6_with_attrs_from_file(tmpdir):
tmpfile = tmpdir.join("sparse6.out")
tmpfilename = str(tmpfile)
# write file json with escaped characters
with open(tmpfilename, "w") as f:
f.write(":Cca")
v_attrs = dict()
e_attrs = dict()
# test that you read back unescaped
def va_cb(vertex, attribute_name, attribute_value):
if vertex not in v_attrs:
v_attrs[vertex] = {}
v_attrs[vertex][attribute_name] = attribute_value
def ea_cb(edge, attribute_name, attribute_value):
if edge not in e_attrs:
e_attrs[edge] = {}
e_attrs[edge][attribute_name] = attribute_value
edgelist = read_edgelist_graph6sparse6(tmpfilename, vertex_attribute_cb=va_cb, edge_attribute_cb=ea_cb)
assert list(edgelist) == [('0', '1', 1.0), ('0', '2', 1.0), ('0', '3', 1.0), ('2', '3', 1.0)]
assert v_attrs == {}
assert e_attrs == {}
def test_input_sparse6_from_string_with_attrs(tmpdir):
v_attrs = dict()
e_attrs = dict()
# test that you read back unescaped
def va_cb(vertex, attribute_name, attribute_value):
if vertex not in v_attrs:
v_attrs[vertex] = {}
v_attrs[vertex][attribute_name] = attribute_value
def ea_cb(edge, attribute_name, attribute_value):
if edge not in e_attrs:
e_attrs[edge] = {}
e_attrs[edge][attribute_name] = attribute_value
edgelist = parse_edgelist_graph6sparse6(":Cca", vertex_attribute_cb=va_cb, edge_attribute_cb=ea_cb)
assert list(edgelist) == [('0', '1', 1.0), ('0', '2', 1.0), ('0', '3', 1.0), ('2', '3', 1.0)]
assert v_attrs == {}
assert e_attrs == {}
def test_input_sparse6_from_string(tmpdir):
edgelist = parse_edgelist_graph6sparse6(":Cca")
print(edgelist)
assert list(edgelist) == [('0', '1', 1.0), ('0', '2', 1.0), ('0', '3', 1.0), ('2', '3', 1.0)]
def test_input_graph6_from_file(tmpdir):
tmpfile = tmpdir.join("graph6.out")
tmpfilename = str(tmpfile)
# write file json with escaped characters
with open(tmpfilename, "w") as f:
f.write("Ct")
edgelist = read_edgelist_graph6sparse6(tmpfilename)
assert list(edgelist) == [('1', '0', 1.0), ('2', '0', 1.0), ('3', '0', 1.0), ('3', '2', 1.0)]
def test_input_graph6_with_attrs_from_file(tmpdir):
tmpfile = tmpdir.join("graph6.out")
tmpfilename = str(tmpfile)
# write file json with escaped characters
with open(tmpfilename, "w") as f:
f.write("Ct")
v_attrs = dict()
e_attrs = dict()
# test that you read back unescaped
def va_cb(vertex, attribute_name, attribute_value):
if vertex not in v_attrs:
v_attrs[vertex] = {}
v_attrs[vertex][attribute_name] = attribute_value
def ea_cb(edge, attribute_name, attribute_value):
if edge not in e_attrs:
e_attrs[edge] = {}
e_attrs[edge][attribute_name] = attribute_value
edgelist = read_edgelist_graph6sparse6(tmpfilename, vertex_attribute_cb=va_cb, edge_attribute_cb=ea_cb)
assert list(edgelist) == [('1', '0', 1.0), ('2', '0', 1.0), ('3', '0', 1.0), ('3', '2', 1.0)]
assert v_attrs == {}
assert e_attrs == {}
def test_input_graph6_from_string_with_attrs(tmpdir):
v_attrs = dict()
e_attrs = dict()
# test that you read back unescaped
def va_cb(vertex, attribute_name, attribute_value):
if vertex not in v_attrs:
v_attrs[vertex] = {}
v_attrs[vertex][attribute_name] = attribute_value
def ea_cb(edge, attribute_name, attribute_value):
if edge not in e_attrs:
e_attrs[edge] = {}
e_attrs[edge][attribute_name] = attribute_value
edgelist = parse_edgelist_graph6sparse6("Ct", vertex_attribute_cb=va_cb, edge_attribute_cb=ea_cb)
assert list(edgelist) == [('1', '0', 1.0), ('2', '0', 1.0), ('3', '0', 1.0), ('3', '2', 1.0)]
assert v_attrs == {}
assert e_attrs == {}
def test_input_graph6_from_string(tmpdir):
edgelist = parse_edgelist_graph6sparse6("Ct")
print(edgelist)
assert list(edgelist) == [('1', '0', 1.0), ('2', '0', 1.0), ('3', '0', 1.0), ('3', '2', 1.0)]
def test_input_graph6_no_import_cb(tmpdir):
edgelist = parse_edgelist_graph6sparse6("Ct")
print(edgelist)
assert list(edgelist) == [('1', '0', 1.0), ('2', '0', 1.0), ('3', '0', 1.0), ('3', '2', 1.0)]