Skip to content

Commit

Permalink
add io type update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Oct 16, 2023
1 parent 6608b09 commit a4c6c7f
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ISA/ISA/ArcTypes/ArcTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,14 @@ type ArcInvestigation(identifier : string, ?title : string, ?description : strin
let copy = inv.Copy()
copy.DeregisterMissingAssays()
copy


/// Updates the IOtypes of the IO columns across all tables in the investigation if possible.
///
/// If an entity with the same name as an entity with a higher IOType specifity is found, the IOType of the entity with the lower IOType specificity is updated.
///
/// E.g. RawDataFile is more specific than Source, but less specific than DerivedDataFile.
///
/// E.g. Sample is equally specific to RawDataFile.
member this.UpdateIO() =
let ioMap =
[
Expand Down
106 changes: 106 additions & 0 deletions tests/ISA/ISA.Tests/ArcInvestigation.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,111 @@ let tests_Assay = testList "CRUD Assay" [
]
]

let tests_UpdateIOTypes = testList "UpdateIOType" [
testList "SameAssay" [
testCase "nothingToUpdate" <| fun _ ->
let i = ArcInvestigation.init("MyInvestigation")
let a = i.InitAssay("MyAssay")
let t1 = a.InitTable("MyTable")
let t2 = a.InitTable("MyTable2")
t1.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Source %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i)))
|]
t2.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Source_Alt %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i)))
|]
let a_Copy = a.Copy()
i.UpdateIO()
Expect.sequenceEqual a.Tables a_Copy.Tables "Tables should be unchanged"
testCase "updateOutputByNextInput" <| fun _ ->
let i = ArcInvestigation.init("MyInvestigation")
let a = i.InitAssay("MyAssay")
let t1 = a.InitTable("MyTable")
let t2 = a.InitTable("MyTable2")
t1.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Source %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i)))
|]
t2.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i)))
|]
i.UpdateIO()
Expect.sequenceEqual t1.Headers [CompositeHeader.Input IOType.Source; CompositeHeader.Output IOType.Sample] "Headers should be updated"
Expect.sequenceEqual t2.Headers [CompositeHeader.Input IOType.Sample; CompositeHeader.Output IOType.Sample] "Headers should be updated"
testCase "failBecauseClashing" <| fun _ ->
let i = ArcInvestigation.init("MyInvestigation")
let a = i.InitAssay("MyAssay")
let t1 = a.InitTable("MyTable")
let t2 = a.InitTable("MyTable2")
t1.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Source %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i)))
|]
t2.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.DerivedDataFile, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i)))
|]
Expect.throws (fun () -> i.UpdateIO()) "Update should fail as sample and data can not be updated against each other."
]
testList "AssayAndStudy" [
testCase "nothingToUpdate" <| fun _ ->
let i = ArcInvestigation.init("MyInvestigation")
let s = i.InitStudy("MyStudy")
let a = i.InitAssay("MyAssay")
let t1 = s.InitTable("MyTable")
let t2 = a.InitTable("MyTable2")
t1.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Source %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i)))
|]
t2.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Source_Alt %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i)))
|]
let a_Copy = a.Copy()
let s_Copy = s.Copy()
i.UpdateIO()
Expect.sequenceEqual a.Tables a_Copy.Tables "Tables should be unchanged"
Expect.sequenceEqual s.Tables s_Copy.Tables "Tables should be unchanged"
testCase "updateOutputByNextInput" <| fun _ ->
let i = ArcInvestigation.init("MyInvestigation")
let s = i.InitStudy("MyStudy")
let a = i.InitAssay("MyAssay")
let t1 = s.InitTable("MyTable")
let t2 = a.InitTable("MyTable2")
t1.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Source %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i)))
|]
t2.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i)))
|]
i.UpdateIO()
Expect.sequenceEqual t1.Headers [CompositeHeader.Input IOType.Source; CompositeHeader.Output IOType.Sample] "Headers should be updated"
Expect.sequenceEqual t2.Headers [CompositeHeader.Input IOType.Sample; CompositeHeader.Output IOType.Sample] "Headers should be updated"
testCase "failBecauseClashing" <| fun _ ->
let i = ArcInvestigation.init("MyInvestigation")
let s = i.InitStudy("MyStudy")
let a = i.InitAssay("MyAssay")
let t1 = s.InitTable("MyTable")
let t2 = a.InitTable("MyTable2")
t1.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.Source, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Source %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i)))
|]
t2.AddColumns [|
CompositeColumn.create (CompositeHeader.Input IOType.DerivedDataFile, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample %i" i)))
CompositeColumn.create (CompositeHeader.Output IOType.Sample, Array.init 3 (fun i -> CompositeCell.createFreeText (sprintf "Sample_Alt %i" i)))
|]
Expect.throws (fun () -> i.UpdateIO()) "Update should fail as sample and data can not be updated against each other."
]
]


let private tests_GetHashCode = testList "GetHashCode" [
testCase "passing" <| fun _ ->
let actual = ArcInvestigation.init("Test")
Expand Down Expand Up @@ -700,5 +805,6 @@ let main =
tests_Study
tests_Assay
tests_GetHashCode
tests_UpdateIOTypes
// tests_UpdateBy
]

0 comments on commit a4c6c7f

Please sign in to comment.