From 16926d5972ce740255f70ea6521b602796cc7b40 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Thu, 17 Aug 2023 11:31:13 +0200 Subject: [PATCH] Add more static member tests for CvParam --- .../CvParamTests.fs | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/tests/ControlledVocabulary.Tests/CvParamTests.fs b/tests/ControlledVocabulary.Tests/CvParamTests.fs index 9317c3e..012c731 100644 --- a/tests/ControlledVocabulary.Tests/CvParamTests.fs +++ b/tests/ControlledVocabulary.Tests/CvParamTests.fs @@ -109,3 +109,105 @@ module StaticMemberTests = let actual = testCvParams |> List.map CvParam.tryGetCvUnitTermRef Assert.Equal List>(expected, actual) + [] + let ``mapValue`` () = + let expected = [ParamValue.Value 1; ParamValue.Value 1; ParamValue.Value 1] + let actual = testCvParams |> List.map (CvParam.mapValue (fun _ -> ParamValue.Value 1) >> CvParam.getParamValue) + Assert.Equal(expected, actual) + + [] + let ``tryMapValue`` () = + let expected = [Some (ParamValue.Value 1); Some (ParamValue.Value 1); Some (ParamValue.Value 1)] + let actual = testCvParams |> List.map (CvParam.tryMapValue (fun _ -> Some (ParamValue.Value 1)) >> Option.map CvParam.getParamValue) + Assert.Equal<(ParamValue option) List>(expected, actual) + + [] + let ``tryAddName`` () = + let expected = [Some testName1; None; None] + let actual = testCvParams |> List.map (CvParam.tryAddName testName1 >> Option.map CvParam.getCvName) + Assert.Equal<(string option) List>(expected, actual) + + [] + let ``tryAddAccession`` () = + let expected = [None; None; None] + let actual = testCvParams |> List.map (CvParam.tryAddAccession testAccession1 >> Option.map CvParam.getCvAccession) + Assert.Equal<(string option) List>(expected, actual) + + [] + let ``tryAddReference`` () = + let expected = [None; None; None] + let actual = testCvParams |> List.map (CvParam.tryAddReference testRef1 >> Option.map CvParam.getCvRef) + Assert.Equal<(string option) List>(expected, actual) + + [] + let ``tryAddUnit`` () = + let expected = [Some (ParamValue.WithCvUnitAccession (5, testTerm1)); None; None] + let actual = testCvParams |> List.map (CvParam.tryAddUnit testTerm1 >> Option.map CvParam.getParamValue) + Assert.Equal<(ParamValue option) List>(expected, actual) + + [] + let ``getCvAccession`` () = + let expected = [testAccession1; testAccession1; testAccession2] + let actual = testCvParams |> List.map CvParam.getCvAccession + Assert.Equal(expected, actual) + + [] + let ``getCvName`` () = + let expected = [testName1; testName1; testName2] + let actual = testCvParams |> List.map CvParam.getCvName + Assert.Equal(expected, actual) + + [] + let ``getCvRef`` () = + let expected = [testRef1; testRef1; testRef2] + let actual = testCvParams |> List.map CvParam.getCvRef + Assert.Equal(expected, actual) + + [] + let ``getTerm`` () = + let expected = [testTerm1; testTerm1; testTerm2] + let actual = testCvParams |> List.map CvParam.getTerm + Assert.Equal(expected, actual) + + [] + let ``equalsTerm`` () = + Assert.All( + ( + List.zip + [testTerm1; testTerm1; testTerm2] + testCvParams + ), + (fun (x,y) -> CvParam.equalsTerm x y |> Assert.True) + ) + + [] + let ``equals`` () = + Assert.All( + ( + List.zip + [ + CvParam(testTerm1, ParamValue.Value 5) + CvParam(testTerm1, ParamValue.CvValue testTerm2) + CvParam(testTerm2, ParamValue.WithCvUnitAccession (5, testTerm1)) + ] + testCvParams + ), + (fun (x,y) -> CvParam.equals x y |> Assert.True) + ) + + [] + let ``equalsName`` () = + Assert.All( + ( + List.zip + [ + CvParam(testTerm1, ParamValue.Value 5) + CvParam(testTerm1, ParamValue.CvValue testTerm2) + CvParam(testTerm2, ParamValue.WithCvUnitAccession (5, testTerm1)) + ] + testCvParams + ), + (fun (x,y) -> CvParam.equalsName x y |> Assert.True) + ) + +