Skip to content

Commit 98fb467

Browse files
authored
Merge pull request #54 from CSBiology/hash_hotfix
Hotfix DynamicObj hash failing for empty list
2 parents 1336865 + 792a134 commit 98fb467

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/DynamicObj/DynamicObj.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,15 @@ and HashUtils =
420420
let c = en.Current :?> System.Collections.DictionaryEntry
421421
HashCodes.mergeHashes (hash c.Key) (HashUtils.deepHash c.Value)
422422
]
423-
|> List.reduce HashCodes.mergeHashes
423+
|> fun l -> if l.IsEmpty then 0 else l |> List.reduce HashCodes.mergeHashes
424424
#endif
425425
| :? System.Collections.IEnumerable as e ->
426426
let en = e.GetEnumerator()
427427
[
428428
while en.MoveNext() do
429429
HashUtils.deepHash en.Current
430430
]
431-
|> List.reduce HashCodes.mergeHashes
431+
|> fun l -> if l.IsEmpty then 0 else l |> List.reduce HashCodes.mergeHashes
432432
| _ -> DynamicObj.HashCodes.hash o
433433

434434
and CopyUtils =

tests/DynamicObject.Tests/HashUtils.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ let tests_Dictionary =
146146

147147
let tests_Lists =
148148
testList "Lists" [
149+
testCase "Empty" <| fun _ ->
150+
Expect.equal (HashUtils.deepHash []) (HashUtils.deepHash []) "Empty List should return consistent Hash"
149151
testList "Shuffled Int" [
150152
testCase "1v1" <| fun _ ->
151153
Expect.equal (HashUtils.deepHash intList1) (HashUtils.deepHash intList1) "Same List should return consistent Hash"
@@ -167,6 +169,8 @@ let tests_Lists =
167169

168170
let tests_Array =
169171
testList "Array" [
172+
testCase "Empty" <| fun _ ->
173+
Expect.equal (HashUtils.deepHash [||]) (HashUtils.deepHash [||]) "Empty Array should return consistent Hash"
170174
testList "Shuffled Int" [
171175
testCase "1v1" <| fun _ ->
172176
Expect.equal (HashUtils.deepHash intArray1) (HashUtils.deepHash intArray1) "Same Array should return consistent Hash"
@@ -179,6 +183,8 @@ let tests_Array =
179183

180184
let tests_Seq =
181185
testList "Seq" [
186+
testCase "Empty" <| fun _ ->
187+
Expect.equal (HashUtils.deepHash Seq.empty) (HashUtils.deepHash Seq.empty) "Empty Seq should return consistent Hash"
182188
testList "Shuffled Int" [
183189
testCase "1v1" <| fun _ ->
184190
Expect.equal (HashUtils.deepHash intSeq1) (HashUtils.deepHash intSeq1) "Same Seq should return consistent Hash"
@@ -191,6 +197,8 @@ let tests_Seq =
191197

192198
let tests_ResizeArray =
193199
testList "ResizeArray" [
200+
testCase "Empty" <| fun _ ->
201+
Expect.equal (HashUtils.deepHash (ResizeArray [])) (HashUtils.deepHash (ResizeArray [])) "Empty ResizeArray should return consistent Hash"
194202
testList "Shuffled Int" [
195203
testCase "1v1" <| fun _ ->
196204

0 commit comments

Comments
 (0)