Skip to content

Commit 5a6f144

Browse files
committed
Custom equality for Env
1 parent 7f76845 commit 5a6f144

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Hedgehog.Stateful/Hedgehog.Stateful.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6-
<Version>0.7.0-beta1</Version>
6+
<Version>0.7.0-beta2</Version>
77
<Description>Stateful testing for Hedgehog</Description>
88
<Authors>Alexey Raga</Authors>
99
<Copyright>Copyright © 2025</Copyright>

src/Hedgehog.Stateful/Types.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Env = private {
2525
/// A symbolic variable is not yet bound to a generated value and is used to represent a value in the model before binding occurs.
2626
/// </summary>
2727
[<StructuredFormatDisplay("{DisplayText}")>]
28+
[<CustomEquality; CustomComparison>]
2829
type Var<'T> = private {
2930
/// <summary>
3031
/// The unique integer name of the variable.
@@ -127,6 +128,20 @@ Commands that use Var<T> inputs must override Require to call TryResolve and ret
127128
static member internal CreateSymbolic(value: 'T) : Var<'T> =
128129
{ Name = -1; Default = Some value; Transform = unbox<'T>; ResolvedValue = None }
129130

131+
override this.Equals(other: obj) : bool =
132+
match other with
133+
| :? Var<'T> as otherVar -> this.Name = otherVar.Name
134+
| _ -> false
135+
136+
override this.GetHashCode() : int =
137+
hash this.Name
138+
139+
interface System.IComparable with
140+
member this.CompareTo(other: obj) : int =
141+
match other with
142+
| :? Var<'T> as otherVar -> compare this.Name otherVar.Name
143+
| _ -> invalidArg (nameof other) "Cannot compare values of different types"
144+
130145

131146
module internal Env =
132147
/// Empty environment

0 commit comments

Comments
 (0)