Skip to content

Commit

Permalink
Add unit tests for FsAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Mar 10, 2023
1 parent 65dbd74 commit 3337d57
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
96 changes: 96 additions & 0 deletions tests/FsSpreadsheet.Tests/FsAddress.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
module FsAddress

open Expecto
open FsSpreadsheet


let testAddress1 = FsAddress("B5")
let testAddress2 = FsAddress(3, 2)
let testAddress3 = FsAddress(4, 8, true, true)
let testAddress4 = FsAddress(2, "D", true, true)
let testAddress5 = FsAddress("Z69")
let testAddress6 = FsAddress(5, 2)


[<Tests>]
let fsAddressTests =
testList "FsAddress" [
testList "Constructors" [
testList "cellAddressString" [
testCase "RowNumber" <| fun _ ->
Expect.equal testAddress1.RowNumber 5 "RowNumber differs"
testCase "ColumnNumber" <| fun _ ->
Expect.equal testAddress1.ColumnNumber 2 "ColumnNumber differs"
testCase "Address" <| fun _ ->
Expect.equal testAddress1.Address "B5" "Excel-style address differs"
testCase "FixedRow" <| fun _ ->
Expect.isFalse testAddress1.FixedRow "FixedRow is not false"
testCase "FixedColumn" <| fun _ ->
Expect.isFalse testAddress1.FixedColumn "FixedColumn is not false"
]
testList "rowNumber, columnNumber" [
testCase "RowNumber" <| fun _ ->
Expect.equal testAddress2.RowNumber 3 "RowNumber differs"
testCase "ColumnNumber" <| fun _ ->
Expect.equal testAddress2.ColumnNumber 2 "ColumnNumber differs"
testCase "Address" <| fun _ ->
Expect.equal testAddress2.Address "B3" "Excel-style address differs"
testCase "FixedRow" <| fun _ ->
Expect.isFalse testAddress2.FixedRow "FixedRow is not false"
testCase "FixedColumn" <| fun _ ->
Expect.isFalse testAddress2.FixedColumn "FixedColumn is not false"
]
testList "rowNumber, columnNumber, fixedRow, fixedColumn" [
testCase "RowNumber" <| fun _ ->
Expect.equal testAddress3.RowNumber 4 "RowNumber differs"
testCase "ColumnNumber" <| fun _ ->
Expect.equal testAddress3.ColumnNumber 8 "ColumnNumber differs"
testCase "Address" <| fun _ ->
Expect.equal testAddress3.Address "H4" "Excel-style address differs"
testCase "FixedRow" <| fun _ ->
Expect.isFalse testAddress3.FixedRow "FixedRow is not false"
testCase "FixedColumn" <| fun _ ->
Expect.isFalse testAddress3.FixedColumn "FixedColumn is not false"
]
testList "rowNumber, columnLetter, fixedRow, fixedColumn" [
testCase "RowNumber" <| fun _ ->
Expect.equal testAddress4.RowNumber 2 "RowNumber differs"
testCase "ColumnNumber" <| fun _ ->
Expect.equal testAddress4.ColumnNumber 4 "ColumnNumber differs"
testCase "Address" <| fun _ ->
Expect.equal testAddress4.Address "D2" "Excel-style address differs"
testCase "FixedRow" <| fun _ ->
Expect.isFalse testAddress4.FixedRow "FixedRow is not false"
testCase "FixedColumn" <| fun _ ->
Expect.isFalse testAddress4.FixedColumn "FixedColumn is not false"
]
]
testList "UpdateIndices" [
testList "rowIndex, colIndex" [ // @Contributors: 1 testList per overload pls
do testAddress5.UpdateIndices(4,1) |> ignore
testCase "RowNumber" <| fun _ ->
Expect.equal testAddress5.RowNumber 4 "RowNumber differs"
testCase "ColumnNumber" <| fun _ ->
Expect.equal testAddress5.ColumnNumber 1 "ColumnNumber differs"
]
]
testList "ToIndices" [
testList "rowIndex, colIndex" [
let rowIndex, colIndex = testAddress1.ToIndices()
testCase "RowNumber" <| fun _ ->
Expect.equal rowIndex 5 "RowNumber differs"
testCase "ColumnNumber" <| fun _ ->
Expect.equal colIndex 2 "ColumnNumber differs"
]
]
testList "Compare" [
testList "address" [
testCase "testAddress1 vs testAddress2" <| fun _ ->
let result = testAddress1.Compare testAddress2
Expect.isFalse result "Addresses do not differ"
testCase "testAddress1 vs testAddress6" <| fun _ ->
let result = testAddress1.Compare testAddress6
Expect.isTrue result "Addresses differ"
]
]
]
1 change: 1 addition & 0 deletions tests/FsSpreadsheet.Tests/FsSpreadsheet.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="FsAddress.fs" />
<Compile Include="FsCell.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
Expand Down

0 comments on commit 3337d57

Please sign in to comment.