Lesson 6 of 11
Total Noob Fail
In this lesson
Session six starts with five tests failing on one machine but passing on Raymond Lim's, caused by line breaks in a string the test code splits. The first cell strategy, which really returned the last cell, becomes a strategy that counts each color's cells, and a planted bug shows the new test can fail. After removing the assumption that the surrounding color is white, work on two connected stones ends with finding X and Y swapped in the test's fill board helper.
Transcript
[00:05] (external link, opens in new tab) Hello everyone and welcome back to session number six. Here I am with Raymond Lim and this time we've decided to do something just a bit different. We're running our tests. We're we moved things to my machine and this time something weird is happening right now is that we have five tests failing on my machine but getting the same version the latest version of the source code on Raymond's machine seems to run all the tests and they're passing. So we've just decided to start debugging one of the tests just to figure out what's going on.
[00:35] (external link, opens in new tab) We we thought maybe we should just record this and u see where this leads. So, I'm just debugging the first cell winner strategy here to see what's going on. Raymond, I'm guessing so far you have no idea as much as I am what the hell is going on, right? >> Yep. No idea. >> so we're surrounded by surrounded by And here it's just just going through and going through.
[01:06] (external link, opens in new tab) So when you look at the get winner on your machine, do you see anything different from this code? >> let me take a look. >> The test as well. Maybe the test is different. Did you by any chance tab all the tests without running them? >> No, I ran them. I just ran them right now too. So,
[01:37] (external link, opens in new tab) Is that trimming? And there's a trimming going on here. What the hell? Covered by night and five failing tests. Execution time per test is zero. So, it's interesting that this isn't covered by the tests. So the failing tests are they're all about determine winner and add stone to empty position position is filled.
[02:07] (external link, opens in new tab) That's like the most basic thing. >> You see this right here, >> right? This one's failing. >> Yeah. Interesting. So this is the most basic thing. >> Check it out. >> With debugger
[02:41] (external link, opens in new tab) Position status turn position status matrix. Yeah. What is position status matrix in this case? They're all empty. fill board. I guess fill board is the culprit here because it's not filling out things here.
[03:30] (external link, opens in new tab) So, I'm not sure. Let's see. Beat that for a second.
[04:02] (external link, opens in new tab) Now there are still no lines. That's the problem here is that the split on my machine. Hey, you know what's going on? I think you want to >> Did you >> did you accidentally edit it? >> Yeah, I think I'm figuring it out. So, here's a thought. You know what? I think the local on my machine is messing up with the strings and the >> slash r/n thing. >> Yeah. So, what's the local on your machine? >> I don't know. I never looked that up before. I'm guessing US American
[04:34] (external link, opens in new tab) >> local. What's the local on my machine? Format is US. Location United States. Additional pretty sure there's a regional regional. You don't have any like anything special going on? >> No, I I don't have anything special. region.
[05:05] (external link, opens in new tab) >> Maybe it might be the git GitHub thing pushing up, pulling down might give a No. Yeah, maybe it's probably your machine. So on my machine there are no SLRs. On your machine there are >> Yeah, >> that's interesting. That makes sense though. if there if if if our machines are the same. I mean, can you can you open your regional settings and tell me what what things look like on your end?
[05:47] (external link, opens in new tab) Everything looks the same so far. Yeah. United States settings. >> language for nonuni code programs is English. >> maybe that's the difference. But what about additional settings about numbers, decimal symbols, currency, time, date.
[06:20] (external link, opens in new tab) So this is the point where I would go and say C sharp string slash R not found something like that. Maybe slash are using strings custom numeric formats
[06:55] (external link, opens in new tab) Slash and slash r. So we went all line breaks in a string place line breaks through the stapes string literal character classes. Yeah, there's something about the strings here that makes those things not run on my machine. So we have to get rid of it. >> Mhm. >> So I'm trying to understand what it is. Now there is a name for the strings that start with this. They're are they called literal strings? What's the name of that?
[07:29] (external link, opens in new tab) >> I don't remember. >> Sharp. Line breaks. Literal strings. Not sure if that's the name. Oh, string literal. Yeah, multi-line string literal. Is there an easy way to create a multi-line string literal? Yeah, blah blah blah. Yeah, that's the we don't have to escape special characters. It's verbatim string though with the sign verb
[08:05] (external link, opens in new tab) String new line slash r slashn c that's interesting. I'm I mean I'm kind of stumped here on what is to be done to solve this problem, >> right? We could go the
[08:40] (external link, opens in new tab) The route where we would split two times like to check if there's a slash r or slashn because you can see there's only slashn here. Now when you debug in your part on your end do you see slash ends or slash ends and slash rs in this same line. >> Oh okay let me try that. >> This is from the same test
[09:13] (external link, opens in new tab) The add stone to empty position. >> Okay. You just highlight it on the split. Mine says slash r/n >> after the after after the numbers. >> Yeah. >> Wow. >> Yeah. Mine mine says slash r slashn. >> Maybe it's a different Visual Studio version.
[09:44] (external link, opens in new tab) I mean, what version of Visual Studio are you running? >> I think professional. Is it >> is it 2010? Yeah, it's 2010. >> It's probably I think mine is ultimate. So ultimate parses string better obviously. >> Not sure. I have no idea. Okay. So we can you know what? I'm just going to go to brute force now. I don't want to deal with this too much. So I'm just going to say
[10:15] (external link, opens in new tab) If >> mine is ultimate also. >> H So, sometimes it is, sometimes it isn't. Is that what you mean? >> Maybe. How about you just split it first by slash r slashn and then and then split it again. Oh god, feels so dirty.
[10:49] (external link, opens in new tab) This >> I wonder would that work on your machine though? I can try right now. >> You can try right now. Right. >> Yeah. Or split. I think it just takes all these literals anyway. But I think on your machine won't work because >> it still passes for me. >> Still passes. >> Yep. Yep.
[11:19] (external link, opens in new tab) So, we don't need a slash R at all. >> Oh. Oh, I didn't try it without the slash R. Let me try it without the slash R. >> Yeah, still passes for me. >> Yeah, that makes sense because we trim everything anyway. More lines. So, okay. >> So, just change it slash in. >> Sorry. >> Cool. Yeah. So, I agree with you. Just change it to slash in. >> interesting. NCrunch disable and NCrunch enable.
[11:53] (external link, opens in new tab) >> Oh, it's not passing for you anymore. >> It is, but it's not. It seems like it's not running. Seems like it's not running the test. >> Oh, it's probably because it doesn't considered it changed. Maybe. >> Whatever. At least we can continue now. >> Sweet. Okay, so in our last episode we created the DSL (external link, opens in new tab) and now we have the tests on the left and the production code on the right.
[12:26] (external link, opens in new tab) So what we can do is to basically I don't know just try to continue. >> Yes. >> Yes, please. Well, >> the thing is that we we're running into that test case that's passing but we're expecting to fail. the last two test case we added. >> yeah, and you said that you found out the reason why. >> Yeah. So the reason why was because we changed the behavior of the first cell strategy.
[13:00] (external link, opens in new tab) So if you look at the code for that, it's actually returning the last cell found as the winner instead of first cell found as the winner. So if we go to first cell strategy we should rename it to last cell based on >> Yeah. >> this. >> Right. >> So let's rename it
[13:31] (external link, opens in new tab) Last. So winner strategy. >> Okay. And to make the test fail, you can just switch the Hold on. Where's my mouse? This one with this one. I don't know if you can see my mouse. >> Mosquito. Sorry. >> You were saying >> you can switch this one with this one like the right side and the left side. >> Let's create another test that recreates that. >> Okay.
[14:07] (external link, opens in new tab) And rename it determine winner. And what's the difference? How would you name it differently? >> black owns last cell found. I don't know. I don't want to kind of the thing I feel like putting that will I don't put kind of put the strategy into it, right? We don't really want to put the the the implementation details into No, but we do want to make sure that the order >> of winning doesn't matter of owning. >> Okay. Sure.
[14:38] (external link, opens in new tab) >> So, it's it is about order. So, how would you rename it? >> Black owns one cell, white owns two cells, and black goes last. >> Sure. >> Yeah. And the difference is what would you change here? >> So I would change >> go ahead and change it. >> All right.
[15:31] (external link, opens in new tab) All right, there we go. >> Okay. Maybe we should do it this way, actually. How do I think about it? Is there a way to move right on to the side? Never mind. Okay. Okay. So, how would you fix this? >> So, I would change the last winner strategy.
[16:03] (external link, opens in new tab) >> Yeah. instead to returning the last winner, you would instead count you have a count for each stone color and then you return the one with the greater greater count. >> So we need to start counting. >> Yeah. >> Okay. So maybe.
[16:36] (external link, opens in new tab) Okay. So, what's the simplest solution (external link, opens in new tab) that can make this everything pass? Do you have anything in mind? >> so just in declare two variables like white white stones, white territories, black territories and both set them to zero. And here we just >> like increment it.
[17:06] (external link, opens in new tab) Yeah. >> okay. So, white cells++ and here we would say sorry black cells plus+ and >> and then yeah so it's kind of like if they're equal to each other return empty else return the bigger one.
[17:39] (external link, opens in new tab) What's the simplest that will make everything pass right now? Is there anything simpler? Like yeah, if >> white is greater than black, return white. See? Oh, that didn't work yet.
[18:10] (external link, opens in new tab) Turn black. Oh yeah, that's why. Okay, still didn't make it past. >> So actually instead copy in for add another if statement if black is greater than white. And just change it. Yeah, black greater than white. And then for the last one, return stone.
[18:48] (external link, opens in new tab) >> Interesting. So, what's failing right now is you can see here covered by six passing and one failing test. Black owns two cells, white owns one cell. This is the one that's failing right now. >> Okay. Could you go look at the test? I want to check if the test is correct. >> And what was the filler message? >> The what? >> What was the failure message?
[19:19] (external link, opens in new tab) >> Oh, you can see it here. Expected black but was white. >> H. So, I'm thinking maybe we're not using the thing here, the strategy. So, we can say test with debugger.
[19:50] (external link, opens in new tab) Step into this, go into rules, go into the result. The result here is empty. Okay, >> But black should have two, white should have one. Unless we're not counting the winners correctly. >> Oh, that's not what we meant to have. This one.
[20:23] (external link, opens in new tab) Yeah, sure. And here, white cells. So we would have I'm just going to go through and say right here white cells black cells too. So we have the same number. >> Wow. >> Should we have the same number here in this test? >> No, we shouldn't. There should be only one white, two black. >> Okay. So you want you want to go back to the loop and step through it. Like check two two
[20:57] (external link, opens in new tab) Actually. Just put break points inside the if >> inside the if statements. And >> sure. >> >> just going to go here and say >> well you can just move the the arrow up to the >> top right there. Yeah. >> Okay. So we have white cells here. >> that's one. >> Okay. I see why now.
[21:28] (external link, opens in new tab) >> What? Because there there is there is a white cell right here. >> But in black but black should have three then I should know that this is two of them. I see. Okay. So white does have two. So there's something wrong with our test. So we just need to move everything aside by one and then that should pass. >> Awesome. >> Very cool. Found a problem with our test. >> It would have been much harder to find if this wasn't visual. >> Yeah. If if we didn't have the DSL.
[22:00] (external link, opens in new tab) Yeah. >> so it's like this. >> Yeah. >> This like this. >> That should be >> just say zero at the end. >> Are we still meeting a nine though? I mean is that greater than nine? 1 2 3 4 5 6 7 8 Oh, it's it's at zero. Okay, it's fine, I guess. Yeah, >> we don't care. >> Yeah, we don't care. We don't check right now. So we can actually say
[22:31] (external link, opens in new tab) That make sense. >> What did you just do? What happened? >> Remove this line. >> Oh, okay. >> Yeah. >> Okay. Seems to be passing now. So now the question is how do we trust it and see it fail when it should fail, >> right? >> See it fail. Right now we saw it fail for the wrong reason. >> Okay. >> Now we just made it pass for the right reason, but we didn't say see it fail for the right reason.
[23:02] (external link, opens in new tab) So we can't trust (external link, opens in new tab) it. Maybe it's always passing. >> So we we should revert it back to the original implementation. >> No, not the test. We should we should go to the we should find the place in production code, >> right? that we can comment out to actually create the bug that this creates that this tests for. Black owns two cells, white owns one cell, black wins.
[23:32] (external link, opens in new tab) >> So, you can add I mean maybe revert our change in the prod product code back to original. I don't know. Do we have to do that? No, we have to find if we want to trust this test, we have to put a real bug that this test tests for and see it fail when it should fail, >> right? >> That was our original implementation. >> If I if put a plus here for example.
[24:04] (external link, opens in new tab) >> Okay. >> Yeah. Plus. Okay. Like this. something should fail. But not this test >> because it's not testing for two too many black cells here. H it's testing for black owns two cells, white owns one cell. So if we have two many white cells maybe or yeah actually if we comment this out
[24:37] (external link, opens in new tab) This test should fail just like we wanted to. Right. >> Now, that seems weird, but I just want to make sure that this test is is actually testing what it's supposed to. >> Okay. >> Go away, Dropbox. Anyway, okay. So, I I trust it a bit more now. It seems weird, but in TDD (external link, opens in new tab) when you when you start testing with a test that fails, you're actually saying, "I'm testing the test because the test should fail in this position." Then you make the test pass without touching it because you're actually fixing production code and then you should see the test pass.
[25:19] (external link, opens in new tab) >> That's basically a way of testing the test because you've seen it fail when it should and you've seen it pass when it should. >> Okay. But what happens if you realize the test was wrong the whole the whole time and now you've fixed it and it's still passing? How do you know it fails when it when it when it needs to fail? >> Okay. >> So, you need to find a way to trust it. That's what I was looking for. I think it was okay this time. >> Okay. >> Okay. So, we've just changed our strategy. So, maybe we should name our strategy to
[25:50] (external link, opens in new tab) >> most cells win. >> Winner by count strategy. Okay. >> Okay. Yeah. >> Cool. >> Okay. So, now we have a winner based on actual counts. >> Mhm. >> Right. Do we want to add another feature? Do you want to add another test that proves this? >> I think the the amount of tests we have right now proves it already.
[26:22] (external link, opens in new tab) >> Yeah. But what about the feature where we want to have multiple points here? That's one of the features we want to have. Right. >> Right. >> So we can create that feature now. >> Do you want to you want you want me to try and do it or do you want to try it? >> No, but the thing is that we don't have the feature to detect that area is surrounded by you know I mean we don't have that code right now. So I think we need to break it into
[26:52] (external link, opens in new tab) Two two steps. one to detect that two spaces connected to each other are surrounded by a group. >> Sure. >> And then we can check that the amount of points >> it's greater. >> So is there is there a test that you can make without checking the amount of points or getting the winner >> that proves that you can detect this? What test you want?
[27:23] (external link, opens in new tab) >> I mean, it would basically be the same one as where's basically the same one as this one, but
[28:09] (external link, opens in new tab) Right. >> Okay. >> And we probably name it to >> black surrounds two cells maybe. Yeah. >> Or black territory is two cells, spans two cells. I'm not sure. >> I think the guy called it connection. One black connection. >> I if I looked at this test, I don't understand that. >> One black
[28:40] (external link, opens in new tab) Chain surrounds two cells. >> Okay, that looks good. This is called a chain I guess. >> Well, and I like that we see that it's already failing, >> right? But this one is like I just like we mentioned it cop this one does both the getting the winner and checking the group. So actually maybe it's not this test that >> Yeah, but what's the problem? I mean I'm trying to understand why do you have a problem with this test?
[29:12] (external link, opens in new tab) Why is that bad? I feel like it's two two things we're doing at once. I don't know. Maybe you can show me why it's good. >> So, the way I think about it, it's not a bad test. Can you bring it to the screen? >> Okay. Where did I put it? >> Yeah, >> I just missed it. >> So, why do I think this is actually not a bad test? Because the way I think about it, a unit of work (external link, opens in new tab) only has three types of results. End results (external link, opens in new tab).
[29:43] (external link, opens in new tab) It either returns a value, it changes the state of the system, or it calls a third party, which is where you would use a mock object (external link, opens in new tab) like to to check that a logger was called. >> Mhm. >> Now, in this case, we're filling the board. We're actually changing the state of the game. >> Right? Now if we were to check the state of the game the internal state we would actually be checking implementation detail which we don't care about.
[30:14] (external link, opens in new tab) >> Let's say that we would check and we would check that and see that somehow the game knows that the two cells are surrounded. Okay. >> Mhm. >> It wouldn't mean anything because the get winner would not change behavior. Mhm. >> It only means something if it matters to get winner. >> So >> when I create the board, I want to get the result at the same scope at the same level where I change the state. I don't want to dig deeper. I want the entire thing to be encapsulated.
[30:46] (external link, opens in new tab) So I don't care about how the winner is determined. I just know that the only thing different is and now now I have two cells. I don't care how it's calculated. I just know that it affects the winner. Okay. >> There is only one way to know that the game cares about this and that's currently by getting the winner. >> Mhm. >> Does that make sense? >> Right. >> Or maybe you're just being polite. I'm not sure. >> No, it makes sense. It makes sense. >> Okay. >> but if you if you can think of a different way to check that it knows about that these two cells are surrounded, I'd love to know.
[31:23] (external link, opens in new tab) We can make a discussion. I just figure out one one of the tests we had is it eats up a white stone with when we surround it with black, right? So like this one. So if we have this one, we can do basically the same thing where we put in another copy of this cell. I mean copy of this test. >> Yeah. So these are two features we need to test for. I mean we need these two tests definitely. That's another behavior.
[31:54] (external link, opens in new tab) >> Those are two end results that and each one of them needs a separate test or two features. >> One of them is eating the thing you just surrounded and the other is determining the winner. >> Mhm. >> Okay. Just because you eat something doesn't mean that the winner will still be determined correctly. Right. >> Right. >> So, we still have to check both of them. So, if that's what you meant, I understand that that's another type of end result. That's cool. Right. I was thinking that maybe this test might be easier >> than the other test. Like you know how you're you're talking about write the easiest test first.
[32:28] (external link, opens in new tab) >> Sure. >> So >> why do you think it would be easier? >> I don't I don't know just I guess I guess it kind of like separating the steps from >> okay >> finding a group and getting a winner. >> Okay. So, so let's create a version of this test that you're currently selecting and comment out of the other one. >> Okay. >> Actually, it's a version of the other one only there are there are two whites inside the black chain.
[33:01] (external link, opens in new tab) >> What did I just do? >> Did I make a copy? >> I have >> I don't know. The window's so small. Okay. What's going on? Well, you can make the window bigger for now and just double click it.
[33:34] (external link, opens in new tab) Okay, here it goes. Surround two. Round two. Opposite color stones. Two. Round two. Yep. opposite color stones, black, white, and white. >> Okay. And what about the other test? >> The other test we should probably >> need to comment out because it's we have two failing tests right now, >> right?
[34:06] (external link, opens in new tab) >> Where did I put >> where? There it is. There you are. Our >> Okay. Okay. >> So, this test obviously fails. That's good. So, we should be getting the boarded position. I think the assert >> should probably change, right? So the the question for this one would be, should I I know like you don't like having two asserts, but would it be good to have two asserts to assert that both of these >> are empty?
[34:38] (external link, opens in new tab) I think so. For now, it would make sense. And maybe later I might split it. But they're both about the same. They're on the same object. >> Mhm. >> So, I wouldn't mind. So, status two like this, status one, and status too. >> I think you got rid of the position status.
[35:12] (external link, opens in new tab) Okay. Still failing. >> Mhm. That's expected. Okay. So, having said that, that doesn't work. So how do you want to work on this? So currently what's failing is
[35:43] (external link, opens in new tab) The whole is surrounded by Right. >> Right. >> where's the thing that makes things empty? We need to later extract that. Right. It's always happening when someone changes the position. Yeah. And remove if needed. >> Stone is surrounded. That's what we care about, right? >> Mhm. So he's fully surrounded by. So we can check he's fully surrounded by maybe fully surrounded by might also check that.
[36:22] (external link, opens in new tab) Okay. So what would be the simplest thing that would make that pass? I'm kind of wondering what would be a good way to solve that. >> I don't I don't know what the simplest way would be. >> okay. What's a good way? >> So, the way I did it was that I I don't think I don't know if it's a good way or not, but I basically found all the connecting stones and then I check and then I then I checked if those if those stones were fully surrounded
[36:54] (external link, opens in new tab) >> all the connecting stones. >> Right? So if we go back >> like a recursive function or something. >> For me, I didn't use a recursive function. I I don't think it was necessary to be a recursive function. >> But for now, let's make an assumption that we just need to check the stone to the right. >> Yeah. >> Okay. >> And then see where we we we go with that. So, we can check is fully surrounded by and if it's not fully surrounded
[37:28] (external link, opens in new tab) >> or or if it if it has a stone of the same color on the right. >> Mhm. >> interesting. What if we said it's not surrounded by but it's surrounded by except just one block of the same color. I think that would make the test pass. Yes.
[38:00] (external link, opens in new tab) Yeah. And then we can introduce tests afterwards that makes it fail. Okay. So, I'm not sure I did what I just said, but I think it was smart or stupid or simple. We can check not just fully surrounded by but we can also check something like this var fully surrounded except
[38:31] (external link, opens in new tab) One matching color We still have an assumption here about the color. >> Is our test about white or is it about black that's being surrounded? >> Right now it's it's black being surrounded by white. That's we haven't had we haven't added tests to remove that assumption yet.
[39:12] (external link, opens in new tab) Maybe we should do that test first. >> Okay, sure. >> To remove the white assumption. Okay. >> so delete the whole thing. >> Comment out that test. >> Yep. >> Okay. >> H, that's not good. That's not what I meant. There we go. So this is the test that's failing. And this is the one that I'm going to comment out.
[39:45] (external link, opens in new tab) Because our assumption that's not meant our assumption where is its assumption using Vim keyboard shortcuts here for some reason. Come on F and this is what it looks like. Seriously.
[40:21] (external link, opens in new tab) White. Oh. Okay. So, what would a test that proves that we can't always choose white? >> So, basically, choose one of those tests and basically which one? >> that one right there. And then switch invert their colors. Okay. So, add stone surround opposite color stone color color stone.
[40:59] (external link, opens in new tab) Actually, what if we not duplicate it but use the test case here? >> Oh, yeah. So instead we would do something like this test let's extract ah no we can't because the board is different we can put that actually we can we can create the string as an attribute string as well
[41:34] (external link, opens in new tab) Like this then we could say that this is a test.
[42:11] (external link, opens in new tab) And we would actually let's select it like this. Control control select would have worked here. I'm not sure why that's not working. Or maybe it's alt. Yeah, it's alt. There you go. And we would select the winner to be >> well this one isn't selecting winner is just >> empty position actually. >> Yeah. So it's still still the same. So you just need to copy the test case and convert to colors.
[42:45] (external link, opens in new tab) >> Okay. And then we would say string board. Then we say that fill board with >> you already have a board variable. >> Yeah, board map. >> That sounds great. >> yeah, that's the same test. And then we'll just say B W B.
[43:19] (external link, opens in new tab) >> Okay. So in this case empty position but was filled position. >> Mhm. Because the white was not removed. >> BBWB. Okay. It would have been nicer if NCrunch would have said this one failed and this one passed. >> Mhm. That's true. >> Okay. Now we can go back and say,
[44:05] (external link, opens in new tab) I remember there was being a recursive lookout lookup. I can't remember what that key. Or maybe it's control I white. Yep, control I. In any case, >> the easiest solution would just duplicate it, right? And just change it to black, right? >> Here. >> Yeah. It's full surrounded. It's full surrounded by color white.
[44:35] (external link, opens in new tab) I would say an ore actually. >> Or nice. >> Okay. So we would say >> Yep. >> Yeah, that makes it pass. >> But I got I got a test case for you that will make it fail. >> Yeah. Hold on. Let's just make sure.
[45:13] (external link, opens in new tab) Yep. >> So if you have a black stone surrounded by all black that will that that will fail. >> Cool. So why don't you create that and that but it should Yeah. But it should not I mean that's a different test case. >> Yeah it's a different test case. >> A different expected behavior. >> Right. >> So okay. So, >> so how do we deal with that one? >> We create a new test because the name wouldn't fit, >> right?
[45:46] (external link, opens in new tab) >> Unless we can actually, you know, what we could do? >> Mhm. >> We can also create a test case that just we can extract the empty and say we're looking for stone color empty here we're looking for stone color black >> fill. >> And actually, let's make it.
[46:16] (external link, opens in new tab) >> No, it's position. It's position position fill >> position is always sorry >> because the assert is using position status. It's not using >> Yeah. Oh, so we should get rid of that empty thing. Oh, that's bad.
[46:51] (external link, opens in new tab) >> I think we can get rid of position status later on. >> Let's make everything pass. Position status filled. So, let's make it white. >> Yeah. We you need to add the variable. You have it. >> Oh yeah, that's right. Status expected.
[47:33] (external link, opens in new tab) Surrounded. position status one failing. It's this one. Let's make sure. Yeah, it's still white. Okay.
[48:10] (external link, opens in new tab) >> that's a good test. So, how would you solve it? >> So, I would get I would have a a statement that chooses the surrounded color based off what the current color is. >> Why don't you go ahead and do that? >> All right. simplest thing that could possibly work. Remember
[48:47] (external link, opens in new tab) XY Nice. Keep this one.
[49:28] (external link, opens in new tab) Yay. Cool. Okay, now we just need to make this much much more readable. So now we can do basically right? >> Yep.
[50:04] (external link, opens in new tab) So we could say if it's surrounded by opposite color >> yeah I like to rename them. Yeah I I like it. >> I don't know if we need to rename it though. >> Okay. >> Surrounded can only be by opposite color. >> Yeah. >> I I was thinking maybe it needs to call another one but maybe not. I think the only thing if want to do is if you want to rename the method.
[50:34] (external link, opens in new tab) So, but I think it's it's a good name for the method. >> Is there any other assumptions we have to get rid of here that we don't like? >> I actually wrote down a bunch of assumptions. So, >> where are they? >> Give me a sec. >> Well, there was in the to-dos. How do you u view the to-dos easily? I forgot. There's a there should be a way to >> control I todo. Control I >> todo. >> Oh. All right. So that one we did.
[51:04] (external link, opens in new tab) >> Okay. >> So control L. Okay. >> Control shift L. >> Control shift L. All right. Control I again. >> Yeah. Incremental search. When no one owns any territories, the last player wins. The player that wins is white because of komi. We already removed that. >> We only already have komi, don't we? >> Yeah. Yeah, you're right.
[51:38] (external link, opens in new tab) >> Actually, first round of territory found by the for loop is the winner. We remove that as well. >> Yep. >> I think that's it. >> What happens when you're out of board position? Oh yeah, like if you add add a stone outside of 1919. But right now we don't check we don't have it's like a new feature. We don't have anything about >> I don't think it's important now. I mean I usually try to when I drive new stuff I like to try to get the happy path first.
[52:10] (external link, opens in new tab) Just get things running and then check all the edge cases and valid stuff >> because otherwise you can go through a whole day of just checking invalid stuff and then your man manager comes to you and says hey got anything for me and you'll say well I have nothing but it checks all the invalid values right so we never want to do that >> just leave it for now >> sorry >> we can just leave that for now we can Okay.
[52:42] (external link, opens in new tab) >> all right. >> It's interesting. We don't even have the line of the top line. Have you noticed? Oh, yeah, we do, actually. >> The the line is offset by one, by the way. You need to add a space before the one. >> Sorry. >> So, let me add it for you. >> I don't understand. Oh yeah,
[53:18] (external link, opens in new tab) >> that's just for readability though, >> right? >> So we have to go like this, >> what else? What else? What else? >> So we have the two features that we commented out. test for two features. >> Okay, let's go ahead with that. But you know what? Let me just let me just commit something first. What what feature did we just finish? >> so we just removed assumption
[53:49] (external link, opens in new tab) That surround surrounded only by white. >> Removed assumption that surrounding color is always white. Anything else? Oh, added counting how many cells. Edit counting how many cells determine
[54:23] (external link, opens in new tab) Determine the winner cells H1 H to determine the winner. Okay. Yeah. Okay. >> Okay. >> Cool. >> Okay. So, what test is should we uncomment first? >> This one you said was easier or No, you had an easier >> I think it's easier, but I thought it was easier, but maybe the >> No, this is not this is Yeah, >> this is harder.
[54:54] (external link, opens in new tab) You think it's harder? >> Oh, no. No. I I I misunderstood. Yeah, I think this one might be easier, but I'm not sure. So this should fail right now. >> Yeah. >> And again the feature is surround two opposite color stones. Remove the opposite color stone. Okay. So we got rid of the thing here. So now let's see if we can make this work in a simple way.
[55:31] (external link, opens in new tab) We got the opposite color is fully surrounded by the opposite color. We'll actually return false, right? >> Because but we also have a special rule that says aha but this time we can also be partially surrounded. >> Right. So we can check what if we had something like this are
[56:03] (external link, opens in new tab) Part of a s might be part of a surrounded of multiple surrounded cells. is a adjacent with an A. Is it with an A? >> Yeah, I think so. >> Is adjacent cell
[56:33] (external link, opens in new tab) Of same. Well, how would you name this method that that checks that we have? Well, for now the assumption is is that we have one cell of the same color next to us. Cell of the same color. H would you say that? That would be good. >> Yeah. >> So I would do something like this. And also
[57:06] (external link, opens in new tab) Rules is almost fully surrounded. What do you think? >> so why why is there two have to occur right? First you have to have you have to be almost surrounded and the one next to you should be of your own color so it's not empty. >> I see. But I'm just I'm just thinking out loud. Maybe this is complicated.
[57:36] (external link, opens in new tab) >> Can't the can't the other one be part of Can't this method be part of this method inside there? >> Well, it could be almost fully surrounded and the cell next to me might be empty. >> Or am I thinking too much about this? Maybe I should make that assumption. >> Yeah, maybe. Yeah, let's just get rid of it and then we can add remove that assumption about the empty later.
[58:09] (external link, opens in new tab) >> What do you think around it? >> But if we want to remove that assumption, we could also do it in this method so that it it returns. >> Sorry, >> I think that maybe we can probably do it inside this method that in is fully surrounded by >> Yeah, but that would be we would start doing counts. I I want to right now >> just see if we can solve it without touching anything else. >> Okay. >> And then we can after it passes we can incorporate it by refactoring.
[58:44] (external link, opens in new tab) Is almost fully surrounded. Int X int color opposite color. Okay. So it would almost look the same. Where is fully surrounded? Where does that exist? Yeah.
[59:14] (external link, opens in new tab) So imagine we did exactly this. >> Mhm. Actually yeah, let's say surroundings don't
[59:54] (external link, opens in new tab) But here we would check. >> well if you want to make it pass, you just >> comment out the one of them, right? >> You would just want to comment out one of them, huh? >> If we want to make it pass right right away. >> No, we would have to change it. Right? because that would pass for everything else that's for the surround to check the the other the get opposite
[1:00:26] (external link, opens in new tab) Like so for us is surrounded on right we can just say is get opposite color we don't have to get opposite here that sucks we have to get it from board right so now we have to go here actually you know go with the board.
[1:01:36] (external link, opens in new tab) So stone color matrix is basically what is it just get stone color? Yeah. Bor that get stone color. And yeah, I'm thinking we're diving here quite fast. Let's see.
[1:02:06] (external link, opens in new tab) I'm kind of losing myself. It's a bit late. Let's see. So now where were what were we trying to do again? >> You were trying you we we didn't have access to a method get get opposite color but I think it's >> he's almost fully surrounded. Yeah. >> Right. Oh, and we said get opposite color of >> XY.
[1:02:37] (external link, opens in new tab) >> X and Y. >> No, actually get opposite color of you wanted to get >> X and Y + one. Yeah, >> actually you didn't need to get opposite color. You can just get get current color of XY. >> That's true. Oh, that's stupid of me. or get stone color. >> Yeah. >> X plus Y.
[1:03:12] (external link, opens in new tab) >> your your method return type is void. You need to be change it to bool. >> Yep. And we still have to go here and say rules. What else? Pretty sure it's not building. Let's see. Oh, actually it does build. It's still failing.
[1:03:43] (external link, opens in new tab) So, or I thought that would be the simplest thing to just check that it's surrounded and it's the same color on the right. >> I think it's because we're checking both of them, >> but we're not using the result. That's why. So, if we go here, >> it's almost fully surrounded. So, yeah, we get almost surrounded, but we don't return anything. and we don't do anything about it.
[1:04:13] (external link, opens in new tab) >> Mhm. >> So, >> so if >> so if fully surrounded no problem. But let's say we can say if almost surrounded then both positions are empty. So x + one. Right. >> Right. Okay. I see.
[1:05:01] (external link, opens in new tab) But it's still failing. So, that's not working. is >> your code is checking on the right like what what can you dive into is almost fully surrounded. >> Okay. >> Oh, it's y + one. Maybe that's the problem. No, it's it's the top one.
[1:05:32] (external link, opens in new tab) Is that mean the second one? >> Oh, yeah. So, it's X plus one. So, it seems like it would work. And we can just say put a break point and test with debugger. That sucks. I think I'm trying to think if we could have made a smaller step, but I think we're cheating quite enough.
[1:06:02] (external link, opens in new tab) Anyway, run on right. We have X and Y. >> Surround on left is already false. What was the X and Y right now? 30. >> Yeah, we should wait for surround on left to be true. True. >> Okay. >> Oh, you're red. Okay. So now we have x4 and y1. x4 and y is one.
[1:06:33] (external link, opens in new tab) So that shouldn't be get surrounded. >> Yeah, that's not it. We were looking for 22 x2 y2. So you could put in conditional x2 y2. >> That's true. But we already got there. >> Okay. So now we would have >> so left checking that board gets stone color of x + one is the same as board stone color of xy >> right but surrounded on left is already false
[1:07:22] (external link, opens in new tab) Shift. There was a shortcut for that, I'm pretty sure. Shift P. No. Control Shift Damn it. Debug. Quick watch. Shift F9. That's value empty. Interesting. It's an empty color of x minus one. Are we getting the wrong board here?
[1:07:52] (external link, opens in new tab) >> I think you might have removed it. >> You think we already removed it? >> Yeah, like maybe the code that we added somehow removed it. >> I don't know how though, but at least we found the bot. like so it's almost fully surrounded. Oh, so you think in the fill board? >> No, I mean in this is almost fully surrounded.
[1:08:23] (external link, opens in new tab) Maybe it returned true when checking W and then removed it. Maybe it's possible. Oh, because we already added the code here.
[1:08:57] (external link, opens in new tab) So, we got here before we got here. So, we haven't removed anything. >> Okay. But we did get almost surrounded. So, that's good. >> So, that's for 41. X41. So then it removes >> x4 and >> and then >> one >> plus one. So that should be on our right. Okay. >> That doesn't make sense, right? Am I missing something?
[1:09:28] (external link, opens in new tab) >> I mean it's this position. >> Oh, I think No, I shouldn't. >> What? >> No, I was wrong. I was thinking of I was thinking that maybe I mean it should have well actually you could check the board position right now but I'm guessing that when it checks this one it it says it's surrounded and then it removes this and it removes this
[1:09:59] (external link, opens in new tab) Because it doesn't check. Let's see. So two one is empty and one and one two one and two one and one two two one Damn it. Two one is empty. Yeah.
[1:10:34] (external link, opens in new tab) >> Yeah. Because it's it's checking for freely surrounded even if it's empty. >> Mhm. >> So we shouldn't make anything if it's empty. Make sense? >> Yeah. >> So if something is empty, it can never be surrounded. >> No, but the thing is >> that makes sense. >> Yeah. Yeah, you're right. You might not add that to is almost fully surrounded only though because the almost fully surrounded is kind of interesting where I mean it's kind of >> fully surrounded has the same problem.
[1:11:05] (external link, opens in new tab) >> But it's fully surrounded only removes >> in that middle position. So if it's empty it'll set it to is empty. >> Yeah. >> The almost fully surrounded is if it it's also setting what's right of it. So we can just the simplest thing would be to just check if board get stone color of x and y
[1:11:42] (external link, opens in new tab) Equals empty >> right >> return false. Okay, so we had here here >> and now we can try again. Obviously still failing.
[1:12:17] (external link, opens in new tab) I wonder if the viewers at home are already lost or not. So, now we get here first. And that's okay. What was the XY? 32. Okay. >> 32.
[1:13:03] (external link, opens in new tab) So, status one. Okay. So, three and two should not say that it's fully surrounded. Should say it's partially surrounded, right? >> Yeah. So >> no, it's not this one. It's this one. So 32, but we had two and two that also came out fully surrounded. Right. >> Right. So I I think I know understand what's happening. So
[1:13:34] (external link, opens in new tab) It's it's first checking here and then I mean when it adds this actually no I don't really understand. Oh, when it adds the W maybe right here and then it checks then it checks this one first. >> Mhm. >> And then or if or maybe it might be No, actually maybe this one. I'm not sure which when when is it which stone is it adding that it does the remove stone.
[1:14:06] (external link, opens in new tab) Do you know what I mean? That's why I'm just trying I'm just trying to understand how this code is working. >> I think if we move fully surrounded to be first and will win. I mean basically if we do this it will help some way and the reason is because this returns true as well.
[1:14:40] (external link, opens in new tab) >> Mhm. >> So we want to get this one first but that didn't help. Was more of a guess actually.
[1:15:12] (external link, opens in new tab) What if we just did this? We have to fix fully surrounded. That's what I think. What do you think? Are you Are you Are you lost as well? >> you should not say fully surrounded successfully. That's what I'm saying. We have a bug here. Do you agree? >> If if it's empty, you mean if it's >> I mean for 3.2, it should not say that it's fully surrounded, >> right? >> Do you agree? >> I agree. I agree. Yeah. >> Why did it say it's fully surrounded? That's what I'm That's why I'm asking.
[1:15:43] (external link, opens in new tab) >> So, you want to dive into that then? Yeah Fully surrounded. So we will check here. Let's try again.
[1:16:15] (external link, opens in new tab) Okay. So here we have x and y of three and two. So now we can go ahead and start debugging. Why does it say that's fully surrounded around on left says true wtf dude get stone color surrounding stone color is white.
[1:16:47] (external link, opens in new tab) And here x is three, y is two. So we have two and two. It says that this is actually white. >> Let's see. Board position stone color.
[1:17:19] (external link, opens in new tab) Two and two. This says white. Oh, I think yeah, I think that remember we I think we have an unfinished business. We only check if something is surrounded if if the first three if it's surrounded on top, left, and bottom. >> Mhm. >> I think
[1:17:52] (external link, opens in new tab) And when we added this one or this one or one of them, it already checked and turned it into white. >> No, it doesn't not supposed to turn anything into white. It's supposed to make it empty. >> True. >> So, what the hell? >> Yeah, I want to check first if it's always white or was it black and somehow it turned into white. >> Okay. >> so how we do that?
[1:18:25] (external link, opens in new tab) >> You bug the hell out of this. So right now the board position before doing anything is
[1:19:05] (external link, opens in new tab) And we have the stone color matrix. Everything's empty except we have white at two and two. >> See this? >> Yeah. >> So, can we set a break point at adding when we add the stones to the board? here. >> Yeah. And then run the test from the beginning.
[1:19:42] (external link, opens in new tab) >> Okay. >> So 31 is right. And then we should >> Okay. 32 black. Yeah, that's right. Three is white. Okay. 42. Oh, he didn't start from the beginning though, right? So, we don't know >> it didn't start from the beginning. I'm not sure why
[1:20:16] (external link, opens in new tab) >> two and two white. >> Okay. So, we came here from here. So, we always add a white here. >> Oh, I see. Wait, what? How does that How's that part of the test? >> Am I getting a wrong test? >> You're in the wrong test right now. We're We're trying to do
[1:20:51] (external link, opens in new tab) That's a different test. >> What the hell? Hello Mike. Okay, >> thanks world. >> It's problem with the font too big. >> All right, >> let's make sure we're not crazy. >> So much for TDD, huh? >> so we have So let's just make this a bit bigger so you can see it.
[1:21:35] (external link, opens in new tab) >> One and three is white. >> Yeah. One. And that's it. So this is where things happen. One and one becomes empty. Okay. >> Okay. >> Two and three black.
[1:22:12] (external link, opens in new tab) >> Two and four white. >> Okay. This is this is probably where No, actually no. Probably the >> Why is two and four white? I think we might have accidentally switched the X and Y positions. I mean, it's like two, four. It's supposed to be two, four in our fillboard. We might have accidentally switched the X and Y positions.
[1:22:46] (external link, opens in new tab) Please, how but how how do all the tests continue to pass then? cuz the it didn't really matter which direction is X and which direction is is Y. It's mainly for readability. So you could like just rotate the board and it's still the same, right? >> But it's not. >> You >> But it's not. You think it's because that we have different length on and X and Y?
[1:23:21] (external link, opens in new tab) Say again. I'm not sure I understand. >> So you think X and Y because they have different length then something's wrong. I mean here I and J. Okay. I is the line. Let's rename that. Okay. >> No. So if you switch Yeah. >> We add the line number. I think I think the I was the Y and J was the X because you're going through each each line like up like that and then you're going >> Let me change line number to to X. Okay.
[1:23:51] (external link, opens in new tab) >> Okay. >> And X. So we X and Y and J is the line length. Aha. So J is actually X. Yeah, that's what that's what I meant. >> That should be Y and then the other one should be X. Jesus X Y
[1:24:35] (external link, opens in new tab) Tests passing. All tests are passing now. So it's the original reason was that. Nice. Our fill board was wrong. >> Oh my god. This is this is why this is why I always recommend people not to have any logic in the tests because that's the hardest crap to find. And here I am doing such a rookie mistake. Horrible. I'm just If I had any balls, I would ship myself right now.
[1:25:09] (external link, opens in new tab) Horrible. Oh god. Okay, I'm going to commit this and go to sleep and just just just think about all the things I could have done with my time. Git commit to say we are so stupid found some bugs in our tests like Oops. And what did we actually add?
[1:25:40] (external link, opens in new tab) What feature did we just add by the way? We had how do you say check >> two neighboring positions if surrounded by opposite stone? >> Yeah. >> or check >> multiple stones can be surrounded but only on the right. >> Yeah. Only attached on the right. >> Perfect.
[1:26:12] (external link, opens in new tab) You know what? As far as I'm concerned, this is an achievement based on our current stupidity level. >> Okay. >> All right. >> Okay. So, thank you for an amazing session, Raymond. Seriously, that was that was just chalk full of awesome. I will see you maybe tomorrow. >> Yeah, >> go away color scheme. Okay. See you see you dear viewers.
[1:26:42] (external link, opens in new tab) Hopefully you won't want to shoot us for this. >> Cheers. Dear God,