WEBVTT NOTE This file was generated by Descript 00:00:00.690 --> 00:00:01.170 Manuel (2): All right. 00:00:01.440 --> 00:00:08.670 So this is going to be a tiny made up example of how to do test driven 00:00:08.670 --> 00:00:12.471 development with large language models. 00:00:12.473 --> 00:00:18.443 have an empty go project here and I want to write the first function 00:00:18.473 --> 00:00:21.473 that I want to write is because I'm generating Excel sheets. 00:00:22.253 --> 00:00:28.463 I kind of want to have something that transforms a column index and 00:00:28.463 --> 00:00:31.853 to a column name with characters. 00:00:31.853 --> 00:00:34.793 So for example, one would go to a. 00:00:35.453 --> 00:00:40.463 And then things like if you had 27, it would go to AA, for example. 00:00:41.183 --> 00:00:50.903 So the first thing I'm going to do is I'm gonna write a little text, 00:00:51.233 --> 00:00:52.763 because this is human language, right? 00:00:52.793 --> 00:01:01.313 So this function transforms a column index, an integer, into a string that 00:01:01.313 --> 00:01:05.573 can be used to designate an Excel column. 00:01:07.403 --> 00:01:08.333 Good way to start. 00:01:08.346 --> 00:01:10.811 Maybe that's kind of what I would do as a documentation, 00:01:10.811 --> 00:01:12.632 if I were to program normally. 00:01:13.262 --> 00:01:17.192 So now that I have that, I'm going to think about an API for this, 00:01:17.192 --> 00:01:18.332 I'm going to think really hard. 00:01:20.552 --> 00:01:21.812 I have an API for this. 00:01:23.552 --> 00:01:28.952 It's going to be called ColumnIndexToColumnAlphaString and 00:01:28.952 --> 00:01:33.302 it's going to take an index as an integer, it's going to return a string. 00:01:34.022 --> 00:01:36.722 So, that's my function. 00:01:38.342 --> 00:01:45.722 Obviously, this is kind of simple enough that I would, you know, that 00:01:45.722 --> 00:01:50.702 I can write most of the unit cases by myself, but I think that makes for for 00:01:50.702 --> 00:01:56.742 a good example to put into ChatGPT. 00:01:57.392 --> 00:02:00.882 So you're going to put it in here and I'm going to ask ChatGPT, 00:02:00.933 --> 00:02:05.823 what are some edge cases I should consider when writing the following? 00:02:06.663 --> 00:02:09.183 And go, I don't think, I even need to say that it's go. 00:02:09.693 --> 00:02:15.363 What are edge cases I should be considering, and I'm actually 00:02:15.963 --> 00:02:17.733 to not confuse it too much. 00:02:18.303 --> 00:02:21.363 I'm just going to remove what looks like an implementation. 00:02:22.053 --> 00:02:25.600 And writing the following function in go. 00:02:25.600 --> 00:02:28.044 I'm just going to ask it like a list of edge cases. 00:02:35.784 --> 00:02:37.054 So those are pretty good, right? 00:02:38.784 --> 00:02:42.454 And this case, I could ask ChatGPT to just generate the unit test for me. 00:02:43.674 --> 00:02:47.274 Which is, you know, it's fine cause this is simple enough, but however, 00:02:47.634 --> 00:02:50.664 I'm going to assume that my unit tests are a little bit more complicated. 00:02:50.664 --> 00:02:53.514 I've got like a slightly more complicated domain to deal with. 00:02:53.574 --> 00:02:57.854 Maybe I've got some abstractions, which ChatGPT knows nothing about 00:02:57.854 --> 00:03:00.894 cause all its context that it has is the name of my function, really. 00:03:01.374 --> 00:03:09.564 So what I'm going to do here is I'm going to paste this in here and maybe I'm going 00:03:09.564 --> 00:03:15.204 to write, you know, I'm actually going to go to the test function and I'm going to 00:03:15.204 --> 00:03:22.014 write test ColumnIndexToColumnAlphaString. 00:03:22.344 --> 00:03:31.214 So, the first test I'm going to do is TestSimpleColumnIndexToString 00:03:32.934 --> 00:03:35.514 and it's going to take a testing T. 00:03:36.084 --> 00:03:42.184 And then I'm going to make my column index as equal to one. 00:03:44.934 --> 00:03:46.434 So actually, do we want to start at zero? 00:03:46.494 --> 00:03:50.134 We want to start at zero, we're normal programmers. 00:03:51.834 --> 00:03:54.934 I'm making this a little bit more verbose on purpose. 00:03:56.034 --> 00:03:58.194 I'm going to assume that this is a more complicated 00:03:58.194 --> 00:04:00.634 scaffolding that I have going on. 00:04:02.874 --> 00:04:11.214 So instead of just testing this inline, I'm going to put this in here, right? 00:04:11.334 --> 00:04:15.084 It's like, this is my expected, this is my thing here. 00:04:15.534 --> 00:04:22.284 And then gonna do testify dot assert. 00:04:23.574 --> 00:04:29.364 And then now it knows that we're using testify, and everything's great. 00:04:29.934 --> 00:04:35.064 So actually, I do need to install testify. 00:04:35.574 --> 00:04:41.664 What is the package name of the testify library, because 00:04:41.664 --> 00:04:43.024 I'm too lazy to Google it. 00:04:44.814 --> 00:04:47.154 It's often wrong when you do this kind of stuff. 00:04:47.364 --> 00:04:49.954 So, you know, be mindful of it. 00:04:52.884 --> 00:04:56.064 So, what did I call this? 00:04:56.184 --> 00:04:56.604 There we go. 00:05:01.524 --> 00:05:03.864 I'm sure there's a way to do this in the IDE, but... 00:05:05.454 --> 00:05:07.364 All right, let's let it re-index. 00:05:09.174 --> 00:05:11.614 And it's not called assert. 00:05:16.944 --> 00:05:19.104 I think it's called assert equal. 00:05:19.974 --> 00:05:20.664 Alright, there we go. 00:05:21.684 --> 00:05:22.254 So. 00:05:26.034 --> 00:05:30.724 This is our first unit test, gives our model a little, you know, a 00:05:30.724 --> 00:05:32.784 little slice of the style we want. 00:05:32.964 --> 00:05:38.394 To make it more funky let's add like, let's add some comment, 00:05:39.284 --> 00:05:45.654 assert that column zero is "A", just so that it picks up on it. 00:05:45.684 --> 00:05:48.454 And so now I do have these here, right? 00:05:50.904 --> 00:05:55.062 Where I literally just pasted the code in here. 00:05:55.132 --> 00:05:58.432 So anyway, negative input values of not valid to return 00:05:58.462 --> 00:05:59.872 an error or an empty string. 00:05:59.902 --> 00:06:01.492 I'm going to assume that it's an empty string. 00:06:01.912 --> 00:06:08.132 So I'm going to call this func TestNegativeColumnIndexToString 00:06:08.152 --> 00:06:10.612 and I'm just going to tab complete it and probably... 00:06:10.762 --> 00:06:12.903 See how it matches the structure. 00:06:15.403 --> 00:06:19.233 Right, it didn't try to do a shortcut, it actually puts this in 00:06:19.233 --> 00:06:22.463 here, and so now we can do the rest. 00:06:25.023 --> 00:06:29.763 And we're going to, we're going to have a look at the end to make sure that 00:06:30.033 --> 00:06:31.543 you know, that they're roughly correct. 00:06:34.083 --> 00:06:35.043 So come on... 00:06:36.063 --> 00:06:37.563 Sometimes it takes a little bit. 00:06:41.223 --> 00:06:43.593 And edge test case of this... 00:06:44.883 --> 00:06:48.333 and what I'm missing here is, I'm just testing the edge cases. 00:06:48.363 --> 00:06:50.083 And I'm curious about all of that. 00:06:51.243 --> 00:06:59.073 But what are some nice normal unit things, inputs, outputs to test 00:06:59.103 --> 00:07:03.543 to complement the edge case tests. 00:07:08.035 --> 00:07:11.845 All right, so this is nice, it gives us a table and we could write our table 00:07:11.845 --> 00:07:13.945 driven unit tests like this, but... 00:07:14.005 --> 00:07:24.655 "write a table driven unit test for these values using the testify/assert library". 00:07:26.665 --> 00:07:31.975 And then it has seen so many table driven unit tests that will 00:07:32.065 --> 00:07:33.785 usually get this, like no problem. 00:07:35.125 --> 00:07:37.925 And then I can just copy the code and... 00:07:38.765 --> 00:07:39.995 We have a simple test here. 00:07:40.835 --> 00:07:44.455 And then actually what I realized is this one is one-index based, so 00:07:44.935 --> 00:07:49.355 "instead of using one for a use zero". 00:07:52.825 --> 00:08:01.435 And so, this is really nice to steer it in that way because I'm 00:08:01.465 --> 00:08:04.075 at a human language level, right? 00:08:05.425 --> 00:08:12.955 And so "use zero, but then use 10, 25, et cetera." 00:08:13.375 --> 00:08:18.495 So you can give it these very quick ideas on how to refactor stuff, but you don't— 00:08:18.715 --> 00:08:20.065 ah, it didn't catch it on this one. 00:08:22.785 --> 00:08:26.515 Anyway, we're going to take this and we're going to paste it in here. 00:08:28.485 --> 00:08:32.755 The cool thing is that it gives you like full usable things that uses assert.Equal. 00:08:34.185 --> 00:08:38.485 And potentially we, you know, we could have it insert a comment here. 00:08:39.945 --> 00:08:42.345 So convert table... 00:08:44.775 --> 00:08:49.765 table driven value, something like that. 00:08:50.625 --> 00:08:54.165 This one doesn't have a comment on top of it, so I could either use this 00:08:54.165 --> 00:09:00.432 one here or it could just use what copilot produces and here we have like 00:09:00.432 --> 00:09:06.582 a pretty complete test, there there's some invalid things here that we like 00:09:06.582 --> 00:09:08.112 we should of course read overdose. 00:09:08.112 --> 00:09:10.842 I'm not going to do it as in this example, there's some of 00:09:11.022 --> 00:09:13.542 these are just not good, right? 00:09:13.662 --> 00:09:15.472 The input parameters should be an integer. 00:09:17.052 --> 00:09:19.152 This is not a go thing. 00:09:19.362 --> 00:09:20.802 So we'll remove that. 00:09:20.862 --> 00:09:23.142 And then we can test all of these. 00:09:23.142 --> 00:09:24.772 So potentially these are off by one. 00:09:26.712 --> 00:09:31.272 This kind of pattern matching fuzziness is something you get a good feel for. 00:09:32.052 --> 00:09:34.062 And here we have it.