Skip to content

Instantly share code, notes, and snippets.

View CoditCompany's full-sized avatar
👋
You can find us on @CoditEU

Codit CoditCompany

👋
You can find us on @CoditEU
View GitHub Profile
[<Property>]
let ``PositiveInt don't gets created if value is negative`` () =
Arb.generate<int>
|> Gen.filter ((>) 0)
|> Arb.fromGen
|> Prop.forAll <| fun x ->
None = posInt x
[<Property>]
let ``PositiveInt gets created if value isn't negative`` (FsCheck.PositiveInt x) =
public class ISBN13
{
public ISBN13(string value)
{
ValidateStringNullOrEmpty(value);
ValidateStringLength(value, 13);
ValidateStringMatches(value, "[0-9]{9}");
ValidateISBNCheckSum(value);
}
type ISBN13 = private ISBN13 of string
let ifTrueThen x = function
| true -> Some x
| false -> None
let (|NullOrEmpty|_|) =
String.IsNullOrEmpty
>> ifTrueThen NullOrEmpty
type Book =
{ ISBN13 : string
Author : String50
Pages : PositiveInt }
public class String50
{
public String50(string value)
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentException(nameof(value));
}
if (value.Length > 50)
type String50 = private String50 of string
let ifTrueThen succ = function
| true -> Some succ
| false -> None
let (|NullOrEmpty|_|) =
String.IsNullOrEmpty
>> ifTrueThen NullOrEmpty
type Book =
{ ISBN13 : string
Author : string
Pages : PositiveInt }
let (|Negative|_|) x = if x < 0 then Some Negative else None
let posInt x = function
| Negative -> None
| x -> Some <| PositiveInt x
type PositiveInt = private PositiveInt of int
let posInt x = function
| x when x < 0 -> None
| x -> Some <| PositiveInt x
type Book =
{ ISBN13 : string
Author : string
Pages : int }