-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathJaggedCollection.fs
More file actions
99 lines (79 loc) · 3.73 KB
/
JaggedCollection.fs
File metadata and controls
99 lines (79 loc) · 3.73 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
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
module JaggedCollectionTests
open Expecto
open System
open FSharp.Stats
let a =
[|
[| 1.; 2.; 3;|]
[| 4.; 5.; 6;|]
[| 7.; 8.; 9;|]
[|10.;11.;12;|]
|]
let aL =
[
[ 1.; 2.; 3;]
[ 4.; 5.; 6;]
[ 7.; 8.; 9;]
[10.;11.;12;]
]
let aT =
[|
[| 1.; 4.; 7.; 10.|]
[| 2.; 5.; 8.; 11.|]
[| 3.; 6.; 9.; 12.|]
|]
let aFirstLong =
[|
[|1.;2.;3.|]
[|1.;2. |]
[|1.;2. |]
[|1.;2. |]
|]
let aFirstShort =
[|
[|1.;2.;3.;4. |]
[|1.;2.;3.;4.;5.;6.|]
[|1.;2.;3.;4.;5.;6.|]
[|1.;2.;3.;4.;5.;6.|]
|]
[<Tests>]
let arrayTests =
testList "JaggedArray" [
testCase "transpose" <| fun () ->
let a_transposed = JaggedArray.transpose a
Expect.equal a_transposed aT "transpose didn't work"
let aFirstLong_transpose() = JaggedArray.transpose aFirstLong
Expect.throws (fun _ -> aFirstLong_transpose () |> ignore ) "All rows must be of equal length!"
let aFirstShort_transpose() = JaggedArray.transpose aFirstShort
Expect.throws (fun _ -> aFirstShort_transpose () |> ignore ) "All rows must be of equal length!"
//The unchecked version works even if the inner collections are of varying length and the first collection is the longest
let aFirstShort_transposeUnchecked = JaggedArray.transpose_ aFirstShort
Expect.equal aFirstShort_transposeUnchecked [|[|1.;1.;1.;1.|];[|2.;2.;2.;2.|];[|3.;3.;3.;3.|];[|4.;4.;4.;4.|]|] "Unchecked transpose gives unintuitive results"
//The unchecked version does not work if the inner collections are of varying length and the first collection isn't the longest
let aFirstLong_transposeUnchecked() = JaggedArray.transpose_ aFirstLong
Expect.throws (fun _ -> aFirstLong_transposeUnchecked () |> ignore ) "All rows must be of equal length!"
]
[<Tests>]
let listTests =
testList "JaggedList" [
testCase "ofJaggedArray" <| fun () ->
let a' = JaggedList.ofJaggedArray a
Expect.equal aL a' "JaggedList.ofJaggedArray didn't work"
testCase "transpose" <| fun () ->
let a' = JaggedList.ofJaggedArray a
let aT' = JaggedList.ofJaggedArray aT
let aFirstLong' = JaggedList.ofJaggedArray aFirstLong
let aFirstShort' = JaggedList.ofJaggedArray aFirstShort
let a_transposed = JaggedList.transpose a'
Expect.equal a_transposed aT' "transpose didn't work"
let aFirstLong_transpose() = JaggedList.transpose aFirstLong'
Expect.throws (fun _ -> aFirstLong_transpose () |> ignore ) "All rows must be of equal length!"
let aFirstShort_transpose() = JaggedList.transpose aFirstShort'
Expect.throws (fun _ -> aFirstShort_transpose () |> ignore ) "All rows must be of equal length!"
//The unchecked version works even if the inner collections are of varying length and the first collection is the longest
let aFirstShort_transposeUnchecked = JaggedList.transpose_ aFirstShort'
Expect.equal aFirstShort_transposeUnchecked [[1.;1.;1.;1.];[2.;2.;2.;2.];[3.;3.;3.;3.];[4.;4.;4.;4.]] "Unchecked transpose gives unintuitive results"
//The unchecked version does not work if the inner collections are of varying length and the first collection isn't the longest
let aFirstLong_transposeUnchecked() = JaggedList.transpose_ aFirstLong'
Expect.throws (fun _ -> aFirstLong_transposeUnchecked () |> ignore ) "All rows must be of equal length!"
]