|
| 1 | +""" |
| 2 | +Unit tests for pymathics.graph.measures_and_metrics |
| 3 | +""" |
| 4 | + |
| 5 | +from test.helper import check_evaluation |
| 6 | + |
| 7 | + |
| 8 | +def test_graph_distance(): |
| 9 | + for str_expr, str_expected, mess in [ |
| 10 | + ( |
| 11 | + "GraphDistance[{1 <-> 2, 2 <-> 3, 3 <-> 4, 2 <-> 4, 4 -> 5}, 1, 5]", |
| 12 | + "3", |
| 13 | + None, |
| 14 | + ), |
| 15 | + ("GraphDistance[{1 <-> 2, 2 <-> 3, 3 <-> 4, 4 -> 2, 4 -> 5}, 1, 5]", "4", None), |
| 16 | + ( |
| 17 | + "GraphDistance[{1 <-> 2, 2 <-> 3, 4 -> 3, 4 -> 2, 4 -> 5}, 1, 5]", |
| 18 | + "Infinity", |
| 19 | + None, |
| 20 | + ), |
| 21 | + ( |
| 22 | + "Sort[GraphDistance[{1 <-> 2, 2 <-> 3, 3 <-> 4, 2 <-> 4, 4 -> 5}, 3]]", |
| 23 | + "{0, 1, 1, 2, 2}", |
| 24 | + None, |
| 25 | + ), |
| 26 | + ( |
| 27 | + "GraphDistance[{}, 1, 1]", |
| 28 | + "GraphDistance[{}, 1, 1]", |
| 29 | + [ |
| 30 | + "The vertex at position 2 in GraphDistance[{}, 1, 1] does not belong to " |
| 31 | + "the graph at position 1." |
| 32 | + ], |
| 33 | + ), |
| 34 | + ( |
| 35 | + "GraphDistance[{1 -> 2}, 3, 4]", |
| 36 | + "GraphDistance[{1 -> 2}, 3, 4]", |
| 37 | + [ |
| 38 | + "The vertex at position 2 in GraphDistance[{1 -> 2}, 3, 4] does not belong " |
| 39 | + "to the graph at position 1." |
| 40 | + ], |
| 41 | + ), |
| 42 | + ]: |
| 43 | + check_evaluation(str_expr, str_expected, expected_messages=mess) |
0 commit comments