1 00:00:07,250 --> 00:00:07,850 All right. 2 00:00:07,850 --> 00:00:13,940 In this lecture, we are going to go over the solution to the little assignment that I assigned at the 3 00:00:13,940 --> 00:00:15,470 end of the previous lecture. 4 00:00:15,650 --> 00:00:22,970 And then we are going to begin implementing our test cases for our directed and undirected graph. 5 00:00:23,780 --> 00:00:34,460 So let's go ahead and add in the solution for the previous little assignment and hopefully that you 6 00:00:34,460 --> 00:00:43,820 notice that it was not too bad and all we had to do was add an an edge from 1 to 0 instead of 0 to 1. 7 00:00:43,820 --> 00:00:46,550 So we will say edge one. 8 00:00:47,700 --> 00:00:55,290 Got to string, and then we want to modify it. 9 00:00:57,540 --> 00:01:11,160 And we will modify our value that we get and we will say e dot push edge 1.2 string excuse me, not 10 00:01:11,160 --> 00:01:11,690 one. 11 00:01:11,700 --> 00:01:18,480 We want to go from 1 to 0 and we need to obviously pass in the same weight. 12 00:01:18,480 --> 00:01:21,570 So we still say edge dot two. 13 00:01:21,600 --> 00:01:24,090 So let's format this to make sure it looks good. 14 00:01:24,480 --> 00:01:28,080 So we're going from 0 to 1 and 1 to 0 here. 15 00:01:28,650 --> 00:01:35,610 So we're just reversing our edge and saying, hey, it is going both ways and that's all we have to 16 00:01:35,610 --> 00:01:38,700 do for that portion. 17 00:01:38,700 --> 00:01:42,020 So let's build, make sure we don't have any little errors. 18 00:01:42,260 --> 00:01:42,840 A righty. 19 00:01:42,840 --> 00:01:44,640 So everything's looking good there. 20 00:01:45,000 --> 00:01:51,690 So what we could do now is start implementing in some of our test cases. 21 00:01:52,950 --> 00:02:06,870 So let's come down here and say config test and we will say mod test, undirected 22 00:02:07,950 --> 00:02:17,310 graph and we will say use super and we'll just bring them all into scope to keep it easy. 23 00:02:18,890 --> 00:02:21,420 So now we are saying that we have a test. 24 00:02:21,440 --> 00:02:27,830 Let me put in my brackets and we want to test out our neighbors. 25 00:02:28,370 --> 00:02:33,890 And this will let us pretty much test everything that we need to test by doing this. 26 00:02:34,070 --> 00:02:40,280 So we will say let mute graph equals undirected graph new. 27 00:02:40,580 --> 00:02:42,470 So this is going to test out our new. 28 00:02:43,290 --> 00:02:45,800 And now we want to add edges. 29 00:02:48,350 --> 00:02:59,210 And we will say are going to have a B and we'll give it a weight of five. 30 00:03:01,130 --> 00:03:03,070 We will do another edge. 31 00:03:03,080 --> 00:03:05,390 We will say B. 32 00:03:08,240 --> 00:03:11,570 See and give it a weight of ten. 33 00:03:13,970 --> 00:03:18,980 And graph adage edge again and we will say. 34 00:03:23,050 --> 00:03:23,860 See. 35 00:03:26,480 --> 00:03:32,510 A and I missed a quotation, so we need to add that in. 36 00:03:32,930 --> 00:03:33,560 All right. 37 00:03:38,540 --> 00:03:40,010 Let's make sure there's not. 38 00:03:40,160 --> 00:03:40,760 Okay. 39 00:03:43,430 --> 00:03:44,000 All right. 40 00:03:44,690 --> 00:03:46,970 So now we can assert equals. 41 00:03:49,640 --> 00:03:56,870 And so with us doing add Edge, if we look at Add Edge, we're actually testing out add node as well. 42 00:03:59,540 --> 00:04:04,460 So this covers all of our methods that we created. 43 00:04:04,460 --> 00:04:14,180 So we want to assert equals that are graph dot neighbors of A and we want to unwrap the value. 44 00:04:14,180 --> 00:04:24,200 That way we can look inside and we want to say make sure that it reference a vector that has a string 45 00:04:25,190 --> 00:04:26,930 from B 46 00:04:29,990 --> 00:04:31,370 as a way to five. 47 00:04:33,470 --> 00:04:35,690 And we also have a 48 00:04:38,390 --> 00:04:42,200 string from C 49 00:04:45,290 --> 00:04:49,670 that has a weight of seven. 50 00:04:54,240 --> 00:04:56,640 And it looks like I need you there. 51 00:04:56,670 --> 00:04:57,330 There we go. 52 00:04:58,020 --> 00:05:00,480 All right, So. 53 00:05:01,380 --> 00:05:02,880 Let's cargo format this. 54 00:05:02,880 --> 00:05:03,510 Make sure everything. 55 00:05:03,570 --> 00:05:03,920 Okay. 56 00:05:03,930 --> 00:05:04,590 There we go. 57 00:05:06,720 --> 00:05:07,890 So yeah, that looks pretty good. 58 00:05:07,890 --> 00:05:15,870 So we're we're seeing what neighbors a has and an undirected graph so a will have a neighbor of B and 59 00:05:15,870 --> 00:05:25,710 then A will also since we're here have a neighbor of C, So if we run cargo test, we supplied three 60 00:05:25,710 --> 00:05:35,850 arguments we need to add in parentheses everywhere here since we are needing to add in a tuple. 61 00:05:39,130 --> 00:05:39,760 There we go. 62 00:05:40,000 --> 00:05:41,440 So now let's run it. 63 00:05:43,030 --> 00:05:45,490 And our test passed successfully. 64 00:05:45,490 --> 00:05:50,500 So all of our methods for our undirected graph looked pretty good. 65 00:05:50,650 --> 00:05:57,040 So what we can do now is test out our directed graph. 66 00:05:57,730 --> 00:06:05,410 So what we'll do is we'll create one more here. 67 00:06:05,410 --> 00:06:15,880 We need to specify that it is a test and we will say test and we'll call this one directed and it's 68 00:06:15,880 --> 00:06:17,650 going to be set up pretty similar. 69 00:06:17,650 --> 00:06:33,910 So we will say let graph equals directed graph new and we will say graph add edge from A to B. 70 00:06:36,410 --> 00:06:38,300 With the weight of five. 71 00:06:40,490 --> 00:06:43,260 And we'll just go ahead and copy in these other two. 72 00:06:44,090 --> 00:06:47,040 That way we're not wasting time typing it. 73 00:06:47,220 --> 00:06:51,590 And we'll actually add one more edge here just to make it a little different. 74 00:06:51,600 --> 00:07:00,030 And we will say from B to A with the weight of five. 75 00:07:00,030 --> 00:07:05,580 So we made this one, this edge go both ways. 76 00:07:07,350 --> 00:07:07,980 All right. 77 00:07:08,520 --> 00:07:22,500 So let's assert equals here to test out that our graphed dot neighbors of a we need to unwrap the value 78 00:07:22,530 --> 00:07:23,190 here 79 00:07:27,960 --> 00:07:31,080 and let's say. 80 00:07:33,270 --> 00:07:48,240 A reference to a vector that contains a string from B with a weight of five. 81 00:07:50,460 --> 00:07:50,820 Right. 82 00:07:50,820 --> 00:08:01,500 This should be our only neighbour for a because we're going from A to B and this will make this will 83 00:08:01,500 --> 00:08:08,970 let us check to make sure that our directed graph is indeed directed because we should not see a number 84 00:08:08,970 --> 00:08:15,870 of C So let's format this to make it pretty. 85 00:08:17,490 --> 00:08:17,940 All right. 86 00:08:17,940 --> 00:08:24,960 So let's run this test now to make sure that it returns true as well. 87 00:08:26,620 --> 00:08:28,330 Test directed returned. 88 00:08:28,330 --> 00:08:30,910 Okay, so we are looking good there. 89 00:08:31,300 --> 00:08:40,180 Let's add in one more test case here, and let's do it from a graph where we check the neighbors of 90 00:08:40,510 --> 00:08:46,090 B and then we need to unwrap our value here. 91 00:08:47,290 --> 00:08:52,710 So with it being B, we should see C and A returned. 92 00:08:52,720 --> 00:09:00,070 So we want to return a vector string from 93 00:09:02,170 --> 00:09:03,190 C. 94 00:09:05,180 --> 00:09:09,260 Which has the weight of ten. 95 00:09:12,970 --> 00:09:16,350 Now I need to add in the parentheses here. 96 00:09:16,360 --> 00:09:17,290 There we go. 97 00:09:17,290 --> 00:09:19,270 And we need a 98 00:09:22,000 --> 00:09:34,910 string from a where we have five and that looks good. 99 00:09:34,930 --> 00:09:37,390 Let's cargo format it to make sure. 100 00:09:37,630 --> 00:09:38,380 All right. 101 00:09:38,380 --> 00:09:40,450 And let's run our test. 102 00:09:40,450 --> 00:09:44,530 And we still see that everything is passing successfully. 103 00:09:44,530 --> 00:09:48,010 So our graph implementation looks good to go. 104 00:09:48,010 --> 00:09:56,260 We are passing all of our test cases, and our test cases are indeed testing our add edge on our undirected 105 00:09:56,260 --> 00:10:02,410 and our directed as well as our neighbors and adding in a node. 106 00:10:02,920 --> 00:10:09,670 So if you have any questions about a graph, please feel free to ask me in the Q&A section and we will 107 00:10:09,670 --> 00:10:17,590 take this knowledge of our graphs and begin implementing in some algorithms such as Dijkstra. 108 00:10:17,590 --> 00:10:22,720 So we have some algorithms to go over starting in the next lecture. 109 00:10:23,370 --> 00:10:25,710 So look forward to seeing you there. 110 00:10:25,710 --> 00:10:31,680 And again, if you have any questions about what we did with our graph implementation, please ask them 111 00:10:31,680 --> 00:10:33,180 in the Q&A section.