Skip to content

Commit

Permalink
Delete some unit tests and add some integration tests
Browse files Browse the repository at this point in the history
Also some updates for test project, dependency- and structure-wise.
  • Loading branch information
omaus committed Jul 17, 2023
1 parent 4623a46 commit 69a1f28
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 89 deletions.
7 changes: 6 additions & 1 deletion tests/ArcGraphModel.IO.Tests/ArcGraphModel.IO.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -7,6 +7,9 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="TestUtils.fs" />
<Compile Include="IntegrationTests\ParseInvestigationTests.fs" />
<None Include="Fixtures\**" CopyToOutputDirectory="Always" />
<Compile Include="KeyParserTests.fs" />
<Compile Include="TokenAggregationTests.fs" />
<Compile Include="Program.fs" />
Expand All @@ -15,6 +18,8 @@
<ItemGroup>
<PackageReference Include="Fable.Mocha" Version="2.16.0" />
<PackageReference Include="Expecto" Version="9.*" />
<PackageReference Include="FsSpreadsheet" Version="[2.0.2]" />
<PackageReference Include="FsSpreadsheet.ExcelIO" Version="[2.0.2]" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module ParseInvestigationTests

open FsSpreadsheet
open FsSpreadsheet.ExcelIO
open ArcGraphModel
open ArcGraphModel.IO
open Expecto

open TestUtils


let inves = FsWorkbook.fromXlsxFile "Fixtures/isa.investigation.xlsx"
let invesWs = FsWorkbook.getWorksheets inves |> Seq.head
let invesWsParsed = Worksheet.parseRowsFlat invesWs

//let cvp1 = CvParam("", "ONTOLOGY SOURCE REFERENCE", "", ParamValue.Value "", [])
let up1 = UserParam("ONTOLOGY SOURCE REFERENCE", ParamValue.Value "", [])

[<Tests>]
let ``Investigation File is parsed correctly`` =
testList "Investigation from file" [
//testList "CvParam" [
// testCase "First Param is CvParam" (fun _ ->
// Expect.isSome (invesWsParsed.Head |> CvParam.tryCvParam) "Is no CvParam"
// )
// testCase "First CvParam name" (fun _ ->
// CvParam.termNamesEqual (invesWsParsed.Head :?> CvParam) cvp1
// )
//]
testList "UserParam" [
testCase "First Param is UserParam" (fun _ ->
Expect.isSome (invesWsParsed.Head |> UserParam.tryUserParam) "Is no UserParam"
)
testCase "First UserParam name" (fun _ ->
UserParam.termNamesEqual (invesWsParsed.Head :?> UserParam) up1
)
]
]
145 changes: 74 additions & 71 deletions tests/ArcGraphModel.IO.Tests/KeyParserTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,82 @@ open Expecto
#endif


module Keys =



//module Keys =

let justToken = "Last Name"
let tokenWithSingleQualifier = "Person Last Name"
let tokenWithTwoIdentifiers = "Study Person Last Name"
let structuredName = "[temperature]"
let structuredNameWithQualifer = "Factor [temperature]"
let unparseableToken = "I'm just a token"
// let justToken = "Last Name"
// let tokenWithSingleQualifier = "Person Last Name"
// let tokenWithTwoIdentifiers = "Study Person Last Name"
// let structuredName = "[temperature]"
// let structuredNameWithQualifier = "Factor [temperature]"
// let unparseableToken = "I'm just a token"


