-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathds_test.py
62 lines (43 loc) · 2.39 KB
/
ds_test.py
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
import numpy as np
import pandas as pd
from graph_mate import DiGraph, Graph, Layout
def test_numpy_graph():
el = np.array([[0, 1], [2, 3], [4, 1]], dtype=np.uint32)
g = Graph.from_numpy(el, layout=Layout.Sorted)
assert g.node_count() == 5
assert g.edge_count() == 3
assert np.array_equal(g.neighbors(0), np.array([1], dtype=np.uint32))
assert np.array_equal(g.neighbors(1), np.array([0, 4], dtype=np.uint32))
assert np.array_equal(g.neighbors(2), np.array([3], dtype=np.uint32))
assert np.array_equal(g.neighbors(3), np.array([2], dtype=np.uint32))
assert np.array_equal(g.neighbors(4), np.array([1], dtype=np.uint32))
def test_pandas_graph():
df = pd.DataFrame({"source": [0, 2, 4], "target": [1, 3, 1]})
g = Graph.from_pandas(df, layout=Layout.Sorted)
assert g.node_count() == 5
assert g.edge_count() == 3
assert np.array_equal(g.neighbors(0), np.array([1], dtype=np.uint32))
assert np.array_equal(g.neighbors(1), np.array([0, 4], dtype=np.uint32))
assert np.array_equal(g.neighbors(2), np.array([3], dtype=np.uint32))
assert np.array_equal(g.neighbors(3), np.array([2], dtype=np.uint32))
assert np.array_equal(g.neighbors(4), np.array([1], dtype=np.uint32))
def test_numpy_digraph():
el = np.array([[0, 1], [2, 3], [4, 1]], dtype=np.uint32)
g = DiGraph.from_numpy(el, layout=Layout.Sorted)
assert g.node_count() == 5
assert g.edge_count() == 3
assert np.array_equal(g.out_neighbors(0), np.array([1], dtype=np.uint32))
assert np.array_equal(g.out_neighbors(2), np.array([3], dtype=np.uint32))
assert np.array_equal(g.out_neighbors(4), np.array([1], dtype=np.uint32))
assert np.array_equal(g.in_neighbors(1), np.array([0, 4], dtype=np.uint32))
assert np.array_equal(g.in_neighbors(3), np.array([2], dtype=np.uint32))
def test_pandas_digraph():
df = pd.DataFrame({"source": [0, 2, 4], "target": [1, 3, 1]})
g = DiGraph.from_pandas(df, layout=Layout.Sorted)
assert g.node_count() == 5
assert g.edge_count() == 3
assert np.array_equal(g.out_neighbors(0), np.array([1], dtype=np.uint32))
assert np.array_equal(g.out_neighbors(2), np.array([3], dtype=np.uint32))
assert np.array_equal(g.out_neighbors(4), np.array([1], dtype=np.uint32))
assert np.array_equal(g.in_neighbors(1), np.array([0, 4], dtype=np.uint32))
assert np.array_equal(g.in_neighbors(3), np.array([2], dtype=np.uint32))