1+ package com .thealgorithms .graphs ;
2+
13import java .util .Map ;
24import java .util .List ;
35import java .util .HashMap ;
46import java .util .Arrays ;
57
8+ import org .junit .Test ;
9+ import static org .junit .Assert .*;
10+
611/**
7- * Simple test for BidirectionalBFS.
12+ * Unit tests for BidirectionalBFS.
813 */
914public class BidirectionalBFSTest
1015{
11- public static void main (String [] args )
16+ @ Test
17+ public void testPathExists ()
1218 {
1319 Map <Integer , List <Integer >> graph = new HashMap <>();
1420 graph .put (0 , Arrays .asList (1 , 2 ));
@@ -18,12 +24,19 @@ public static void main(String[] args)
1824 graph .put (4 , Arrays .asList (2 , 5 ));
1925 graph .put (5 , Arrays .asList (3 , 4 ));
2026
21- // Test 1
22- boolean result1 = BidirectionalBFS .bidirectionalBFS (graph , 0 , 5 );
23- System .out .println ("Path 0->5 exists: " + result1 ); // true
27+ assertTrue (BidirectionalBFS .bidirectionalBFS (graph , 0 , 5 ));
28+ }
2429
25- // Test 2
26- boolean result2 = BidirectionalBFS .bidirectionalBFS (graph , 0 , 6 );
27- System .out .println ("Path 0->6 exists: " + result2 ); // false
30+ @ Test
31+ public void testPathDoesNotExist ()
32+ {
33+ Map <Integer , List <Integer >> graph = new HashMap <>();
34+ graph .put (0 , Arrays .asList (1 ));
35+ graph .put (1 , Arrays .asList (0 ));
36+ // node 2 is isolated
37+ graph .put (2 , Arrays .asList ());
38+
39+ assertFalse (BidirectionalBFS .bidirectionalBFS (graph , 0 , 2 ));
2840 }
2941}
42+
0 commit comments