Skip to content

Commit

Permalink
Add FsTable unit tests (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Mar 22, 2023
1 parent 5437128 commit af5a98b
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions tests/FsSpreadsheet.Tests/FsTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ let dummyFsTableFields =
dummyFsCells
|> Seq.map (fun c -> c.RowNumber)
|> Seq.min
let mutable i = -1
dummyFsCells
|> Seq.choose (
fun fsc ->
i <- i + 1
if fsc.RowNumber = headerRowIndex then
FsTableField(
fsc.Value,
fsc.ColumnNumber,
dummyFsRangeColumns |> Seq.find (fun t -> t.Index = fsc.ColumnNumber),
i,
dummyFsRangeColumns |> Seq.find (fun t -> t.RangeAddress.FirstAddress.ColumnNumber = fsc.ColumnNumber),
obj,
obj
)
Expand All @@ -79,15 +81,60 @@ let fsTableTests =
testList "tableFields : seq FsTableField" [
let testFsTable = FsTable("testFsTable", FsRangeAddress(dummyFsCellsCollectionFirstAddress, dummyFsCellsCollectionLastAddress))
testFsTable.AddFields dummyFsTableFields |> ignore
let testNames, testIndeces = testFsTable.Fields dummyFsCellsCollection |> Seq.map (fun tf -> tf.Name, tf.Index) |> Seq.toArray |> Array.unzip
let dummyNames, dummyIndeces = dummyFsTableFields |> Seq.map (fun tf -> tf.Name, tf.Index) |> Seq.toArray |> Array.unzip
let testNames, testIndeces =
testFsTable.Fields dummyFsCellsCollection
|> Seq.map (fun tf -> tf.Name, tf.Index)
|> Seq.toArray
|> Array.unzip
let dummyNames, dummyIndeces =
dummyFsTableFields
|> Seq.map (fun tf -> tf.Name, tf.Index)
|> Seq.toArray
|> Array.unzip
testCase "Names are there" <| fun _ ->
Expect.sequenceEqual testNames dummyNames "Names are not equal"
testCase "Indeces are there" <| fun _ ->
Expect.sequenceEqual testIndeces dummyIndeces "Indeces are not equal"
]
]
testList "TryGetHeaderCellOfColumn" [
//testList ""
testList "cellsCollection : FsCellsCollection, colIndex : int" [
let testHeaderCell = dummyFsTable.TryGetHeaderCellOfColumn(dummyFsCellsCollection, 3)
testCase "Is Some" <| fun _ ->
Expect.isSome testHeaderCell "Is None"
testCase "Has correct value" <| fun _ ->
let actualCell = dummyFsCells |> Seq.item 1
Expect.equal testHeaderCell.Value.Value actualCell.Value "FsCell is incorrect in value"
]
testList "cellsCollection : FsCellsCollection, column : FsRangeColumn" [
let testHeaderCell = dummyFsTable.TryGetHeaderCellOfColumn(dummyFsCellsCollection, Seq.item 1 dummyFsRangeColumns)
testCase "Is Some" <| fun _ ->
Expect.isSome testHeaderCell "Is None"
testCase "Has correct value" <| fun _ ->
let actualCell = dummyFsCells |> Seq.item 1
Expect.equal testHeaderCell.Value.Value actualCell.Value "FsCell is incorrect in value"
]
]
testList "TryGetHeaderCellOfTableField" [
testList "cellsCollection : FsCellsCollection, tableFieldIndex : int" [
let testFsTable = FsTable("testFsTable", FsRangeAddress(dummyFsCellsCollectionFirstAddress, dummyFsCellsCollectionLastAddress))
testFsTable.AddFields dummyFsTableFields
let testHeaderCell = testFsTable.TryGetHeaderCellOfTableField(dummyFsCellsCollection, 1)
testCase "Is Some" <| fun _ ->
Expect.isSome testHeaderCell "Is None"
testCase "Has correct value" <| fun _ ->
let actualCell = dummyFsCells |> Seq.item 1
Expect.equal testHeaderCell.Value.Value actualCell.Value "FsCell is incorrect in value"
]
]
testList "GetHeaderCellOfTableField" [
testList "cellsCollection : FsCellsCollection, tableField : FsTableField" [
let testFsTable = FsTable("testFsTable", FsRangeAddress(dummyFsCellsCollectionFirstAddress, dummyFsCellsCollectionLastAddress))
testFsTable.AddFields dummyFsTableFields
let testHeaderCell = testFsTable.GetHeaderCellOfTableField(dummyFsCellsCollection, Seq.item 1 dummyFsTableFields)
testCase "Has correct value" <| fun _ ->
let actualCell = dummyFsCells |> Seq.item 1
Expect.equal testHeaderCell.Value actualCell.Value "FsCell is incorrect in value"
]
]
]

0 comments on commit af5a98b

Please sign in to comment.