ChatGPT writes C# code and test code (ChatGPT Coding)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right today I want to show you how you can leverage chat GPT to write software help you write tests for software this is going to be something that's going to be very big in the future you have to leverage the power behind artificial intelligence and uh I just as also there's a disclaimer I do not want to have you believe that this is the way to write software but it will help in doing some trivial tasks maybe helping you come up with some different test cases for your code and you should always however you should always conduct reviews with your colleagues with your Architects and with test Engineers to make sure that you are following all the proper guidelines that your organization has so let's just jump into a real quick example we can just type down here into the chat GPT chat line we can chat uh type for instance um write C sharp code that will uh list what do we want to say uh Rob's right C sharp code that will list up to 500 prime numbers so now the AI is going to spit out for us code that will do this it takes you step by step through it so even if you're if you'd never even have programmed anything in your life you can use uh you can use the chat bot here to create code for you so I don't know if this runs I have no idea if this is actually going to be code that you can use but what it also does is here you can see how it's showing you what the code does it explains to you in plain text what it's doing and and then we can just kind of scroll up and we can kind of look and see okay this is how how it determines to call the namespace and then this made the class declaration and so on and so forth so um looks to be rather trivial again it was a rather trivial um assignment for the chat GPT and so now what we can do is we can take it a step further we can actually say okay thanks now using end unit because end unit is a common test framework for net for c-sharp thanks now using n unit right um test cases to test the code and so now check GPT is going to spit out for me a test class and we can see what it's showing me um actually this is not even really doing what I intended actually what it does is it is giving me a prime number or telling me if a certain number is prime or not but this is nonetheless interesting what it's spitting out here so it's going through has three test cases so far now four test cases so and now it's telling me too the test cases cover a range of different input values including prime numbers composite numbers negative numbers and special cases like zero and one you can add more test cases if you need needed to thoroughly test the is prime function now I just myself just realized that this is not exactly what I wanted it to do I wanted it to give me up to 500 prime numbers here however it just checks if a number is prime so let's uh let's fine tune this a little bit and let me refine my requirement and say okay thanks again but now I just want code that will output the first 500 prime numbers starting let's say starting with with five so now we even says it's a modified version of C sharp program that will output the first 500 prime numbers starting with five okay so it's giving me a count it's giving me the number while the count is less than 500 if is prime number uh write line number count plus plus okay so it increments the count it increments the number so it's going to go through a loop there to first check it and it writes this is prime function which will determine if a number is prime or not if it is prime then it will as we can see here in the top here if it is prime it will write out that number so this is doing a little bit more of what I wanted to do so I had to I had to be a little bit more specific in my requirements for uh the chat GPT to figure out what I want um and now I'll just go back and basically do the same thing but ask it to right now to write for me some test cases so let's say now write test cases using n unit to verify the program okay so here's some test cases you use to verify the modified version of the program using end units so the same thing and as you can see it does it rather quickly um what I think is actually kind of cool is that you can actually see looks like it's typing something so it's going like basically character for character but it's actually just writing out chunks I think certainly the UI or the AI is probably has already a snapshot of what it has in mind to do and it just basically types it out so that you can read it kind of in real time otherwise you'd have like a big block of of information just being spit out so let's see here this test case uses a string writer okay so uses a string right to capture the output of the program and then Compares it to the expected output which is a string containing the first 500 numbers starting with five okay so this is only one test case um yeah because I spec because of my specification said I want them to print out the first 500 Prime starting with five so here is just of course um it knows what those first 500 prime numbers are and writes out the expected output let me check this if this is correct weight so as a string writer um the string the expected output now here it says it's basically a blank string or an empty string so now here's the for Loop if the program has a is the prime number starting with that number then the outs expected output but I don't see where uh okay so basically as the program right the program here will um basically run the entire program so it will write to this stream string writer the results of the call to the program and here it's building the expected output and once it builds the expected output then it compares the expected output which it built here to the um to the string that was made with a string writer so this is a really interesting way to use chat GPT you can use it for you know for writing scripts even you could probably use some kind of uh if you have a particular API that you're using for test cases you can probably use this as well for writing scripts to facilitate the execution of tests this is just scratching the surface so if you like this type of content please hit like hit subscribe and we'll try to get more content like this out to you in the next coming days thanks a lot
Info
Channel: Software Quality Think Tank
Views: 3,510
Rating: undefined out of 5
Keywords: ChatGPT, Software, C#, coding, chatgpt coding
Id: sOVt-8T2a5k
Channel Id: undefined
Length: 8min 55sec (535 seconds)
Published: Mon Jan 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.