AI Assistant vs Property-based Tests

Опубликовано: 22 Март 2024
на канале: Pairing with Duncan
478
28

Our type-driven 10 pin bowling simulator is pretty much done, but I still have nagging doubts about whether our scoring is correct.

At the moment the tests for scores are based on some example games that I dreamt up, plus a single test that all strikes scores 300, and a property-based test that if we never roll a strike or a spare, the score is the sum of the rolls. In order to have full confidence we definitely need more tests, but manually creating them and doing sums to work out what the score should be would be tedious and error-prone.

Computers are supposed to save us from tedium and errors, and I’ve seen a lot of people using AI for test generation, so today I’m going to ask AI Assistant for help. The results are interesting, but not yet good enough. So I went back to property based testing and found a way to combine jqwik (https://jqwik.net/) with AI generated code that gives the confidence that I wanted for very little effort on my part.


In this episode

00:01:03 Fixing a rendering issue we found with random games
00:01:57 The issue is in the definition of spare in final frames
00:03:19 Commit
00:03:42 Review our current scoring tests
00:04:59 Lets try generating some more tests with AI Assistant
00:06:14 They pass and are useful : +1 to AI Assistant
00:07:05 A more complicated test doesn't pass
00:07:57 That was a miserable failure
00:08:21 We can't negotiate, so let's try again as a chat
00:09:07 Pick and choose what to tests to import
00:10:22 Negociate over style
00:10:47 More, more, I'm still not satisfied
00:12:34 Oh hold on, I wasn't actually running those new tests
00:13:19 Debug to learn what is wrong with the AI generated code
00:16:37 Now we made them work let's check the AI tests in
00:16:59 Could we do better with properties?
00:17:23 How about comparing our score with an independent algorithm
00:18:43 Minor IntelliJ bug dragging a selection in AI Assistant
00:19:07 Create a property that the score is like the other function generates
00:20:41 It works! Lets check what it is actually doing
00:21:23 Final tidy
00:22:58 Final commit
00:23:17 Final doubts

You can see the code on GitHub https://github.com/dmcg/bowling-for-y... and this miniseries in a playlist    • Bowling Kata  

If you like this, 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 Assistant vs Property-based Tests онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Pairing with Duncan 22 Март 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 478 раз и оно понравилось 28 людям.