-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter_04_ex_8.fs
More file actions
25 lines (21 loc) · 743 Bytes
/
Chapter_04_ex_8.fs
File metadata and controls
25 lines (21 loc) · 743 Bytes
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
module Chapter_04_ex_8
open NUnit.Framework
open FsUnit
// 4.8 recursive (not tail-recursive)
let rec split items =
match items with
| [] -> ([],[])
| [x0] -> ([x0],[])
| [x0;x1] -> ([x0],[x1])
| x0::x1::xs -> let (r1, r2) = split xs
(x0::r1, x1::r2)
[<TestFixture>]
type ``Chapter_04_ex_8_Tests``() =
[<Test>]
member x.``4.8 recursive``() =
split [] |> should equal ([], [])
// This one is hard to test, since the value ([2],[]) has type int list*'a list
// split [2] |> should equal ([2],[])
split [2;4] |> should equal ([2],[4])
split [1;2;3;4;5] |> should equal ([1;3;5],[2;4])
split [1;2;3;4;5;6] |> should equal ([1;3;5],[2;4;6])