let private simpleParsing = testList "SimpleParsing" [
//let private simpleParsing = testList "SimpleParsing" [

testCase "JustToken" (fun _ ->
let f = KeyParser.parseKey [] Keys.justToken
let result = f (ParamValue.Value "Test")
Expect.isTrue (CvParam.isCvParam result) "Key was not correctly parsed to CvParam"
let param = result :?> CvParam
Expect.equal param.Attributes List.empty "Token should not have Attributes"
Expect.equal (CvBase.getTerm param) Terms.familyName "Token was parsed to wrong term"
Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
)
testCase "TokenWithSingleQualifier" (fun _ ->
let f = KeyParser.parseKey [] Keys.tokenWithSingleQualifier
let result = f (ParamValue.Value "Test")
Expect.isTrue (CvParam.isCvParam result) "Key was not correctly parsed to CvParam"
let param = result :?> CvParam
Expect.equal 1 param.Attributes.Length "Token should have one attribute"
Expect.equal (CvBase.getTerm param.Attributes.[0]) Terms.person "Incorrect attribute"
Expect.equal (CvBase.getTerm param) Terms.familyName "Token was parsed to wrong term"
Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
)
testCase "TokenWithTwoIdentifiers" (fun _ ->
let f = KeyParser.parseKey [] Keys.tokenWithTwoIdentifiers
let result = f (ParamValue.Value "Test")
Expect.isTrue (CvParam.isCvParam result) "Key was not correctly parsed to CvParam"
let param = result :?> CvParam
Expect.equal 2 param.Attributes.Length "Token should have two attributes"
Expect.equal (CvBase.getTerm param.Attributes.[0]) Terms.person "Incorrect attribute"
Expect.equal (CvBase.getTerm param.Attributes.[1]) Terms.study "Incorrect attribute"
Expect.equal (CvBase.getTerm param) Terms.familyName "Token was parsed to wrong term"
Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
)
testCase "StructuredName" (fun _ ->
let f = KeyParser.parseKey [] Keys.structuredName
let result = f (ParamValue.Value "Test")
Expect.isTrue (CvParam.isCvParam result) "Key was not correctly parsed to CvParam"
let param = result :?> CvParam
Expect.equal param.Attributes List.empty "Token should not have Attributes"
Expect.equal (CvBase.getTerm param) ("","temperature","") "Token was parsed to wrong term"
Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
)
testCase "StructuredNameWithQualifer" (fun _ ->
let f = KeyParser.parseKey [] Keys.structuredNameWithQualifer
let result = f (ParamValue.Value "Test")
Expect.isTrue (CvParam.isCvParam result) "Key was not correctly parsed to CvParam"
let param = result :?> CvParam
Expect.equal 1 param.Attributes.Length "Token should have one attribute"
Expect.equal (CvBase.getTerm param) ("","temperature","") "Token was parsed to wrong term"
Expect.equal (CvBase.getTerm param.Attributes.[0]) Terms.factor "Incorrect attribute"
Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
)
testCase "UnparseableToken" (fun _ ->
let f = KeyParser.parseKey [] Keys.unparseableToken
let result = f (ParamValue.Value "Test")
Expect.isTrue (CvBase.is<UserParam> result) "Key was not correctly parsed to UserParam"
let param = result :?> UserParam
Expect.equal param.Attributes List.empty "Token should not have Attributes"
Expect.equal (CvBase.getCvName param) ("I'm just a token") "Token was parsed to wrong term"
Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
)
]
// testCase "JustToken" (fun _ ->
// let f = KeyParser.parseKey [] Keys.justToken
// let result = f (ParamValue.Value "Test")
// Expect.isTrue (CvParam.isCvParam result) "Key was not correctly parsed to CvParam"
// let param = result :?> CvParam
// Expect.equal param.Attributes List.empty "Token should not have Attributes"
// Expect.equal (CvBase.getTerm param) Terms.familyName "Token was parsed to wrong term"
// Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
// )
// testCase "TokenWithSingleQualifier" (fun _ ->
// let f = KeyParser.parseKey [] Keys.tokenWithSingleQualifier
// let result = f (ParamValue.Value "Test")
// Expect.isTrue (CvParam.isCvParam result) "Key was not correctly parsed to CvParam"
// let param = result :?> CvParam
// Expect.equal 1 param.Attributes.Length "Token should have one attribute"
// Expect.equal (CvBase.getTerm param.Attributes.[0]) Terms.person "Incorrect attribute"
// Expect.equal (CvBase.getTerm param) Terms.familyName "Token was parsed to wrong term"
// Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
// )
// testCase "TokenWithTwoIdentifiers" (fun _ ->
// let f = KeyParser.parseKey [] Keys.tokenWithTwoIdentifiers
// let result = f (ParamValue.Value "Test")
// Expect.isTrue (CvParam.isCvParam result) "Key was not correctly parsed to CvParam"
// let param = result :?> CvParam
// Expect.equal 2 param.Attributes.Length "Token should have two attributes"
// Expect.equal (CvBase.getTerm param.Attributes.[0]) Terms.person "Incorrect attribute"
// Expect.equal (CvBase.getTerm param.Attributes.[1]) Terms.study "Incorrect attribute"
// Expect.equal (CvBase.getTerm param) Terms.familyName "Token was parsed to wrong term"
// Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
// )
// testCase "StructuredName" (fun _ ->
// let f = KeyParser.parseKey [] Keys.structuredName
// let result = f (ParamValue.Value "Test")
// Expect.isTrue (CvParam.isCvParam result) "Key was not correctly parsed to CvParam"
// let param = result :?> CvParam
// Expect.equal param.Attributes List.empty "Token should not have Attributes"
// Expect.equal (CvBase.getTerm param) ("","temperature","") "Token was parsed to wrong term"
// Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
// )
// testCase "StructuredNameWithQualifer" (fun _ ->
// let f = KeyParser.parseKey [] Keys.structuredNameWithQualifier
// let result = f (ParamValue.Value "Test")
// Expect.isTrue (CvParam.isCvParam result) "Key was not correctly parsed to CvParam"
// let param = result :?> CvParam
// Expect.equal 1 param.Attributes.Length "Token should have one attribute"
// Expect.equal (CvBase.getTerm param) ("","temperature","") "Token was parsed to wrong term"
// Expect.equal (CvBase.getTerm param.Attributes.[0]) Terms.factor "Incorrect attribute"
// Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
// )
// testCase "UnparseableToken" (fun _ ->
// let f = KeyParser.parseKey [] Keys.unparseableToken
// let result = f (ParamValue.Value "Test")
// Expect.isTrue (CvBase.is<UserParam> result) "Key was not correctly parsed to UserParam"
// let param = result :?> UserParam
// Expect.equal param.Attributes List.empty "Token should not have Attributes"
// Expect.equal (CvBase.getCvName param) ("I'm just a token") "Token was parsed to wrong term"
// Expect.equal (Param.getValue param) ("Test" :> System.IConvertible) "Value was stored incorrectly"
// )
//]

