Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify compute res - Add, Mul, Unconstrained #68

Closed
wants to merge 8 commits into from
Closed

Conversation

jkktom
Copy link
Contributor

@jkktom jkktom commented Sep 26, 2023

  • Improved test cases for Add
  • Negative Felt cases for Mul
  • Unconstrained and Op1 cases
    Please kindly discard former branch. I changed too much so just restarted.

Copy link
Contributor

@rodrigo-pino rodrigo-pino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! Some minor issues and is good to go

Comment on lines 220 to 221
mv.address, err = mv.address.Add(lhs.address, rhs.felt)
mv.felt = nil // Felt field is set to nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to set felt member as nil since address is already non nil. MemoryValue only has one member non nil at a time. It works as the union of both types.

If felt and address are both non nil, then the MemoryValue type was misused, that means that the error occurred somewhere before. No need to hide it here.

@@ -346,34 +348,168 @@ func TestInferOperandSub(t *testing.T) {
assert.Equal(t, expectedOp0Cell, op0Cell)
}

func TestComputeAddRes(t *testing.T) {
func TestComputeRes_Unconstrained(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CamelCase for defining Tests, update the name to TestComputeResUnconstrained. Please do this to the other tests as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 355 to 356
cellOp0 := &mem.Cell{Accessed: true, Value: mem.MemoryValueFromInt(10)}
cellOp1 := &mem.Cell{Accessed: true, Value: mem.MemoryValueFromInt(15)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this tests cellOp0 and cellOp1 can be nil since they are not being used by the method being tested

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Test goes with Nil as operands, and succeeds.

vm := defaultVirtualMachine()
instruction := Instruction{Res: Op1}

cellOp0 := &mem.Cell{Accessed: true, Value: mem.MemoryValueFromInt(10)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cellOp0 is not used in this test, so no need to create it to test the function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Cell Operand 0 set to nil, the test succeeds.

vm := defaultVirtualMachine()
instruction := Instruction{Res: AddOperands}

cellOp0 := &mem.Cell{Accessed: true, Value: mem.MemoryValueFromMemoryAddress(mem.NewMemoryAddress(2, 10))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use MemoryValueFromSegmentAndOffset method

}

// Felt should be Positive or Negative. Thus four test cases
func TestComputeMulRes_PToPFelt(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func TestComputeMulRes_PToPFelt(t *testing.T) {
func TestComputeMulResPosToPosFelt(t *testing.T) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Applied to other function names too.

instruction := Instruction{Res: MulOperands}

cellOp0 := &mem.Cell{Accessed: true, Value: mem.MemoryValueFromInt(15)}
cellOp1 := &mem.Cell{Accessed: true, Value: mem.MemoryValueFromMemoryAddress(mem.NewMemoryAddress(2, 10))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use MemoryFromSegmentAndOffset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants