Skip to content

Commit

Permalink
Add first simple integration test for annotation table parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jul 27, 2023
1 parent 5cd5589 commit e9e8bc2
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 19 deletions.
14 changes: 1 addition & 13 deletions playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,7 @@ open ArcGraphModel

// Assay annotation table parsing

let assay = FsWorkbook.fromXlsxFile (__SOURCE_DIRECTORY__ + "/tests/ArcGraphModel.Tests/Fixtures/isa.assay.xlsx")

let sheet1 = FsWorkbook.getWorksheets assay |> Seq.item 0
let sheet2 = FsWorkbook.getWorksheets assay |> Seq.item 1

sheet1.Rows[0] |> Seq.toList
sheet2.Rows[0] |> Seq.toList

let assayTables = AnnotationTable.parseWorkbook assay

assayTables[1]
|> snd
|> fun x -> x.TermRelatedBuildingBlocks
let assayTokens = Assay.parseAnnotationTablesFromFile (__SOURCE_DIRECTORY__ + "/tests/ArcGraphModel.Tests/Fixtures/correct/assay_with_only_source_and_sample_column.xlsx")

// Investigation metadata parsing

Expand Down
2 changes: 2 additions & 0 deletions tests/ArcGraphModel.Tests/ArcGraphModel.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<ItemGroup>
<None Include="Fixtures\**" CopyToOutputDirectory="Always" />
<Compile Include="TestUtils.fs" />
<Compile Include="TestObjects.fs" />
<Compile Include="IntegrationTests\Assay.fs" />
<Compile Include="IntegrationTests\ParseInvestigationTests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
Expand Down
Binary file not shown.
Binary file not shown.
75 changes: 75 additions & 0 deletions tests/ArcGraphModel.Tests/IntegrationTests/Assay.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
module IntegrationTests.Assay

open ControlledVocabulary
open FsSpreadsheet
open FsSpreadsheet.ExcelIO
open ArcGraphModel
open Xunit

open TestUtils
open TestObjects

module Correct =

module ``Assay with only source and sample column`` =

let assay = Assays.Correct.``assay with only source and sample column``

[<Fact>]
let ``AnnotationTable count`` () =
Assert.Equal(assay.Length, 1)

let table = assay.[0] |> snd

[<Fact>]
let ``TokenizedAnnotationTable IOColumn count`` () =
TokenizedAnnotationTable.hasIOColumnAmount 2 table

[<Fact>]
let ``TokenizedAnnotationTable TermRelatedBuildingBlocksAmount`` () =
TokenizedAnnotationTable.hasTermRelatedBuildingBlockAmount 0 table

let expectedIOColumns =
[
[
CvParam(
id = "(n/a)",
name = "Source Name",
ref = "(n/a)",
pv = (ParamValue.Value "Source A"),
attributes = []
)
]
[
CvParam(
id = "(n/a)",
name = "Sample Name",
ref = "(n/a)",
pv = (ParamValue.Value "Sample A"),
attributes = []
)
]
]

let expectedTermRelatedBuildingBlocks: CvParam list list = []

[<Fact>]
let ``TokenizedAnnotationTable IOColumns`` () =
(expectedIOColumns, table.IOColumns)
||> List.iter2 (fun expectedGroup actualGroup ->
(expectedGroup, actualGroup)
||> List.iter2 (fun expectedParam actualParam ->
CvParam.structuralEquality expectedParam actualParam
)
)

[<Fact>]
let ``TokenizedAnnotationTable TermRelatedBuildingBlocks`` () =
(expectedTermRelatedBuildingBlocks, table.TermRelatedBuildingBlocks)
||> List.iter2 (fun expectedGroup actualGroup ->
(expectedGroup, actualGroup)
||> List.iter2 (fun expectedParam actualParam ->
CvParam.structuralEquality expectedParam actualParam
)
)

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ open Xunit

open TestUtils


let inves = FsWorkbook.fromXlsxFile "Fixtures/isa.investigation.xlsx"
let invesWs = FsWorkbook.getWorksheets inves |> Seq.head
let invesWsParsed = Worksheet.parseRowsFlat invesWs
Expand Down
13 changes: 13 additions & 0 deletions tests/ArcGraphModel.Tests/TestObjects.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module TestObjects

open ArcGraphModel

module Assays =

module Correct =

let ``assay with only source and sample column`` =
Assay.parseAnnotationTablesFromFile "Fixtures/correct/assay_with_only_source_and_sample_column.xlsx"

let ``assay with characteristics`` =
Assay.parseAnnotationTablesFromFile "Fixtures/correct/assay_with_single_characteristics.xlsx"
61 changes: 56 additions & 5 deletions tests/ArcGraphModel.Tests/TestUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,61 @@ open ArcGraphModel.AnnotationTable

module CvParam =

open ArcGraphModel
let termNamesEqual (cvpExpectec : CvParam) (cvpActual : CvParam) =
Assert.Equal(
(CvBase.getCvName cvpExpectec),
(CvBase.getCvName cvpActual)
)

let hasTermName (expectedName : string) (cvpActual : CvParam) =
Assert.Equal(
expectedName,
(CvBase.getCvName cvpActual)
)

let accessionsEqual (cvpExpectec : CvParam) (cvpActual : CvParam) =
Assert.Equal(
(CvBase.getCvAccession cvpExpectec),
(CvBase.getCvAccession cvpActual)
)

let hasAccession (expectedID : string) (cvpActual : CvParam) =
Assert.Equal(
expectedID,
(CvBase.getCvAccession cvpActual)
)

let termNamesEqual (cvpActual : CvParam) (cvpExpectec : CvParam) =
let refUrisEqual (cvpExpectec : CvParam) (cvpActual : CvParam) =
Assert.Equal(
(CvBase.getCvName cvpActual),
(CvBase.getCvName cvpExpectec)
(CvBase.getCvRef cvpExpectec),
(CvBase.getCvRef cvpActual)
)

let hasRefUri (expectedRefUri : string) (cvpActual : CvParam) =
Assert.Equal(
expectedRefUri,
(CvBase.getCvRef cvpActual)
)

let valuesEqual (cvpExpectec : CvParam) (cvpActual : CvParam) =
Assert.Equal(
(Param.getParamValue cvpExpectec),
(Param.getParamValue cvpActual)
)

let hasValue (expectedValue : ParamValue) (cvpActual : CvParam) =
Assert.Equal(
expectedValue,
(Param.getParamValue cvpActual)
)

let structuralEquality (cvpExpectec : CvParam) (cvpActual : CvParam) =
termNamesEqual cvpExpectec cvpActual
accessionsEqual cvpExpectec cvpActual
refUrisEqual cvpExpectec cvpActual
valuesEqual cvpExpectec cvpActual


module UserParam =

open ArcGraphModel
Expand All @@ -27,4 +74,8 @@ module UserParam =

module TokenizedAnnotationTable =

()
let hasIOColumnAmount (expectedIOColumnAmount : int) (table : TokenizedAnnotationTable) =
Assert.Equal(expectedIOColumnAmount, table.IOColumns.Length)

let hasTermRelatedBuildingBlockAmount (expectedTermRelatedBuildingBlockAmount : int) (table : TokenizedAnnotationTable) =
Assert.Equal(expectedTermRelatedBuildingBlockAmount, table.TermRelatedBuildingBlocks.Length)

0 comments on commit e9e8bc2

Please sign in to comment.