-
Notifications
You must be signed in to change notification settings - Fork 5
/
live9lib.fs
63 lines (44 loc) · 1.7 KB
/
live9lib.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
namespace Lecture9
module myFunctions =
let getLongestBroken (names: list<string>) =
names |> List.maxBy (fun name -> name.Length)
let getLongest (names: list<string>) =
match names with
| [] -> ""
| _ -> names |> List.maxBy (fun name -> name.Length)
let partitionMultiWord (names: list<string>) =
names |> List.partition (fun name -> name.Contains(" "))
open Xunit
module LongestTests =
[<Fact>]
let longestOfNonEmpty() =
let test = ["Aaaa"; "Bbbbb"; "Cccc"]
Assert.Equal<string>("Bbbbb", myFunctions.getLongest(test))
[<Fact>]
let longestFirstLongest() =
let test = ["Aaa"; "Bbb"]
Assert.Equal<string>("Aaa", myFunctions.getLongest(test))
[<Fact>]
let longestOfEmpty() =
let test = []
Assert.Equal<string>("", myFunctions.getLongest(test))
module PartitionTests =
[<Fact>]
let partitionKeepLength() =
let test = ["A"; "A B"; "A B C"; "C"]
let multi, single = myFunctions.partitionMultiWord(test)
Assert.True(multi.Length + single.Length = test.Length)
[<Fact>]
let partitionNonEmpty() =
let test = ["Seattle"; "New York"; "Reading"]
let expected = ["New York"], ["Seattle"; "Reading"]
Assert.Equal(expected, myFunctions.partitionMultiWord(test))
[<Fact>]
let partitionThenLongest() =
let test = ["Seattle"; "New York"; "Grantchester"]
let expected = ["New York"], ["Seattle"; "Grantchester"]
let actualPartition = myFunctions.partitionMultiWord(test)
let actualLongest = myFunctions.getLongest(test)
Assert.Equal(expected, actualPartition)
Assert.Equal<string>("Grantchester", actualLongest)
// fsc /r:path_to_xunit.dll library.fs /t:dll /o:library.dll