Skip to content

Commit

Permalink
Add ArcTable.iter(i) ✨ #249
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Nov 14, 2023
1 parent efff208 commit 527dd5f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/ISA/ISA/ArcTypes/ArcTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ type ArcTable(name: string, headers: ResizeArray<CompositeHeader>, values: Syste
fun (table:ArcTable) ->
table.TryGetCellAt(column, row)

member this.IterColumns(mapping: CompositeColumn -> unit) =
for columnIndex in 0 .. (this.ColumnCount-1) do
let column = this.GetColumn columnIndex
mapping column

member this.IteriColumns(mapping: int -> CompositeColumn -> unit) =
for columnIndex in 0 .. (this.ColumnCount-1) do
let column = this.GetColumn columnIndex
mapping columnIndex column

// - Cell API - //
// TODO: And then directly a design question. Is a column with rows containing both CompositeCell.Term and CompositeCell.Unitized allowed?
Expand Down
8 changes: 4 additions & 4 deletions src/ISA/ISA/ArcTypes/ArcTables.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ module ArcTablesAux =

match table.TryGetInputColumn() with
| Some ic ->
let ioType = ic.Header.tryInput().Value
let ioType = ic.Header.TryInput().Value
ic.Cells
|> Array.iter (fun c ->
includeInMap (c.ToFreeTextCell().AsFreeText) ioType
)
| None -> ()
match table.TryGetOutputColumn() with
| Some oc ->
let ioType = oc.Header.tryOutput().Value
let ioType = oc.Header.TryOutput().Value
oc.Cells
|> Array.iter (fun c ->
includeInMap (c.ToFreeTextCell().AsFreeText) ioType
Expand All @@ -72,7 +72,7 @@ module ArcTablesAux =
match table.TryGetInputColumn() with
| Some ic ->
let index = table.Headers |> Seq.findIndex (fun x -> x.isInput)
let oldIoType = ic.Header.tryInput().Value
let oldIoType = ic.Header.TryInput().Value
let newIOType =
ic.Cells
|> Array.fold (fun (io : IOType) c ->
Expand All @@ -85,7 +85,7 @@ module ArcTablesAux =
match table.TryGetOutputColumn() with
| Some oc ->
let index = table.Headers |> Seq.findIndex (fun x -> x.isOutput)
let oldIoType = oc.Header.tryOutput().Value
let oldIoType = oc.Header.TryOutput().Value
let newIOType =
oc.Cells
|> Array.fold (fun (io : IOType) c ->
Expand Down
12 changes: 12 additions & 0 deletions tests/ISA/ISA.Tests/ArcTable.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,17 @@ let private tests_Join = testList "Join" [
]
]

let private tests_IterColumns = testList "IterColumns" [
testCase "Replace input column header" <| fun _ ->
let table = create_testTable()
let expected = CompositeHeader.Input IOType.RawDataFile
table.IteriColumns (fun i c ->
if c.Header.isInput then
table.UpdateHeader(i,expected)
)
Expect.equal table.Columns.[0].Header expected ""
]

let private tests_equality = testList "equality" [
testList "override equality" [
testCase "equal" <| fun _ ->
Expand Down Expand Up @@ -2244,6 +2255,7 @@ let main =
tests_validate
tests_UpdateRefWithSheet
tests_Join
tests_IterColumns
tests_GetHashCode
tests_equality
]

0 comments on commit 527dd5f

Please sign in to comment.