From Example-based unit-tests to property testing

I recently wrote about how many unit-tests one needs to write to reduce the number of faults in programs. One of the conclusion one can have is that this is a big number of tests to write! Surely, nobody have time to write that many tests by hand! That’s where property testing enters the scene. 1. A simple function: toUpper Imagine you have to write a new function named toUpper that takes a string as input, and returns the same string, but in upper case.

How Many Unit-tests?

Writing unit-tests is an integral part of writing software. How many tests are needed? What coverage target should one aim for? What’s coverage anyway? Follow along on this quick journey, where I wonder those very questions. 1. Why do we need any tests? First and foremost, why would you need any tests, if you could simply prove that the program is right? After all, in mathematics, if we assume that there are an infinite number of prime numbers for example, we can just prove it, and we don’t have to test all numbers to check that this statement is true.

Java: The Expression Problem & Object Algebras

I am going to have a look at the Expression Problem starting from a simple floral code. Once the problem is faced, I’ll state it formally, and then I’ll have a look at the functional side of things. I’ll finish with solutions that appear in the literature, and see if any is easy to implement in Java. 1. OOP Flowers I enjoy flowers, and I want to break from the usual examples given in code (Java here).

Book review: Humble Pi, by Matt Parker

Humble Pi, A Comedy of Maths Errors is a book by Matt Parker, released in 2019. The book is a fun read of maths mistakes that have consequences in the real world. This is not a book about formulas, nor is it about theorems, proofs, or how not to make mistakes in maths. The author states in the introduction that one of the purposes of the book is to show that maths is not always about being right, but more about the process of exploring the mathematical world.

Java: refactoring logic & impure functions for unit-tests

This is a small Java Coding Dojo where we analyze a piece of code given to us. Our mission is to unit-test it. You can find all of the code from this article in its git repository. 1. The code Here is the code we are given: import; import; import java.nio.file.Files; import java.nio.file.Path; public final class Base { public static String readOrDefault(final String path) { final var file = new File(path); if (!