From 3337d57f3709bc0a398cee57e1dee24904b10ea3 Mon Sep 17 00:00:00 2001 From: omaus Date: Fri, 10 Mar 2023 20:02:51 +0100 Subject: [PATCH] Add unit tests for FsAddress --- tests/FsSpreadsheet.Tests/FsAddress.fs | 96 +++++++++++++++++++ .../FsSpreadsheet.Tests.fsproj | 1 + 2 files changed, 97 insertions(+) create mode 100644 tests/FsSpreadsheet.Tests/FsAddress.fs diff --git a/tests/FsSpreadsheet.Tests/FsAddress.fs b/tests/FsSpreadsheet.Tests/FsAddress.fs new file mode 100644 index 00000000..73bd19d4 --- /dev/null +++ b/tests/FsSpreadsheet.Tests/FsAddress.fs @@ -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) + + +[] +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" + ] + ] + ] \ No newline at end of file diff --git a/tests/FsSpreadsheet.Tests/FsSpreadsheet.Tests.fsproj b/tests/FsSpreadsheet.Tests/FsSpreadsheet.Tests.fsproj index 514a1385..edbb898a 100644 --- a/tests/FsSpreadsheet.Tests/FsSpreadsheet.Tests.fsproj +++ b/tests/FsSpreadsheet.Tests/FsSpreadsheet.Tests.fsproj @@ -7,6 +7,7 @@ +