Skip to content

Commit

Permalink
Add unit tests for new code generation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Mar 13, 2024
1 parent ade2f21 commit 8c49196
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
12 changes: 10 additions & 2 deletions playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
//File.Copy(@"C:\Repos\nfdi4plants\ArcGraphModel\src\ArcGraphModel\bin\Debug\net6.0\ArcGraphModel.dll", @"C:\Repos\nfdi4plants\ArcGraphModel\src\ArcGraphModel\bin\Debug\net6.0\ArcGraphModel_Copy.dll", true)

#r "nuget: FSharpAux"
#r "nuget: FsOboParser"
//#r "nuget: FsOboParser"
#r "nuget: OBO.NET"
#r "nuget: FsSpreadsheet.ExcelIO, 4.1.0"
#r "nuget: FSharp.FGL.ArrayAdjacencyGraph"

Expand Down Expand Up @@ -37,13 +38,20 @@ open System.Collections.Generic

open FsSpreadsheet
open FsSpreadsheet.ExcelIO
open FsOboParser
//open FsOboParser
open OBO.NET
//open FsSpreadsheet.DSL
open ControlledVocabulary
open type ControlledVocabulary.ParamBase
open ARCTokenization
open ARCTokenization.StructuralOntology


let ot = List.head Terms.InvestigationMetadata.ontology.Terms

ARCTokenization.StructuralOntology.CodeGeneration.toCodeString ot
CodeGeneration.toSourceCode "Investigation" Terms.InvestigationMetadata.ontology

System.IO.Directory.GetCurrentDirectory()
let fakePath = CvParam(cvTerm = AFSO.``File Path``, v = System.IO.Directory.GetCurrentDirectory() + "/tests/ARCTokenization.Tests/Fixtures/correct/investigation_simple.xlsx")

Expand Down
1 change: 1 addition & 0 deletions tests/ARCTokenization.Tests/ARCTokenization.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Compile Include="TestObjects.fs" />
<Compile Include="ReferenceObjects.fs" />
<Compile Include="StructuralOntologyTests.fs" />
<Compile Include="CodeGenerationTests.fs" />
<Compile Include="TokenizationTests\ProcessGraphTokenization.fs" />
<Compile Include="TokenizationTests\MetadataTokenization.fs" />
<Compile Include="TokenizationTests\FileSystemTokenization.fs" />
Expand Down
51 changes: 51 additions & 0 deletions tests/ARCTokenization.Tests/CodeGenerationTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace CodeGenerationTests

open OBO.NET
open ARCTokenization
open ARCTokenization.Terms
open Xunit
open ARCTokenization.StructuralOntology
open FSharpAux
open type System.Environment

open TestUtils


module toUnderscoredName =

[<Fact>]
let ``returns correct underscored name`` () =
let expected = "Investigation_Metadata"
let actual = List.head InvestigationMetadata.ontology.Terms |> CodeGeneration.toUnderscoredName
Assert.Equal(expected, actual)


module toTermSourceRef =

[<Fact>]
let ``returns correct TermSourceRef`` () =
let expected = "INVMSO"
let actual = List.head InvestigationMetadata.ontology.Terms |> CodeGeneration.toTermSourceRef
Assert.Equal(expected, actual)


module toCodeString =

[<Fact>]
let ``returns correct F# code`` () =
let expected = $" let Investigation_Metadata = CvTerm.create(\"INVMSO:00000001\", \"Investigation Metadata\", \"INVMSO\"){NewLine}{NewLine}"
let actual = List.head InvestigationMetadata.ontology.Terms |> CodeGeneration.toCodeString
Assert.Equal(expected, actual)


module toSourceCode =

[<Fact>]
let ``returns correct source code`` () =
let expected = $"namespace ARCTokenization.StructuralOntology{NewLine}{NewLine} open ControlledVocabulary{NewLine}{NewLine} module Investigation ={NewLine}{NewLine} let Investigation_Metadata = CvTerm.create(\"INVMSO:00000001\", \"Investigation Metadata\", \"INVMSO\"){NewLine}{NewLine} let ONTOLOGY_SOURCE_REFERENCE = CvTerm.create(\"INVMSO:00000002\", \"ONTOLOGY SOURCE REFERENCE\", \"INVMSO\"){NewLine}{NewLine} let Term_Source_Name = CvTerm.create(\"INVMSO:00000003\", \"Term Source Name\", \"INVMSO\")"
let actual =
CodeGeneration.toSourceCode "Investigation" InvestigationMetadata.ontology
|> String.splitS NewLine
|> Array.take 11
|> String.concat NewLine
Assert.Equal(expected, actual)

0 comments on commit 8c49196

Please sign in to comment.