1
exercism fetch fsharp list-ops

ListOpsTest.fs

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
module ListOpsTest

open Xunit
open FsUnit.Xunit

open ListOps

let big = 100000
let bigList = [1 .. big]
let odd x = x % 2 = 1

[<Fact>]
let ``length of empty list`` () =
    length [] |> should equal 0

[<Fact(Skip = "Remove to run test")>]
let ``length of non-empty list`` () =
    length [1 .. 4] |> should equal 4

[<Fact(Skip = "Remove to run test")>]
let ``length of large list`` () =
    length [1 .. big] |> should equal big

[<Fact(Skip = "Remove to run test")>]
let ``reverse of empty list`` () =
    reverse [] |> should be Empty

[<Fact(Skip = "Remove to run test")>]
let ``reverse of non-empty list`` () =
    reverse [1 .. 100] |> should equal [100 .. -1 .. 1]

[<Fact(Skip = "Remove to run test")>]
let ``map of empty list`` () =
    map ((+) 1) [] |> should be Empty

[<Fact(Skip = "Remove to run test")>]
let ``map of non-empty list`` () =
    map ((+) 1) [1 .. 2 .. 7] |> should equal [2 .. 2 .. 8]

[<Fact(Skip = "Remove to run test")>]
let ``filter of empty list`` () =
    filter id [] |> should be Empty

[<Fact(Skip = "Remove to run test")>]
let ``filter of normal list`` () =
    filter odd [1 .. 4] |> should equal [1; 3]

[<Fact(Skip = "Remove to run test")>]
let ``foldl of empty list`` () =
    foldl (+) 0 [] |> should equal 0

[<Fact(Skip = "Remove to run test")>]
let ``foldl of non-empty list`` () =
    foldl (+) -3 [1 .. 4] |> should equal 7

[<Fact(Skip = "Remove to run test")>]
let ``foldl of huge list`` () =
    foldl (+) 0 [1 .. big] |> should equal (big * (big + 1) / 2)

[<Fact(Skip = "Remove to run test")>]
let ``foldl with non-commutative function`` () =
    foldl (-) 10 [1 .. 4] |> should equal 0

[<Fact(Skip = "Remove to run test")>]
let ``foldl is not just foldr . flip`` () =
    foldl (fun acc item -> item :: acc) [] (List.ofSeq "asdf") |> should equal (List.ofSeq "fdsa")

[<Fact(Skip = "Remove to run test")>]
let ``foldr as id`` () =
    foldr (fun item acc -> item :: acc) [1 .. big] [] = bigList |> should equal true

[<Fact(Skip = "Remove to run test")>]
let ``foldr as append`` () =
    foldr (fun item acc -> item :: acc) [1 .. 99] [100 .. big] = bigList |> should equal true

[<Fact(Skip = "Remove to run test")>]
let ``append of empty lists`` () =
    append [] [] |> should be Empty

[<Fact(Skip = "Remove to run test")>]
let ``append of empty and non-empty lists`` () =
    append [] [1 .. 4] |> should equal [1 .. 4]

[<Fact(Skip = "Remove to run test")>]
let ``append of non-empty and empty lists`` () =
    append [1 .. 4] [] |> should equal [1 .. 4]

[<Fact(Skip = "Remove to run test")>]
let ``append of non-empty lists`` () =
    append [1 .. 3] [4; 5] |> should equal [1 .. 5]

[<Fact(Skip = "Remove to run test")>]
let ``append of large lists`` () =
    append [1 .. (big / 2)] [1 + big / 2 .. big] = bigList |> should equal true

[<Fact(Skip = "Remove to run test")>]
let ``concat of no lists`` () =
    concat [] |> should be Empty

[<Fact(Skip = "Remove to run test")>]
let ``concat of list of lists`` () =
    concat [[1; 2]; [3]; []; [4; 5; 6]] |> should equal [1 .. 6]

[<Fact(Skip = "Remove to run test")>]
let ``concat of large list of small lists`` () =
    concat (map (fun x -> [x]) [1 .. big]) = bigList |> should equal true