如果在F#中获取1维数组的副本,则两个实例的哈希码都相同。 不是这样,看起来如果对Array2D的实例做同样的事情。
以下代码是Xunit单元测试功能,展示了潜在的问题。
[<Fact>]
member this.``test if Array2D has a problem with hash codes`` () =
let a0 = Array2D.init 4 4 ( fun x y -> x * 10 + y )
let a0hc = a0.GetHashCode()
let a1 = Array2D.copy a0
let a1hc0 = a1.GetHashCode()
Assert.Equal(a0hc,a1hc0) // fails!
a1.[0,0] <- 42
let a1hc1 = a1.GetHashCode()
Assert.NotEqual(a1hc0,a1hc1)
a1.[0,0] <- 0
let a1hc2 = a1.GetHashCode()
Assert.Equal(a1hc0,a1hc2)
我的测试代码有问题还是真的是个bug? 或者是设计?