|
1 | 1 | import pytest
|
2 | 2 | import os
|
| 3 | +import pandas as pd |
3 | 4 |
|
4 | 5 | import networkx as nx
|
5 | 6 |
|
@@ -448,3 +449,36 @@ def test_get_density_performance(backend):
|
448 | 449 | for i in range(1000 - 1):
|
449 | 450 | G.nx.add_edge(i, i + 1)
|
450 | 451 | assert nx.density(G.nx) <= 0.005
|
| 452 | + |
| 453 | + |
| 454 | +class TestDataFrameBackend: |
| 455 | + |
| 456 | + def test_can_create_empty(self): |
| 457 | + b = DataFrameBackend() |
| 458 | + assert b.get_edge_count() == 0 |
| 459 | + assert b.get_node_count() == 0 |
| 460 | + |
| 461 | + b.add_edge("A", "B", {}) |
| 462 | + assert b.get_edge_count() == 1 |
| 463 | + assert b.get_node_count() == 2 |
| 464 | + |
| 465 | + def test_can_create_from_int_dataframes(self): |
| 466 | + # Create an edges DataFrame |
| 467 | + edges = pd.DataFrame( |
| 468 | + { |
| 469 | + "source": [0, 1, 2, 3, 4], |
| 470 | + "target": [1, 2, 3, 4, 0], |
| 471 | + "weight": [1, 2, 3, 4, 5], |
| 472 | + } |
| 473 | + ) |
| 474 | + |
| 475 | + nodes = pd.DataFrame( |
| 476 | + { |
| 477 | + "name": [0, 1, 2, 3, 4], |
| 478 | + "value": [1, 2, 3, 4, 5], |
| 479 | + } |
| 480 | + ) |
| 481 | + |
| 482 | + b = DataFrameBackend(edge_df=edges, node_df=nodes) |
| 483 | + assert b.get_edge_count() == 5 |
| 484 | + assert b.get_node_count() == 5 |
0 commit comments