Skip to content

Commit

Permalink
Merge pull request #500 from nfdi4plants/helpers
Browse files Browse the repository at this point in the history
Add ArcTable related helper functions
  • Loading branch information
HLWeil authored Mar 6, 2025
2 parents 180a10c + d2e1f99 commit 4a309c7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Core/Table/ArcTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ type ArcTable(name: string, headers: ResizeArray<CompositeHeader>, values: Syste
member this.ColumnCount
with get() = ArcTableAux.getColumnCount this.Headers

static member columnCount (table:ArcTable) = table.ColumnCount

member this.RowCount
with get() = ArcTableAux.getRowCount this.Values

static member rowCount (table:ArcTable) = table.RowCount

member this.Columns
with get() = [|for i = 0 to this.ColumnCount - 1 do this.GetColumn(i)|]

Expand Down
14 changes: 13 additions & 1 deletion src/Core/Table/CompositeHeader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,19 @@ type CompositeHeader =
| Characteristic oa -> Characteristic (oa.Copy())
| Component oa -> Component (oa.Copy())
| _ -> this


/// <summary>
/// Returns the term of the column if it is a term column. Otherwise returns None.
///
/// Term columns are Parameter, Factor, Characteristic and Component.
/// </summary>
member this.TryGetTerm() =
match this with
| Parameter oa -> Some oa
| Factor oa -> Some oa
| Characteristic oa -> Some oa
| Component oa -> Some oa
| _ -> None

#if FABLE_COMPILER

Expand Down
8 changes: 8 additions & 0 deletions tests/Core/ArcTable.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ let private tests_member =
let table = create_testTable()
Expect.equal table.ColumnCount 5 ""
)
testCase "ColumnCount Static member" (fun () ->
let table = create_testTable()
Expect.equal (ArcTable.columnCount table) 5 ""
)
testCase "RowCount" (fun () ->
let table = create_testTable()
Expect.equal table.RowCount 5 ""
)
testCase "RowCount Static member" (fun () ->
let table = create_testTable()
Expect.equal (ArcTable.rowCount table) 5 ""
)
testCase "Custom equality" (fun () ->
let table1 = create_testTable()
let table2 = create_testTable()
Expand Down
20 changes: 20 additions & 0 deletions tests/Core/CompositeHeader.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,25 @@ let tests_ToTerm = testList "ToTerm" [
yield! allHeaders |> List.map testToTerm
]

let tests_TryGetTerm = testList "TryGetTerm" [
testCase "Parameter" (fun () ->
let oa = OntologyAnnotation.fromTermAnnotation("LOL:123", name = "MyTerm")
let p1 = CompositeHeader.Parameter(oa)
let term = Expect.wantSome (p1.TryGetTerm()) "Parameter should have term"
Expect.equal term oa "Parameter term should be equal to oa"
)
testCase "FreeText" (fun () ->
let ft1 = CompositeHeader.FreeText("MyText")
let term = ft1.TryGetTerm()
Expect.isNone term "FreeText should not have term"
)
testCase "Input" (fun () ->
let i1 = CompositeHeader.Input(IOType.Source)
let term = i1.TryGetTerm()
Expect.isNone term "Input should not have term"
)
]

let tests_GetHashCode = testList "GetHashCode" [
testCase "SimpleParamEqual" (fun () ->
let oa1 = OntologyAnnotation("MyTerm",tan = "LOL:123")
Expand Down Expand Up @@ -473,6 +492,7 @@ let main =
tests_jsHelper
tests_compositeHeader
tests_ToTerm
tests_TryGetTerm
tests_GetHashCode
tests_comparison
]

0 comments on commit 4a309c7

Please sign in to comment.