|
35 | 35 | import org.junit.jupiter.api.Test;
|
36 | 36 | import com.jgalgo.internal.util.TestBase;
|
37 | 37 | import it.unimi.dsi.fastutil.Pair;
|
| 38 | +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; |
| 39 | +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; |
38 | 40 | import it.unimi.dsi.fastutil.ints.IntArrayList;
|
39 | 41 | import it.unimi.dsi.fastutil.ints.IntArrays;
|
| 42 | +import it.unimi.dsi.fastutil.ints.IntIntPair; |
40 | 43 | import it.unimi.dsi.fastutil.ints.IntList;
|
41 | 44 | import it.unimi.dsi.fastutil.ints.IntSet;
|
42 | 45 | import it.unimi.dsi.fastutil.ints.IntSets;
|
@@ -495,6 +498,30 @@ public void addEdgesReassignIdsInvalidEndpoint() {
|
495 | 498 | });
|
496 | 499 | }
|
497 | 500 |
|
| 501 | + @Test |
| 502 | + public void edgeSourceAndTarget() { |
| 503 | + final Random rand = new Random(0x843e29cab46a15b0L); |
| 504 | + foreachBoolConfig(directed -> { |
| 505 | + IndexGraphBuilderImpl b = new IndexGraphBuilderImpl(directed); |
| 506 | + b.addVertices(range(50)); |
| 507 | + Int2ObjectMap<IntIntPair> edges = new Int2ObjectOpenHashMap<>(); |
| 508 | + for (int i = 0; i < 50; i++) { |
| 509 | + int u = rand.nextInt(50), v = rand.nextInt(50); |
| 510 | + int e = b.addEdge(u, v); |
| 511 | + edges.put(e, IntIntPair.of(u, v)); |
| 512 | + } |
| 513 | + for (int e : b.edges()) { |
| 514 | + IntIntPair endpoints = edges.get(e); |
| 515 | + assertEquals(endpoints.firstInt(), b.edgeSource(e)); |
| 516 | + assertEquals(endpoints.secondInt(), b.edgeTarget(e)); |
| 517 | + } |
| 518 | + for (int repeat = 0; repeat < 5; repeat++) |
| 519 | + assertThrows(NoSuchEdgeException.class, () -> b.edgeSource(b.edges().size() + rand.nextInt(10))); |
| 520 | + for (int repeat = 0; repeat < 5; repeat++) |
| 521 | + assertThrows(NoSuchEdgeException.class, () -> b.edgeTarget(b.edges().size() + rand.nextInt(10))); |
| 522 | + }); |
| 523 | + } |
| 524 | + |
498 | 525 | @Test
|
499 | 526 | public void clear() {
|
500 | 527 | foreachBoolConfig(directed -> {
|
|
0 commit comments