Back to Fpinscala

18.Answer

answerkey/testing/18.answer.md

latest796 B
Original Source

Requiring as.takeWhile(f).forall(f) == true doesn't enforce that takeWhile returns the longest possible prefix for which the property holds. To verify that, we could introduce another property which says the head of the remaining list, if not empty, must fail the predicate -- something like !f(as(as.takeWhile(f).size)), but handling the case where as.size == as.takeWhile(f).size.

Another property describes how takeWhile and dropWhile relate -- concatenating the result of calling takeWhile with the result of calling dropWhile on the same list should result in that same list.

If we try to write any of these properties using our library, we'll run in to an issue. Each of these properties requires a Gen[Int => Boolean], but we don't have a way of generating functions.