F# List Manipulation and Property-Based Testing with FsCheck
Classified in French
Written on in English with a size of 4.23 KB
F# List Manipulation and Property-Based Testing
This document provides F# code examples demonstrating list manipulation techniques and property-based testing using FsCheck.
Setting up FsCheck
#r "FsCheck";;
open FsCheck;;
Tagged Value Exercises: Some and None
This section explores the use of tagged values (also known as discriminated unions) and the Some
and None
options in F#.
Defining a Shape Type
type figura =
| Rettangolo of float * float // base * altezza
| Quadrato of float // lato
| Triangolo of float * float ;; // base * altezza
Calculating Area with Option Type
let areaOpt fig =
match fig with
| Rettangolo (b,h) -> if b>0.0 && h>0.0 then Some (b*h) else None
| Quadrato (l) -> if l>0.0 then Some (l*l) else None
|
... Continue reading "F# List Manipulation and Property-Based Testing with FsCheck" »