---
title: "A DSL for our Tests"
url: "https://courses.osherove.com/courses/tdd-pairing-sessions-building-a-go-game/a-dsl-for-our-tests.md"
canonical: "https://courses.osherove.com/courses/tdd-pairing-sessions-building-a-go-game/a-dsl-for-our-tests/"
tags: []
author: "Roy Osherove"
description: "Lesson 7 of 11 in TDD Pairing Sessions - Building a Go Game (The Sessions), 55:07. Free video by Roy Osherove."
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# A DSL for our Tests

1. [Courses](https://courses.osherove.com/#courses)
2. [TDD Pairing Sessions - Building a Go Game](https://courses.osherove.com/courses/tdd-pairing-sessions-building-a-go-game/)
3. The Sessions

Lesson 7 of 11

Duration: 55:07 [Watch on YouTube](https://www.youtube.com/watch?v=TGTnFqtIWQ0)

## In this lesson

In session five the pair turn on NCrunch, which runs the tests when the code changes and shows [line coverage](https://osherove.com/blog/2005/4/3/test-coverage-and-testing-angles.html "Test Coverage and testing angles (osherove.com)"). For counting territories they write tests where one color owns one cell and the other two, but the tests pass unexpectedly and they cannot find out why. They build a [DSL](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-7#ch07lev1sec6 "Building a test API for your application (The Art of Unit Testing, 2nd ed., ch. 7)") that draws the board as a string with numbered rows and B and W stones, parsed by splitting and trimming lines, and convert the other tests to it.

## Transcript

5,375 words

[\[00:03\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=3s) Hey Raymond, how are you? >> I'm doing great. And >> welcome to session number five, I think. >> Yeah. >> Cool. >> So last session we actually stopped with a dilemma about refactoring and we did some refactoring for strategies. But then we we figured maybe it wasn't a good idea based on the fact that we were going to do scoring. So let's see where where this takes us now. So

[\[00:33\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=33s) We stopped short. Let's make sure that all our tests are running. Can you can can you press Alt R? See what happens. I wasn't sure how we had run it last time, so I'll just run it this way. >> All right. >> Okay. And also you've installed NCrunch, >> right? I haven't tried it yet though. >> Okay, so let's try to enable it. Enable NCrunch. And there's this wizard here.

[\[01:05\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=65s) Now, I tried NCrunch a bit on my machine. It's a pretty cool thing, but this dialogue when you try to enable it is just horrible for newbies. So this is how many cores it should use. Max number of background processing threads. Optimize for fast test execution. Run test in parallel. No for us. No. Which again engine execution mode automatically when changes are detected. You see how many questions now?

[\[01:36\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=96s) Ignore test. Ignore all my tests by default. No. I want to run all of them for now. And that's it. So that's that's how easy it is to get started because you really need to know what you're doing. But once you get started, it's a pretty cool thing. So right now it's running test in a separate threads and 14 tests are being monitored and let's see maybe we should put it here.

[\[02:13\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=133s) I'm not sure what would be a good good clip here. We'll see. What if we just here maybe we don't need it. I'm not sure. But anyway, now you can see the [coverage](https://osherove.com/blog/2005/4/3/test-coverage-and-testing-angles.html "Test Coverage and testing angles (osherove.com)") which line is being covered. And you don't even have to press save for the tests to run. So that's pretty cool. So if I if I return like this basically already

[\[02:50\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=170s) Tries to run the tests when it detects some code changes. So if I say equals equals here just to make a bug, you can see that it says project failed to build. So that doesn't make sense. and we didn't even have to do anything and now it's running all the tests again. So if you wanted to see the status we would say NCrunch risk and progress bar

[\[03:22\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=202s) And that's what I used. So it says okay basically so that's what you care about the most. So if we say small equals you can see that status immediately changes and that didn't break anything. But if we say big bigger than

[\[03:53\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=233s) We have nine failing tests. Pretty cool right? >> Right. Very cool. Okay. So, what else do we want to do now? So, you want to can can we try to remember what feature are we working on? >> So, we're working on counting the territories. We have not implemented counting getting points yet. >> Yeah. Right. Now we have a feature that says the winner is the first person who that we find that has any kind of territory.

[\[04:30\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=270s) Right. >> Right. Right. >> So now what is the [simplest test](https://osherove.com/blog/2010/1/6/tdd-4-questions-that-will-help-you-create-the-simplest-thing.html "TDD: 4 questions that will help you create the simplest thing that could possibly work (osherove.com)") to prove that this assumption is wrong? So we can do it where the we can make it so that we can start introducing the concept of of how many territories each person owns. >> Sure. So we can like make the first the first territory that would be found owned by one person that only owns one territory and then the and for the other player would make it like they own two territories.

[\[05:09\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=309s) >> So it should fail because it'll find the first one which is incorrect, right? >> Crap. >> And we should be it should be fine. Instead it should be returning the one that was two territories. Okay. Okay. So, we're going to have two players and one of them going to have two territories. One of them is going to have one territory and the one with two is going to win, right? >> Yes. >> Okay. And that test should fail first. >> Yep. >> Okay. Cool. Okay. So, you want to try and write that?

[\[05:41\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=341s) >> Yeah. Black owns one cell, white owns two cells. Expect white win.

[\[06:13\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=373s) >> Okay. Right. So, oops. >> So, I was thinking we might also want to make u like a [DSL](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-7#ch07lev1sec6 "Building a test API for your application (The Art of Unit Testing, 2nd ed., ch. 7)") for describing the board. So, for example, you know what? Write the test first and then we'll see if a DSL would help us here.

[\[08:13\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=493s) Okay. So this is 2 three. This should be four six So we're not making two consecutive cells for why we're just making two separate territories.

[\[08:46\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=526s) >> Because right now we we have our code does not handle two consecutive cells. >> Sure. >> Okay. >> Right now our our code only handles finding for one cell at a time. >> Okay. >> So that would be another feature we need to add. >> Mhm. I think it's written in the Excel file. So, >> but this is not failing. >> Is not failing. >> No, you can see all the green, right?

[\[09:21\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=561s) My guess is is because it still takes the last player as the winner by default if it needs to. If we add a black player play at the end that doesn't do anything, I think it will fail.

[\[09:59\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=599s) >> Oh, >> interesting. >> Interesting. So, our test is wrong. something wrong with our test. What if we just did that for a second? Okay, so we have the board. We have a black territory in the top two and two, three in one, four and two, three and three.

[\[10:43\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=643s) >> So the second one is X, right? Just to make sure. >> The second one is Say again. >> The second parameter is >> Yeah, second parameter is X. The The third one should be Y. >> Oh, but I Okay, so this is X. This is Y. Okay. So that's three, that's two, these are three, all these are four. Interesting.

[\[11:14\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=674s) Why did it say that? Like maybe maybe our code is amazing. >> Let me comment this out first. Make sure it return should be returning black. Okay. >> Interesting. >> So, you see when they both have when they both have one, the white one, it tends to win.

[\[11:45\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=705s) So, maybe we should reverse it. Maybe we should have two black points so that the black should win.

[\[12:17\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=737s) >> Okay. >> But you still assert that the white wins. Ah. Crap. We're just too Maybe our code already takes care of it. >> Interesting. >> you want to debug it and see what happens? >> Yeah, let's do that. Let's do that. >> Hold on. Hold on. Can you add Let's uncomment this one as well.

[\[12:48\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=768s) >> Okay. >> Make it white just to make sure. Okay. Yep. That doesn't make any sense. Cool. Okay. So, let's see what if we made a break point here.

[\[13:26\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=806s) I feel this NCrunch is making everything run slower. >> Really? >> Just my opinion. >> Okay. >> anyways, hold on. Hold on. >> Oh, okay. >> Let's continue. >> Okay. >> So, what happened? >> we're breaking in right now. >> Sure. >> We're debugging. >> So, I'm jumping in. Jumping in. >> jump in. Probably jump in.

[\[13:58\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=838s) Okay. I would just say if the first cell what it returns. I don't think we need to jump in. Let's just debug the outside and see where the bad result is. >> All right. So, result is black, >> which should be right. because we did that. >> Sure. >> And then what happens? >> And the result is not equal to return result. Okay. So that's the reason why it wins. Let me >> So why does the white one

[\[14:31\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=871s) >> win, >> right? >> Because the first level >> interesting. >> We should u we should switch this with this so that white is first. Right. So that way. >> Why? >> Oh, but it returns white. You said it returns white. So maybe we should >> No, I'm saying that it did return black. Our ours is on black. But when we when Let's create another test the exact opposite test just like we did before.

[\[15:04\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=904s) And we'll see that it returns white in the in the opposite test. So, >> you mean like what we wrote before, what we wrote earlier? >> Yeah. Hold on. >> Sorry. >> so we should like change it back to what it was before. >> No, no. I'm saying let's let's make a copy of the test and make it opposite. >> So, make sure that we're testing it from both sides. >> Okay.

[\[15:36\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=936s) >> I did not rename the >> Yeah. So let's rename the previous one to black wins. >> Black owns owns one cell, two cells, one cell. Black win. Ah, this is unfortunate.

[\[16:17\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=977s) Just copy the test the text from the middle text from the other test and then it it won't reformat right. I try to make it bigger. >> Yeah.

[\[17:01\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1021s) You think this is fine or should I switch all of them? >> Well, the assert is wrong. All right. So, we have two whites and one black territory. >> But this might return because of the I know I should have switched the bottom one >> because it's the first one. It should be it's the first one with the cell wins. Right.

[\[17:31\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1051s) >> Right. So the first one should be black and then this one should be white and then they should fail. It's not failing. Interesting. Okay. Obviously we're just we just too good. No, I'm going to I'm going to run it through the [test runner](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition/chapter-2#sigil_toc_id_37 "The library, the assert, the runner, and the reporter (The Art of Unit Testing, 3rd ed., ch. 2)").

[\[18:04\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1084s) I don't believe this NCrunch, dude. What did it say? 15 pass. >> You know what? Let's since >> I forgot to add the test part to it. >> Sorry. That's why. >> I think it should be okay. >> Okay. It's crazy. All right. >> Okay. Hold on. I I have an idea. Since everything's passing, let's what if we could write a test this way?

[\[18:35\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1115s) Control D with DSL. Okay. Just to make this variation. What I wish we could do is to write the same test. >> Mhm. >> this way. Fill board with

[\[19:16\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1156s) Let's fly like this. would have 1 2 3 4 5 6 7 8 9 10. What's the minimum column number? 12 11. >> The minimum well we Yeah. Minimum is nine right now. >> And you go. The minimum is nine. Yeah.

[\[19:47\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1187s) >> Okay. And then we have two, four, five, six, seven, eight, nine. >> I think you still need the one. >> Really? >> Oh, yeah. >> Yeah, I forgot. Cool. >> Yeah. >> And then we would have let's say empty. >> You could type out empty for the whole thing. Well, what I want is for not empty to be white. You know what I mean?

[\[20:18\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1218s) So, this would be oh, so you think it should be like this? It would have a white. What the hell is going on? Why is it not letting me write? Oh, because we don't have space. We have white.

[\[20:53\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1253s) >> Does that make sense, >> right? >> Maybe we shouldn't use the commas here. I'm not sure. >> yeah, >> sure. Let's not use them.

[\[21:29\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1289s) Like this. >> Yeah, looks good to me. So we can have this and then we could have black here. Okay. Yeah. And another black. Like this.

[\[22:07\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1327s) Then another two spaces. No. >> No. This one only has one. Oh, sorry. I messed you up. >> Dude, this is delicate work. >> By the way, the the test you're writing in is black owns one cell, white owns two cells. >> Yeah. >> So, this is like for the other test. Oh, the other we can copy and change it. The big problem here is the empty spaces. >> What do you think? Is this more readable? >> This is more readable.

[\[22:37\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1357s) I agree with that. >> Yeah, >> it should be pretty easy to to to generate the board based on that, don't you think? >> I think it should be right. >> Do we even need these numbers though? Am I naked? >> I don't know. >> What if we just did this? >> and then >> I think the n I think the numbers make it more readable.

[\[23:09\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1389s) >> Yeah. >> But we're going to have a problem when we reach twodigit numbers. >> Uhuh. >> But in that case, we might just repeat start from zero and one. You know answer like >> one zero 1 2 3 4 5 6 7 >> I agree I agree with that. That that sounds good to me. >> Okay. So let let's start try to create that.

[\[23:40\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1420s) Okay. >> Okay. Well, we don't want to make sure the Oh, I guess the tests are passing. >> Yeah. So where is board? >> Oh, now it's Oh, you >> Wait, wait, wait. Map stone map. Okay, so this would be like basically a loop, right?

[\[24:11\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1451s) Right. >> Or int i equal but we would start from one right >> right >> up to >> which is still zero >> h >> yeah but we would need to we don't care about the numbers we just care about the >> you understand what I mean the inner loops we just care about what's after the numbers. So but here we'll start with nine. So it would be until 10

[\[24:45\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1485s) And we reduce from one >> right then there's another inner loop from 10 to one. So like the the simplest stupidest code we could think of just just to to generate this code. So it would be >> I think this is actually you just board add stone and then if >> but >> if if not empty.

[\[25:24\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1524s) >> Yeah. Just just if so we just need to get the string first. Right. >> Right. String s equals stone map. Oh, how do we treat the stone map? Uhhuh. In this way, we we didn't we didn't figure that. Maybe we'll just create it as an array. >> Array would be easy. Yeah, >> but less less readable.

[\[25:56\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1556s) But I'm pretty sure we can just calculate the the position right based on I and J, >> right? Yeah, it might be easier to just get the line and then where there is a W or a B. So instead of like instead of like so instead of a for loop inside a for loop you just get for each line and then you get for each letter starting from one.

[\[26:26\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1586s) >> Yeah but how do you get the lines? How do you split it by line? >> >> for based on new line >> yeah I mean because it's actually I don't know if there's a string method to do that. split. Just split by line. >> Right. >> Yeah. And for each >> for four, I think we need a four to to get the line number.

[\[26:58\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1618s) >> Oh, yeah. We don't know what what the line number is. >> Yeah. >> Do lines. >> do lines count counts. >> Sure. Sure. >> And starting from one >> really Oh yeah, that's true. >> I think count is a capital C where it's size. >> I think it's length. >> Okay, here length, right? Okay. And in that case, we would have

[\[27:30\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1650s) You start you can start from one until the end of that line array. the so I guess you would write line equals lines I yeah string line I and then we would do basically a >> another for loop yeah >> to line length

[\[28:02\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1682s) >> right it's starting starting from one because you want to skip the numbers on the side. >> Sure. >> And then it would just be you check if if it's empty first. >> Why don't you give it a try? >> Okay. >> I think it will be faster. >> So get it get the string I guess. >> Yeah, the string. So I I would say it's I don't know how I call it cell equals

[\[28:35\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1715s) Line J, right? >> Sure. >> How come it's doesn't care? Okay, even easier. Oops. Okay. Okay. If cell not equals space

[\[29:08\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1748s) And just if cell equals Ah, what was that? Just Yeah, we need the board. We need to give it the board object. >> Oh, yeah. You're right.

[\[30:26\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1826s) >> does that look right to you? >> Well, there's something doesn't compile here. >> Yeah, we need a parameter here. >> Oh, yeah. Maybe we should make board first. >> Sure. >> Might make it look nicer. there. >> Okay, now we just need to remove the other ones.

[\[30:59\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1859s) I mean this whole >> this whole thing. I mean this. >> Okay, now it's failing. >> So, what the hell? Maybe we typed in something wrong. >> You know what we should do? We should Well, well, the the assert is you said that this board is actually matches the other test. >> Oh, yeah. You're right. So, this should be black.

[\[31:30\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1890s) >> So, so yeah. So it should be like this. Wait, I guess we could just replace all. No, just just Oh, come on. Black like this. Black. I think that's easier.

[\[32:02\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1922s) White.

[\[32:33\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1953s) All right. Still failing. >> So, you know what we need to do? We need to put this in a in an existing passing test that we know that we [trust](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition/chapter-7#sigil_toc_id_134 "How to know you trust a test (The Art of Unit Testing, 3rd ed., ch. 7)"). Mhm. >> So we see if we break existing tests. >> Okay. >> So what are some simple tests we can the simplest test we can we can think of here maybe like this. >> Yeah.

[\[33:08\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=1988s) So we would have a black at number two. Right. Okay. >> And number one, >> delete everything else. True. Oh, I think I know what the problem is. I think we don't have the full lines at number four and five and six. So, maybe that doesn't I think the loops are are all wrong. >> Really? Yeah.

[\[33:40\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2020s) >> I mean I feel like it would need >> I mean you see that I mean I mean it it fails because >> the strings end I mean the I and J end here. You can see that. >> So >> it looks like this test is passing right? >> No it fails now. Oh you Oh yeah I thought that this Yeah because we still doing it right here. >> Okay. Yeah, we can re remove that >> at least one cell one for black, right? So, we should remove that.

[\[34:15\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2055s) >> Okay. >> So, this means the other test is failing, right? It's not this test that's failing. >> Well, I guess we can see that exactly by going to the tests >> the DSL. Okay. Okay. >> What do you think? >> I think it looks good. I think we should jump into the to the other tests and figure out why it's failing.

[\[34:46\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2086s) >> Okay. Maybe supposed to fail. >> Actually, I want to know why the other one test is passing. But >> well, let's let's replace this one as well. >> Okay. >> I think it will not pass now as well. Okay, nice. Is there something wrong with our hands still? Maybe. Hopefully.

[\[35:16\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2116s) Okay. So, I'm still scared that our DSL is wrong. So, let Why don't we replace all the other tests with the DSL? >> Okay. You want to comment these two tests out so we can see green? Yeah. Yeah, sure. Yes, that's a good idea. >> You want to keep it to the board? >> Yeah. So,

[\[35:52\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2152s) >> we're green. >> Yay. >> Everything works. >> Okay. I think it will be faster if you do it on your end. >> All right. So it really fast. It just copied from the simple tests. >> All right. Where who was that? Simple tests. Okay. So this one is get position status. Nope. It's not. >> Yeah. But we can we can say that there is no board. Oh, maybe not. Sure. But here would be good. >> Yeah. So this one was >> one and one.

[\[36:24\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2184s) >> I should I should have deleted first. And just one one. So be this one. Should I just comment it out for now? >> No, just delete it. We have source control, right? >> yeah, right. Okay, >> cool. >> This one's the same one as that. it's green. Oh, it's red. Oh, what did I do?

[\[36:56\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2216s) Hold on. A board get what? What? What? What did you replace? >> One one. >> No, there was one two. Okay. Yeah, it's the same board, but the get to position status is now different. Okay. So, okay. Replace it. Okay. >> Now, it fails. >> Okay. So, let's find the problem here. You want to debug it? >> Yeah.

[\[37:27\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2247s) >> Okay. >> So, all right. Where are we? Okay. I want to see the status of board first.

[\[37:57\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2277s) Empty one one should be filled. Everything else is filled. One, two, one. Everything else it's saying is filled. So, yeah. So, let's go to the fill board. So, okay. Okay. So, what's the best way to look at this? Should add another break point in here until it's one, two. It's going to be No, let's just let's just start see what happens.

[\[38:41\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2321s) So, one one should sell. Oh, it's because if there is no >> the cell is currently wrong. The cell it means one. So it it doesn't treat the one cells. The cell is a number. Cell is a number. >> Yeah. Look at the cell. You see it's right here, >> right? It's starting at one though.

[\[39:12\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2352s) What's the line? A line is Oh, it's looking at the How come this How come line is what? What's lines supposed to be >> first one? It starts at starts at one because we have a empty. We have a new line right here. >> Which new line we have? >> No. Which which new line do we have? Oh, this one. >> Yeah. >> Okay. So, we should always do what do you call it?

[\[39:44\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2384s) Trim on the string first. What do you call it? Trim or >> there's a function that removes all the all the extra stuff, all the extra spaces. >> All the extra Okay. >> from both sides. So, I think it's called trim. So, the way you do it is stone map equals mount dot trim.

[\[40:16\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2416s) Yeah, that's it. All right, let's try. No, I don't think it gets rid of empty lines. >> only it gets rid of all the spaces at the beginning and at the end, >> right? But the problem we're having is that empty line on the first on the first line. Right. >> Yeah. But that would have been trimmed. That's what I'm saying that if we put a break point here.

[\[40:46\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2446s) >> Yeah. Okay. >> Oops. >> Ah. Okay. You want to try and repeat that or let's see. Okay. >> Yeah. So, if you look at the stone map, there's still a dash end in the front. >> Oh, wait. We need to look into that. >> No, no, hold on.

[\[41:16\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2476s) Step to the next level. To the next step. >> Okay. >> Okay. So, you're right. It is trimmed. Okay. >> So now let's let's see what happens. Split by line. >> I think we should split by slash r/n maybe. Ah you're right. So this one should be right. Okay. So then one two.

[\[41:54\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2514s) This was sona. Yeah, you're right. - dash r. Okay. So, so we just slash r. So, we should split by slash r first, right? >> Okay. >> And then for each line, we would just say line i.trim. And that way you see now it passes. I didn't have to debug.

[\[42:25\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2545s) >> Nice. >> But I still went to debugging before I noticed. >>. >> All right. >> Okay. >> Cool. >> So now what if we uncomment the last test that was we're were passing when we expected them to fail. >> Okay. Just this one.

[\[42:57\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2577s) H. Okay. What about the the one just before? Can you do it? >> Okay. >> So, this one this one might be failing for the right reason. Maybe we don't have that feature. So we don't know. So let's replace all the other tests. >> So see what happens. >> No, I think this one we the winner should be black.

[\[43:27\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2607s) >> Some reason we have it white. >> But your [test name](https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html "Naming standards for unit tests (osherove.com)") is wrong in that. >> Well, this one's two blacks. Oh, one. Yeah, this one was this one was a copy of this one. >> And we didn't. And then >> Yeah, we we replaced the wrong test. Remember, you made a copy of this one and added DSL to it. But I never replaced the original the the one that should have been replaced. >> Yeah. So, this one's supposed to replace this one up here.

[\[43:58\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2638s) So, >> wait. But but this is the one that fails. >> Right. So, let's get this. Let's get rid of this one. This one's exact copy of the of the bottom one right here. >> Hold on. Yeah. I've got the phone fix anything while I was on the phone. >> No, I didn't.

[\[44:28\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2668s) >> Okay, cool. >> So, we should probably delete this one cuz it's a duplicate of the >> Are you sure? I thought it was the the the opposite of the one that was >> was that was green, >> right? So, now they're all passing right now. So we should I kind of want to look into I want to kind of dive into this and see. >> So these two tests we didn't expect them to pass. Right. >> Right. >> Did we replace but all the other tests? >> we have not replaced the other tests yet. >> So I think look because because I I have to finish soon.

[\[45:01\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2701s) So let why don't we finish up by fixing all the other tests with the DSL. >> Okay. >> And then we're going to have to finish for today. Maybe we'll continue at night but I really have to go and pack. >> Okay. No worries. Okay. So, let's replace the all the other test DSLs. Let's make sure we're on the right track and we'll have a good infrastructure to to run the test later. >> It's mindboggling for me though. Why it's not mindboggling, it's frustrating for me. >> It is mindboggling.

[\[45:31\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2731s) >> It's interesting. Why is it not passing? But this one should be >> She wants one white. >> Oh, how are we going to do the stuff where >> where what >> we >> where we don't because right now it's adding the stones. Well, I guess this is more like a setup. >> It's basically Yeah, it's set. How are we going to do what? >> So, like I'll show you in the next one.

[\[46:02\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2762s) Let me make sure this passing. Okay, so this one actually is not this one. Like this one right here. This test right here. So, >> sure. What's the problem? >> Well, I guess we just don't we don't >> we don't care. >> We don't I don't replace this bottom one right here. The one I highlighted, right? >> No, but here's the cool thing. You can use fill board three times. All it does is just sets sets up the locations, right? >> Oh, yeah.

[\[46:33\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2793s) >> So, you can >> That is cool. >> Yeah. So I can >> but would it would it make sense? >> I know. I think this is readable. So we can add one to two and two. >> I what what I'm saying is it's more readable if you just say add board after that. Add stone instead of two fill boards >> like this. >> Yeah. >> Actually, I think I might have written it incorrectly.

[\[47:04\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2824s) Sorry about that. >> so we have a Yeah. >> Yeah. I do this incorrectly. One, three. So, it's white right here. Black, two, three, and white and then white right here. So, >> isn't it so much more readable now? >> It is. I like and it's so it's easier to write.

[\[47:36\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2856s) >> So this is what they meant by DSL on one of your guys comments. >> Sure. >> So >> I don't think we don't we even need to go up to nine. We can just use like up to five >> because it only fills whatever it cares about. >> You want me So I should do that. >> No, I'm just saying that for the future test we can just make it >> Oh, for the future, right? >> Or just remove the past rows. Oh, I didn't need to do that.

[\[48:13\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2893s) >> Yeah, you can just remove rows six to nine here and that's it. >> Yeah. >> Control shift L. >> Sorry, >> I can do that. Let me cop this one.

[\[48:47\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2927s) Nice. I I think it's Yeah, I think it's nice this way. Hold on. I think that's the last one, right? Oh, no. We still have one more. Okay. >> Yeah. Got a little bit left.

[\[49:21\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2961s) >> I think it will actually work because we do trim even if you tap the the string more to the right. So, it will be more into the middle of the code. I can try that. >> Yeah. >> How how far should I put it? >> Just after I think just after the at sign. >> Okay. >> Yeah. >> I think that's more readable. What do you think? >> I think so, too. >> Okay.

[\[49:59\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=2999s) Hold on. Don't touch anything. >> I guess this NCrunch is pretty cool. >> Yeah, I kind of like it after the initial annoying setup. It's pretty cool. Yeah, I haven't pressed saved yet, so that's a little bit bothersome. I don't know if it's automatically saving for me.

[\[50:29\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=3029s) >> Obviously, otherwise you couldn't run tests. Looks even prettier than before. >> Very cool.

[\[51:44\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=3104s) I should remember black 31. All right, I think that's all of it. Nice. Time to commit. Let me tap this. F.

[\[52:22\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=3142s) What happened? That's not nice.

[\[52:59\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=3179s) >> Are you getting close? >> Almost done. >> Almost. I'm just tabbing these things here, dear. Don't worry. >> No, it's really important. You see, honey. >> All right, cool. >> Now we're done. >> All right, save it. Commit. >> Can you do it on so Yeah, so viewers can see. Cool.

[\[53:39\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=3219s) Should I remove the in front project? I'll just check it for now. >> Sure. So added DSL for about not sure why tests are passing. Last two tests are passing. >> Yeah. >> Cool. >> Cool. All right. Very cool.

[\[54:09\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=3249s) >> Okay. Where's Where's my push? There you go. Okay, Raymond. Let's do let's do another one, I guess, tomorrow. No, no, tomorrow. Yeah, maybe tomorrow. We'll see what happens. But maybe tonight. So, cool. Hopefully that was that was informative to to the viewers as well. It's mindboggling because I'm sure I did the same test and it failed when I did it.

[\[54:45\]](https://www.youtube.com/watch?v=TGTnFqtIWQ0&t=3285s) I don't know. Maybe I skipped this step. >> I don't know why it's passing out. I'm kind of I'm probably going to dive into it right after and see why. >> So, if you have any any insights later, we can we can talk about them in the future episode. >> Okay, >> cool. See you, Raymond. See you, viewers. >> Thank you.

## Related

- [Building a test API for your application](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-7#ch07lev1sec6) · The Art of Unit Testing, 2nd ed., ch. 7

    Book section on building a test API for your application, which is what the string board DSL becomes.

- [Writing readable tests](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-8#ch08lev1sec3) · The Art of Unit Testing, 2nd ed., ch. 8

    Book section on writing readable tests, the goal behind drawing the board as text with B and W stones.

- [The role of helper frameworks in your tests](https://osherove.com/blog/2005/1/15/the-role-of-helper-frameworks-in-your-tests.html) · osherove.com

    On test helpers that replace object-creation clutter in growing tests, like the board-parsing helper built here.

- [Smelling a false sense of trust in passing tests](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition/chapter-7) · The Art of Unit Testing, 3rd ed., ch. 7

    Book section on smelling false trust in passing tests, as the territory tests pass unexpectedly and puzzle the pair.

### Also linked in this lesson

#### The Art of Unit Testing, 3rd ed.

- [The library, the assert, the runner, and the reporter](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition/chapter-2#sigil_toc_id_37), ch. 2
- [How to know you trust a test](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition/chapter-7#sigil_toc_id_134), ch. 7

#### osherove.com

- [Test Coverage and testing angles](https://osherove.com/blog/2005/4/3/test-coverage-and-testing-angles.html)
- [TDD: 4 questions that will help you create the simplest thing that could possibly work](https://osherove.com/blog/2010/1/6/tdd-4-questions-that-will-help-you-create-the-simplest-thing.html)
- [Naming standards for unit tests](https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html)

[Previous lesson Total Noob Fail](https://courses.osherove.com/courses/tdd-pairing-sessions-building-a-go-game/total-noob-fail/) [Next lesson A Refactoring Dillemma](https://courses.osherove.com/courses/tdd-pairing-sessions-building-a-go-game/a-refactoring-dillemma/)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
