-
Notifications
You must be signed in to change notification settings - Fork 5
/
live10a.fsx
82 lines (52 loc) · 1.62 KB
/
live10a.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Lecture 10 the other part
#if INTERACTIVE
#r @"C:\Users\kasutaja\Documents\Visual Studio 2012\Projects\Library2\packages\FsCheck.0.9.1.0\lib\net40-Client\fscheck.dll"
#endif
let revRevIsOrig (xs: list<int>) = List.rev(List.rev xs) = xs
open FsCheck
Check.Quick(revRevIsOrig)
Check.Verbose(revRevIsOrig)
let revIsOrig (xs : list<int>) = List.rev xs = xs
Check.Quick revIsOrig
type ListProperties =
static member ``reverse of reverse is original`` xs = revRevIsOrig xs
static member ``reverse is original`` xs = revIsOrig xs
Check.QuickAll<ListProperties>()
let revRevIsOrigFloat (xs: list<float>) = List.rev(List.rev xs) = xs
Check.Quick(revRevIsOrigFloat)
let rec ordered xs =
match xs with
|[] -> true
|[x] -> true
| x::y::ys -> (x <= y) && ordered (y::ys)
let rec insert x xs =
match xs with
| [] -> [x]
| c::cs -> if x <= c then x::xs else c:: (insert x cs)
let Insert (x : int) xs = ordered xs ==> ordered (insert x xs)
Check.Quick(Insert)
let EagerProp a = a <> 0 ==> (1/a = 1/a)
Check.Quick(EagerProp)
let LazyProp a = a <> 0 ==> lazy(1/a = 1/a)
Check.Quick(LazyProp)
open System
open FsCheck.Prop
let ExpectDivideByZero() =
throws<DivideByZeroException, _>
(lazy (raise <| DivideByZeroException()))
Check.Quick(ExpectDivideByZero)
open FsCheck.Prop
let timeout (a : int) =
lazy (
if a> 10 then
while true do System.Threading.Thread.Sleep(1000)
true
else
true )
|> within 2000
type Tree = Leaf of int | Branch of Tree * Tree
let RevRevTree (xs:list<Tree>) =
List.rev (List.rev xs ) = xs
Check.Quick(RevRevTree)
Check.Verbose(RevRevTree)