@@ -25,6 +25,8 @@ function addEncodingTests() {
2525 STATEMENTS= " $STATEMENTS testCases(${TEST_CASE_COUNTER} ) = Array(${latd} , ${lngd} , ${lati} , ${lngi} , ${len} , \" ${code} \" )\n"
2626 TEST_CASE_COUNTER= $(( TEST_CASE_COUNTER+ 1 ))
2727 done < ../test_data/encoding.csv
28+ # VB uses 0-based indexing for the array.
29+ TEST_CASE_MAX_INDEX= $(( TEST_CASE_COUNTER- 1 ))
2830
2931 # Add the VB function.
3032 echo -e " Private Function loadEncodingTestCSV() AS Variant\n\n Dim testCases(${TEST_CASE_COUNTER} ) As Variant" >> " $VBA_TEST "
@@ -36,6 +38,7 @@ function addEncodingTests() {
3638 cat << EOF >> " $VBA_TEST "
3739
3840' Check the degrees to integer conversions.
41+ ' Due to floating point precision limitations, we may get values 1 less than expected.
3942Sub TEST_IntegerConversion ()
4043 Dim encodingTests As Variant
4144 Dim i As Integer
@@ -46,19 +49,19 @@ Sub TEST_IntegerConversion()
4649
4750 encodingTests = loadEncodingTestCSV ()
4851
49- For i = 0 To ${TEST_CASE_COUNTER }
52+ For i = 0 To ${TEST_CASE_MAX_INDEX }
5053 tc = encodingTests(i)
5154 degrees = tc(0)
5255 want_integer = tc(2)
5356 got_integer = latitudeToInteger(degrees)
54- If got_integer <> want_integer Then
57+ If got_integer < want_integer - 1 Or got_integer > want_integer Then
5558 MsgBox (" Encoding test " + CStr(i) + " : latitudeToInteger(" + CStr(degrees) + " ): got " + CStr(got_integer) + " , want " + CStr(want_integer))
5659 Exit Sub
5760 End If
5861 degrees = tc(1)
5962 want_integer = tc(3)
6063 got_integer = longitudeToInteger(degrees)
61- If got_integer <> want_integer Then
64+ If got_integer < want_integer - 1 Or got_integer > want_integer Then
6265 MsgBox (" Encoding test " + CStr(i) + " : longitudeToInteger(" + CStr(degrees) + " ): got " + CStr(got_integer) + " , want " + CStr(want_integer))
6366 Exit Sub
6467 End If
@@ -80,7 +83,7 @@ Sub TEST_IntegerEncoding()
8083
8184 encodingTests = loadEncodingTestCSV()
8285
83- For i = 0 To ${TEST_CASE_COUNTER }
86+ For i = 0 To ${TEST_CASE_MAX_INDEX }
8487 tc = encodingTests(i)
8588 ' Latitude and longitude are the integer values, not degrees.
8689 latitude = tc(2)
@@ -208,6 +211,7 @@ Sub TEST_OLCLibrary()
208211 MsgBox (" TEST_OLCLibrary passes" )
209212End Sub
210213
214+ ' Main test function. This will call the other test functions one by one.
211215Sub TEST_All()
212216 TEST_OLCLibrary
213217
0 commit comments