let square (x:float) = x * x
square 10.0
// fsharp.formatting // fsharp project scaffold
// 1. promote script to unit test // 2. promote script to documentation // 3. discard :)
type Boolean = | True | False
let printBool (bool:Boolean) = match bool with | True -> "TRUE" | False -> "FALSE"
printBool False
type Result = | Success of float | Failure of string
let safeDivide x y = if y = 0.0 then Failure("Diviside by Zero") else Success(x/y)
let printDivide x y = match (safeDivide x y) with | Success(value) -> printfn "%f" value | Failure(msg) -> printfn "%s" msg
type Tree = | Leaf of int | Branch of Tree * Tree
let tree = Branch( Leaf(1), Branch( Leaf(2), Leaf(3)))
let rec sum acc (tree:Tree) = match tree with | Leaf(v) -> acc + v | Branch(left,right) -> let leftT = sum acc left let rightT = sum acc right leftT + rightT
sum 0 tree
// xunit, nunit // fsunit -> less now // unquote
#I "./packages/" #r "unquote/lib/net40/unquote.dll"
open Swensen.Unquote
test <@ square 2.0 = 4.0 @>
#r "fscheck/lib/net45/fscheck.dll" open FsCheck
let square should always be positive
x =
square x >= 0.0
Check.Verbose square should always be positive
// -infinity * (-infinity) > 0.0
https://fsharpforfunandprofit.com/posts/property-based-testing/ https://fsharpforfunandprofit.com/posts/roman-numeral-kata/ http://blog.ploeh.dk/2015/02/23/property-based-testing-without-a-property-based-testing-framework/ http://brandewinder.com/2014/03/22/fscheck-and-xunit-is-the-bomb/