Skip to content

Commit

Permalink
Fix unexpected hash mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Aug 22, 2023
1 parent fe06299 commit a567a3d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 7 deletions.
1 change: 0 additions & 1 deletion build.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@echo off
cls

dotnet run --project ./build/Build.fsproj %*
41 changes: 38 additions & 3 deletions playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,52 @@ open System.Collections.Generic
//#r @"C:\Repos\nfdi4plants\ArcGraphModel\src\ArcGraphModel\bin\Debug\netstandard2.0\ArcGraphModel.dll"
//#r @"C:\Repos\nfdi4plants\ArcGraphModel\src\ArcGraphModel.IO\bin\Debug\netstandard2.0\ArcGraphModel.IO.dll"
//#r @"C:/Users/olive/.nuget/packages/fsharpaux/1.1.0/lib/net5.0/FSharpAux.dll"
#r "src/ArcGraphModel/bin/Release/netstandard2.0/ArcGraphModel.dll"
#r "src/ControlledVocabulary/bin/Release/netstandard2.0/ControlledVocabulary.dll"
//#r "src/ArcGraphModel/bin/Release/netstandard2.0/ArcGraphModel.dll"
//#r "src/ControlledVocabulary/bin/Release/netstandard2.0/ControlledVocabulary.dll"
#I "src/ControlledVocabulary/bin/Debug/netstandard2.0"
#I "src/ControlledVocabulary/bin/Release/netstandard2.0"
#r "ControlledVocabulary.dll"
#I "src/ARCTokenization/bin/Debug/netstandard2.0"
#I "src/ARCTokenization/bin/Release/netstandard2.0"
#r "ARCTokenization.dll"

open FsSpreadsheet
open FsSpreadsheet.ExcelIO
open FsOboParser
//open FsSpreadsheet.DSL
open ControlledVocabulary
open ControlledVocabulary.ParamBase
open type ControlledVocabulary.ParamBase
open ARCTokenization

let testAccession1 = "TO:00000001"
let testName1 = "Test"
let testRef1 = "TO"

let testTerm1 = CvTerm.create(accession = testAccession1, name = testName1, ref = testRef1)

let testAccession2 = "TO:00000002"
let testName2 = "5"
let testRef2 = "TO"

let testTerm2 = CvTerm.create(accession = testAccession2, name = testName2, ref = testRef2)

let ``CvParam with ParamValue.Value`` = CvParam(testTerm1, ParamValue.Value 5)
let ``CvParam with ParamValue.CvValue`` = CvParam(testTerm1, ParamValue.CvValue testTerm2)
let ``CvParam with ParamValue.WithCvUnitAccession`` = CvParam(testTerm2, ParamValue.WithCvUnitAccession (5, testTerm1))

let testCvParams =
[
``CvParam with ParamValue.Value``
``CvParam with ParamValue.CvValue``
``CvParam with ParamValue.WithCvUnitAccession``
]
let testCvp1 = CvParam("test", "test", "test", ParamValue.Value "test", Dictionary<string,IParam>() |> fun d -> d.Add("test", testCvParams.Head); d)
let testCvp2 = CvParam("test", "test", "test", ParamValue.Value "test", Dictionary<string,IParam>() |> fun d -> d.Add("test", testCvParams.Head); d)
let actual = testCvp1 = testCvp2
testCvp1.GetHashCode()
testCvp2.GetHashCode()



let expectedTermValuesSimple =
[
Expand Down
9 changes: 8 additions & 1 deletion src/ControlledVocabulary/CvContainer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ type CvContainer (
CvContainer(term, dict)
new (term : CvTerm) = CvContainer (term, Seq.empty)

/// Serves as the default hash function.
override this.GetHashCode() =
hash (cvAccession, cvName, cvRef, attributes, properties)

/// Determines whether the specified object is equals to the current object.
override this.Equals(o) =
match o with
| :? CvContainer as cvc -> cvc.GetHashCode() = this.GetHashCode()
| :? CvContainer as cvc ->
(cvc :> ICvBase).Accession = (this :> ICvBase).Accession &&
(cvc :> ICvBase).Name = (this :> ICvBase).Name &&
(cvc :> ICvBase).RefUri = (this :> ICvBase).RefUri &&
cvc.Attributes = this.Attributes &&
cvc.Properties = this.Properties
| :? ICvBase as cvb -> CvBase.equals cvb this
| _ -> false

Expand Down
1 change: 1 addition & 0 deletions src/ControlledVocabulary/CvObject.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type CvObject<'T>(cvAccession : string, cvName : string, cvRef : string, object
| :? ICvBase as cvb -> CvBase.equals cvb this
| _ -> false

/// Serves as the default hash function.
override this.GetHashCode() =
hash (cvAccession, cvName, cvRef, attributes)

Expand Down
9 changes: 8 additions & 1 deletion src/ControlledVocabulary/CvParam.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,20 @@ type CvParam(cvAccession : string, cvName : string, cvRef : string, paramValue :
new (cvTerm,v : IConvertible) =
CvParam (cvTerm,ParamValue.Value v)

/// Serves as the default hash function.
override this.GetHashCode() =
hash (cvAccession, cvName, cvRef, paramValue, attributes)

/// Determines whether the specified object is equals to the current object.
override this.Equals(o) =
match o with
| :? CvTerm as cvt -> Param.equalsTerm cvt this
| :? CvParam as cvp -> cvp.GetHashCode() = this.GetHashCode()
| :? CvParam as cvp ->
cvp.Name = this.Name &&
cvp.Accession = this.Accession &&
cvp.RefUri = this.RefUri &&
cvp.Value = this.Value &&
cvp.Attributes = this.Attributes // careful bc of Dictionary! Comment out if necessary!
| :? IParam as p ->
p.Name = this.Name &&
p.Accession = this.Accession &&
Expand Down
7 changes: 6 additions & 1 deletion src/ControlledVocabulary/UserParam.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ type UserParam(name : string, paramValue : ParamValue, attributes : IDictionary<
new (name,pv) =
UserParam (name,pv,Seq.empty)

/// Serves as the default hash function.
override this.GetHashCode() =
hash (name, paramValue, attributes)

/// Determines whether the specified object is equals to the current object.
override this.Equals(o) =
match o with
| :? CvTerm as cvt -> Param.equalsTerm cvt this
| :? UserParam as up -> this.GetHashCode() = up.GetHashCode()
| :? UserParam as up ->
up.Name = this.Name &&
up.Value = this.Value &&
up.Attributes = this.Attributes
| :? IParam as p ->
p.Name = this.Name &&
p.Value = this.Value
Expand Down

0 comments on commit a567a3d

Please sign in to comment.