Skip to content

Commit ceb6c2b

Browse files
committed
Add (more) tests for ArcInvestigation functionality
1 parent e87294f commit ceb6c2b

1 file changed

Lines changed: 41 additions & 11 deletions

File tree

tests/Spreadsheet/InvestigationFileTests.fs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,30 @@ open TestObjects.Spreadsheet
1010

1111
let private testInvestigationWriterComponents =
1212
// Test the single components of invesigation file writing
13-
testList "InvestigationWriterPartTests" [
13+
testList "InvestigationWriterPartTests" [
14+
1415
testCase "CreateEmptyWorkbook" (fun () ->
1516
let wb = new FsWorkbook()
1617
Expect.isTrue true "Workbook could not be initialized"
1718
)
19+
1820
testCase "CreateSheet" (fun () ->
1921
let sheet = FsWorksheet("Investigation")
2022
Expect.equal sheet.Name "Investigation" "Worksheet could not be initialized"
2123
)
24+
2225
testCase "InvestigationToRows" (fun () ->
2326
let i = ArcInvestigation.init("My Investigation")
2427
let rows = i |> ArcInvestigation.toRows
2528
Expect.isTrue (rows |> Seq.length |> (<) 0) "Investigation should have at least one row"
2629
)
30+
2731
testCase "AddEmptyWorksheet" (fun () ->
2832
let wb = new FsWorkbook()
2933
let sheet = FsWorksheet("Investigation")
3034
wb.AddWorksheet(sheet)
3135
)
36+
3237
testCase "FillWorksheet" (fun () ->
3338
let i = ArcInvestigation.init("My Identifier")
3439
let sheet = FsWorksheet("Investigation")
@@ -37,6 +42,7 @@ let private testInvestigationWriterComponents =
3742
|> Seq.iteri (fun rowI r -> SparseRow.writeToSheet (rowI + 1) r sheet)
3843
Expect.isTrue (sheet.Rows |> Seq.length |> (<) 0) "Worksheet should have at least one row"
3944
)
45+
4046
testCase "AddFilledWorksheet" (fun () ->
4147
let i = ArcInvestigation.init("My Identifier")
4248
let wb = new FsWorkbook()
@@ -47,6 +53,7 @@ let private testInvestigationWriterComponents =
4753
wb.AddWorksheet(sheet)
4854
Expect.isSome (wb.TryGetWorksheetByName "Investigation") "Worksheet should be added to workbook"
4955
)
56+
5057
testCase "OnlyConsiderRegisteredStudies" (fun () ->
5158
let isa = ArcInvestigation("MyInvestigation")
5259
let registeredStudyIdentifier = "RegisteredStudy"
@@ -92,8 +99,8 @@ let private testInvestigationFile =
9299
| err -> Result.Error(sprintf "Reading the test file failed: %s" err.Message)
93100

94101
Expect.isOk readingSuccess (Result.getMessage readingSuccess)
95-
96102
)
103+
97104
testCase "ReaderSuccessDeprecatedSheetName" (fun () ->
98105

99106
let readingSuccess =
@@ -104,8 +111,8 @@ let private testInvestigationFile =
104111
| err -> Result.Error(sprintf "Reading the test file failed: %s" err.Message)
105112

106113
Expect.isOk readingSuccess (Result.getMessage readingSuccess)
107-
108114
)
115+
109116
testCase "ReaderFailureWrongSheetName" (fun () ->
110117

111118
let readingSuccess =
@@ -117,6 +124,30 @@ let private testInvestigationFile =
117124

118125
Expect.isError readingSuccess "Reading the investigation file should fail if the sheet name is wrong"
119126
)
127+
128+
testCase "ReaderSuccess1MadeUpKeyAtTop" (fun () ->
129+
130+
let readingSuccess =
131+
try
132+
ArcInvestigation.fromFsWorkbook Investigation.BII_I_1.fullInvestigation1MadeUpKey |> ignore
133+
Result.Ok "DidRun"
134+
with
135+
| err -> Result.Error(sprintf "Reading the test file failed: %s" err.Message)
136+
137+
Expect.isOk readingSuccess (Result.getMessage readingSuccess)
138+
)
139+
140+
testCase "1MadeUpKeyAtTopInvestigationIdentifierPresent" (fun () ->
141+
142+
let arcInv =
143+
try
144+
ArcInvestigation.fromFsWorkbook Investigation.BII_I_1.fullInvestigation1MadeUpKey
145+
with
146+
| _ -> ArcInvestigation.create ""
147+
148+
Expect.equal arcInv.Identifier "investigation1MadeUpKey" "Did not retrieve the correct Investigation identifier"
149+
)
150+
120151
testCase "WriterSuccess" (fun () ->
121152

122153
let i = ArcInvestigation.fromFsWorkbook Investigation.BII_I_1.fullInvestigation
@@ -152,30 +183,28 @@ let private testInvestigationFile =
152183
Expect.isEmpty i.Studies "Empty study in investigation should be read to empty ResizeArray"
153184
)
154185

155-
testCase "ReaderSuccessEmpty" (fun () ->
156-
186+
testCase "ReaderFailureEmpty" (fun () ->
157187
let readingSuccess =
158188
try
159189
ArcInvestigation.fromFsWorkbook Investigation.emptyInvestigation |> ignore
160190
Result.Ok "DidRun"
161191
with
162192
| err -> Result.Error(sprintf "Reading the empty test file failed: %s" err.Message)
163-
Expect.isOk readingSuccess (Result.getMessage readingSuccess)
193+
Expect.isError readingSuccess (Result.getMessage readingSuccess)
164194
)
165195

166-
testCase "WriterSuccessEmpty" (fun () ->
167-
168-
let i = ArcInvestigation.fromFsWorkbook Investigation.emptyInvestigation
169-
196+
testCase "WriterFailureEmpty" (fun () ->
170197
let writingSuccess =
171198
try
199+
let i = ArcInvestigation.fromFsWorkbook Investigation.emptyInvestigation
172200
ArcInvestigation.toFsWorkbook i |> ignore
173201
Result.Ok "DidRun"
174202
with
175203
| err -> Result.Error(sprintf "Writing the empty test file failed: %s" err.Message)
176204

177-
Expect.isOk writingSuccess (Result.getMessage writingSuccess)
205+
Expect.isError writingSuccess (Result.getMessage writingSuccess)
178206
)
207+
179208
testCase "WriteWithStudyOnlyRegistered" (fun () ->
180209

181210
let studyIdentifiers = ResizeArray ["MyStudy"]
@@ -185,6 +214,7 @@ let private testInvestigationFile =
185214
|> ArcInvestigation.fromFsWorkbook
186215
Expect.sequenceEqual i.RegisteredStudyIdentifiers studyIdentifiers "Registered study Identifier were not written and read correctly"
187216
)
217+
188218
testCase "TestMetadataCollection" (fun () ->
189219

190220
let investigation =

0 commit comments

Comments
 (0)