Skip to content

Commit

Permalink
small fixes and adjustments to xlsx reader and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Feb 2, 2024
1 parent c9d00fb commit 8da67c9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/FsSpreadsheet/FsAddress.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ module CellReference =
let ofIndices column (row : uint32) =
sprintf "%s%i" (indexToColAdress column) row

let private charPart = System.Text.StringBuilder()
let private numPart = System.Text.StringBuilder()


/// Maps a "A1" style excel cell reference to a column * row index tuple (1 Based indices).
let toIndices (reference : string) =
let charPart = charPart.Clear()
let numPart = numPart.Clear()
let charPart = System.Text.StringBuilder()
let numPart = System.Text.StringBuilder()

reference
|> Seq.iter (fun c ->
Expand Down
12 changes: 7 additions & 5 deletions tests/FsSpreadsheet.ExcelIO.Tests/ZipArchiveReader.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module ZipArchiveReader

open Expecto
open TestingUtils
open FsSpreadsheet
open FsSpreadsheet.ExcelIO.ZipArchiveReader
Expand Down Expand Up @@ -35,15 +34,18 @@ let tests_Read = testList "Read" [
Expect.isDefaultTestObject wb
]

open FsSpreadsheet.ExcelIO

let performanceTest = testList "Performance" [
testCase "BigFile" <| fun _ ->
let readF() = FsWorkbook.fromFile("./TestFiles/BigFile.xlsx")
let wb = Expect.wantFaster readF 5 "Reader too slow"
Expect.equal (wb.GetWorksheetAt(1).Rows.Count) 153991 "Row count should be equal"
let readF() = FsWorkbook.fromFile("./TestFiles/BigFile.xlsx") |> ignore
let refReadF() = FsWorkbook.fromXlsxFile("./TestFiles/BigFile.xlsx") |> ignore
Expect.isFasterThan readF refReadF "ZipArchiveReader should be faster than standard reader"
//Expect.equal (wb.GetWorksheetAt(1).Rows.Count) 153991 "Row count should be equal"
]


[<Tests>]
[<Expecto.Tests>]
let main = testList "ZipArchiveReader" [
performanceTest
tests_Read
Expand Down
13 changes: 13 additions & 0 deletions tests/FsSpreadsheet.Tests/FsWorksheetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,22 @@ let tests_SortRows = testList "SortRows" [
Utils.Expect.mySequenceEqual ws.Rows rows "equal"
]

let tests_rescanRows = testList "RescanRows" [
testCase "empty" <| fun _ ->
dummySheet1.RescanRows()
Expect.hasLength dummySheet1.Rows 0 "row count"
testCase "rows" <| fun _ ->
let ws = createBigDummySheet()
let rows = ResizeArray(ws.Rows) // create copy
ws.RescanRows()
Utils.Expect.mySequenceEqual ws.Rows rows "equal"
]


let main =
testSequenced <| testList "FsWorksheet" [
tests_SortRows
tests_rescanRows
testList "FsCell data" [
// TO DO: Ask TM: useful? or was that a mistake? (since the same test is seen in FsCell.fs)
testList "Data | DataType | Adress" [
Expand Down
4 changes: 3 additions & 1 deletion tests/Speedtest/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ let main argv =
let readAssay() = ZipArchiveReader.FsWorkbook.fromFile assayPath
let readStudy() = ZipArchiveReader.FsWorkbook.fromFile studyPath
let readInvestigation() = ZipArchiveReader.FsWorkbook.fromFile investigationPath
let bigFile() = ZipArchiveReader.FsWorkbook.fromFile @"C:\Users\HLWei\source\repos\IO\FsSpreadsheet\tests\TestUtils\TestFiles\BigFile.xlsx"


readInvestigation() |> ignore
readAssay() |> ignore
readStudy() |> ignore

bigFile() |> ignore

let closedXML() =

Expand Down
14 changes: 14 additions & 0 deletions tests/TestUtils/TestingUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ module Expect =
failwithf $"{message}. Expected to be faster than {maxMilliseconds}ms, but took {elapsed.TotalMilliseconds}ms"
res

let isFasterThan (f1 : unit -> _) (f2 : unit -> _) (message : string) =
let stopwatch = Stopwatch()
stopwatch.Start()
f1()
stopwatch.Stop()
let elapsed1 = stopwatch.Elapsed
stopwatch.Start()
f2()
stopwatch.Stop()
let elapsed2 = stopwatch.Elapsed
if elapsed1.TotalMilliseconds > elapsed2.TotalMilliseconds then
failwithf $"{message}. Expected {elapsed1.TotalMilliseconds}ms to be faster than {elapsed2.TotalMilliseconds}ms"
()

let cellSequenceEquals (actual: FsCell seq) (expected: FsCell seq) message =
let cellDiff (s1: FsCell seq) (s2: FsCell seq) =
let s1 = Seq.append (Seq.map Some s1) (Seq.initInfinite (fun _ -> None))
Expand Down

0 comments on commit 8da67c9

Please sign in to comment.