-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter_04_ex_10.fs
More file actions
36 lines (32 loc) · 1.19 KB
/
Chapter_04_ex_10.fs
File metadata and controls
36 lines (32 loc) · 1.19 KB
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
module Chapter_04_ex_10
#if INTERACTIVE
#r "packages/Unquote.2.2.2/lib/net40/unquote.dll"
#r "packages/FsUnit.1.2.1.0/lib/net40/FsUnit.NUnit.dll"
#r "packages/NUnit.2.6.2/lib/nunit.framework.dll"
#endif
open System
open NUnit.Framework
open FsUnit
open Swensen.Unquote
// TODO: Collapse some matches
let rec prefix list1 list2 =
match list1, list2 with
| [],[] -> true
| x1::[], [] -> false // list1 longer than list2 is per definition not a match
| x1::[], x2::[] -> x1 = x2
| x1::xs1, x2::[] -> false // list1 longer than list2 is per definition not a match// failwith "test"//x1 = x2 && prefix xs1 []
| x1::[], x2::xs2 -> x1 = x2
| x1::xs1, x2::xs2 -> x1 = x2 && prefix xs1 xs2
| _ -> failwith "Incomplete match"
[<TestFixture>]
type ``Chapter_04_ex_10_Tests``() =
[<Test>]
member x.``4.10 recursive``() =
test <@ prefix [] [] = true @>
test <@ prefix [1] [1] = true @>
test <@ prefix [1;2] [1;2] = true @>
test <@ prefix [1] [1;2] = true @>
test <@ prefix [1] [1;2;3] = true @>
test <@ prefix [1;2] [1;2;3] = true @>
test <@ prefix [0] [1;2] = false @>
test <@ prefix [1;2] [1] = false @>