AI-Generated Property-Based Fizz-BuzzWords - Now with Dark Mode

Опубликовано: 16 Август 2024
на канале: Pairing with Duncan
423
34

It was only while I was editing the first video in this series that I realised that the code could overflow its integer counter (after two billion or so rounds) and start counting up with negative numbers. Whilst its unlikely that FizzBuzz overflow could blow up a rocket, the point of kata is to practice our skills in a safe environment, so I’m not going to just shrug this off - we should learn from the experience.

If we had a quality assurance department they might have caught the error, but we prefer a process where developers find these things before committing. Maybe a pull request review would have caught the issue, or the extra pair of eyes from pair programming; but today I’m going to look at whether property-based testing would have helped.

Property-based testing frameworks automatically generate example inputs for our code. Those inputs are crafted to try the sorts of values that might break our code; empty strings, negative numbers, or, relevant here, very large numbers. My theory is that if we craft our interface to allow the tests to find errors, they will find errors.

Oh, and because I’ve already forgotten how to use the jqwik property-based testing library, I’ll be leaning on AI Assistant more than usual, so that will be interesting too.

In this episode

00:01:10 Dark mode!
00:01:27 We're starting from acceptance tests
00:01:37 We had an overflow bug, could we have caught it with property-based testing?
00:02:23 AI Assistant generates plausible property-based tests
00:03:57 Still no shortcut for new AI chat
00:04:19 AI does conversions faster than I could
00:07:33 Commit that commendable effort
00:08:07 AI does a good job of implementing one function in terms of another
00:08:56 AI Assistant bug
00:10:01 Commit
00:10:10 AI continues to do our work for us
00:14:50 Our new tests miss the point though
00:15:59 Lets let jqwik specify the start and the number of rounds
00:18:33 That makes us change the function interface
00:19:24 Now we can finally check that our numbers don't overflow
00:21:23 In the end, examples are lower friction than propreties here
00:23:04 Finally we have tests to drive not overflowing
00:23:43 Ah, but what about negative FizzBuzz
00:27:29 Unsuccessful experiments still yield information

There is a playlist of FizzBuzz episodes    • FizzBuzz  

The code is on GitHub https://github.com/dmcg/FizzBuzz/tree...

I get lots of questions about the test progress bar. It was written by the inimitable @dmitrykandalov. To use it install his Liveplugin (https://plugins.jetbrains.com/plugin/...) and then this gist https://gist.github.com/dmcg/1f56ac39...

If you like this video, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (http://java-to-kotlin.dev). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style.


Смотрите видео AI-Generated Property-Based Fizz-BuzzWords - Now with Dark Mode онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Pairing with Duncan 16 Август 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 423 раз и оно понравилось 34 людям.