let main =
testList "KeyParserTests" [
simpleParsing
]
//let main =
// testList "KeyParserTests" [
// simpleParsing
// ]
20 changes: 3 additions & 17 deletions tests/ArcGraphModel.IO.Tests/Program.fs
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
module Tests

#if FABLE_COMPILER
open Fable.Mocha
#else
open Expecto

[<Tests>]
#endif
let all =
testList "All"
[
TokenAggregationTests.main
KeyParserTests.main
]

let [<EntryPoint>] main argv =
#if FABLE_COMPILER
Mocha.runTests all
#else
Tests.runTestsWithCLIArgs [] argv all
#endif
[<EntryPoint>]
let main argv =
Tests.runTestsInAssemblyWithCLIArgs [] argv
31 changes: 31 additions & 0 deletions tests/ArcGraphModel.IO.Tests/TestUtils.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module TestUtils

open Expecto


module CvParam =

open ArcGraphModel

let termNamesEqual (cvpActual : CvParam) (cvpExpectec : CvParam) =
Expect.equal (CvBase.getCvName cvpActual) (CvBase.getCvName cvpExpectec) "CvParam names are not equal"

//let attributesEqual (cvp1 : CvParam) (cvp2 : CvParam) =
// (cvp1.Keys, cvp1.Values |> Seq.map )
// ||> Seq.zip
// |> Seq.toList
// |> List.sortBy fst


module UserParam =

open ArcGraphModel

let termNamesEqual (upActual : UserParam) (upExpectec : UserParam) =
Expect.equal (CvBase.getCvName upActual) (CvBase.getCvName upExpectec) "UserParam names are not equal"

//let attributesEqual (cvp1 : CvParam) (cvp2 : CvParam) =
// (cvp1.Keys, cvp1.Values |> Seq.map )
// ||> Seq.zip
// |> Seq.toList
// |> List.sortBy fst

0 comments on commit 69a1f28

Please sign in to comment.