-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7kyu_Find_min_and_max.fs
48 lines (35 loc) · 1.16 KB
/
7kyu_Find_min_and_max.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
namespace FSharpCodingChallenges_CodeWars
(*
7 kyu
Find min and max
Implement a function that returns the minimal and the maximal value of a list (in this order).
*)
module Katas =
let getMinMax list =
match list with
| [] -> failwith "List's empty!"
| _ -> (List.min list, List.max list)
open Microsoft.VisualStudio.TestTools.UnitTesting
open Katas
[<TestClass>]
type MinMaxTests() =
[<TestMethod>]
member this.``Test with single element list`` () =
let expected = (1, 1)
let actual = getMinMax [1]
Assert.AreEqual(expected, actual)
[<TestMethod>]
member this.``Test with two elements list in order`` () =
let expected = (1, 2)
let actual = getMinMax [1; 2]
Assert.AreEqual(expected, actual)
[<TestMethod>]
member this.``Test with two elements list in reverse order`` () =
let expected = (1, 2)
let actual = getMinMax [2; 1]
Assert.AreEqual(expected, actual)
[<TestMethod>]
[<ExpectedException(typeof<System.Exception>)>]
member this.``Test with empty list`` () =
let actual = getMinMax []
Assert.AreEqual(true, false)