Skip to content

Commit

Permalink
refactor: Remove duplicate of varValueEquals (#411)
Browse files Browse the repository at this point in the history
remove duplicate of varValueEquals
  • Loading branch information
TAdev0 committed May 14, 2024
1 parent b1e02ed commit 60548a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
8 changes: 4 additions & 4 deletions pkg/hintrunner/zero/zerohint_usort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestZeroHintUsort(t *testing.T) {
})
},
check: func(t *testing.T, ctx *hintTestContext) {
varAddrResolvedValueEquals("output_length", feltUint64(3))(t, ctx)
varValueEquals("output_length", feltUint64(3))(t, ctx)
consecutiveVarAddrResolvedValueEquals("output", []*fp.Element{
feltUint64(1),
feltUint64(2),
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestZeroHintUsort(t *testing.T) {
})
},
check: func(t *testing.T, ctx *hintTestContext) {
varAddrResolvedValueEquals("output_length", feltUint64(3))(t, ctx)
varValueEquals("output_length", feltUint64(3))(t, ctx)
consecutiveVarAddrResolvedValueEquals("output", []*fp.Element{
feltUint64(1),
feltUint64(2),
Expand Down Expand Up @@ -273,7 +273,7 @@ func TestZeroHintUsort(t *testing.T) {
})
},
check: func(t *testing.T, ctx *hintTestContext) {
varAddrResolvedValueEquals("output_length", feltUint64(6))(t, ctx)
varValueEquals("output_length", feltUint64(6))(t, ctx)
consecutiveVarAddrResolvedValueEquals("output", []*fp.Element{
feltUint64(1),
feltUint64(2),
Expand Down Expand Up @@ -310,7 +310,7 @@ func TestZeroHintUsort(t *testing.T) {
})
},
check: func(t *testing.T, ctx *hintTestContext) {
varAddrResolvedValueEquals("output_length", feltUint64(0))(t, ctx)
varValueEquals("output_length", feltUint64(0))(t, ctx)
consecutiveVarAddrResolvedValueEquals("output", []*fp.Element{})(t, ctx)
consecutiveVarAddrResolvedValueEquals("multiplicities", []*fp.Element{})(t, ctx)
},
Expand Down
26 changes: 7 additions & 19 deletions pkg/hintrunner/zero/zerohint_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
VM "github.com/NethermindEth/cairo-vm-go/pkg/vm"
"github.com/NethermindEth/cairo-vm-go/pkg/vm/memory"
"github.com/consensys/gnark-crypto/ecc/stark-curve/fp"
f "github.com/consensys/gnark-crypto/ecc/stark-curve/fp"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -96,14 +95,11 @@ func varValueEquals(varName string, expected *fp.Element) func(t *testing.T, ctx
}
}

func varAddrResolvedValueEquals(varName string, expected *fp.Element) func(t *testing.T, ctx *hintTestContext) {
func allVarValueEquals(expectedValues map[string]*fp.Element) func(t *testing.T, ctx *hintTestContext) {
return func(t *testing.T, ctx *hintTestContext) {
o := ctx.operanders[varName]
addr, err := o.GetAddress(ctx.vm)
require.NoError(t, err)
actualFelt, err := ctx.vm.Memory.ReadFromAddressAsElement(&addr)
require.NoError(t, err)
require.Equal(t, &actualFelt, expected, "%s value mismatch:\nhave: %v\nwant: %v", varName, &actualFelt, expected)
for varName, expected := range expectedValues {
varValueEquals(varName, expected)(t, ctx)
}
}
}

Expand All @@ -123,14 +119,6 @@ func consecutiveVarAddrResolvedValueEquals(varName string, expectedValues []*fp.
}
}

func allVarValueEquals(expectedValues map[string]*fp.Element) func(t *testing.T, ctx *hintTestContext) {
return func(t *testing.T, ctx *hintTestContext) {
for varName, expected := range expectedValues {
varValueEquals(varName, expected)(t, ctx)
}
}
}

func consecutiveVarValueEquals(varName string, expectedValues []*fp.Element) func(t *testing.T, ctx *hintTestContext) {
return func(t *testing.T, ctx *hintTestContext) {
o := ctx.operanders[varName]
Expand Down Expand Up @@ -191,10 +179,10 @@ func varValueInScopeEquals(varName string, expected any) func(t *testing.T, ctx
t.Fatalf("%s scope value mismatch:\nhave: %d\nwant: %d", varName, value, expected)
}
}
case []f.Element:
case []fp.Element:
{
valueArray := value.([]f.Element)
expectedArray := expected.([]f.Element)
valueArray := value.([]fp.Element)
expectedArray := expected.([]fp.Element)
if !reflect.DeepEqual(valueArray, expectedArray) {
t.Fatalf("%s scope value mismatch:\nhave: %v\nwant: %v", varName, value, expected)
}
Expand Down

0 comments on commit 60548a3

Please sign in to comment.