Skip to content

Commit

Permalink
style: run trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
renzobanegass committed Aug 8, 2024
1 parent 3941898 commit 17227a8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/hints/hintHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ import {
shouldSkipSquashLoop,
} from './dict/shouldSkipSquashLoop';
import { TestLessThan, testLessThan } from './math/testLessThan';
import { TestLessThanOrEqualAddress, testLessThanOrEqualAddress } from './math/testLessThanOrEqualAddress';
import {
TestLessThanOrEqualAddress,
testLessThanOrEqualAddress,
} from './math/testLessThanOrEqualAddress';

/**
* Map hint names to the function executing their logic.
Expand Down
2 changes: 1 addition & 1 deletion src/hints/hintName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export enum HintName {
ShouldContinueSquashLoop = 'ShouldContinueSquashLoop',
ShouldSkipSquashLoop = 'ShouldSkipSquashLoop',
TestLessThan = 'TestLessThan',
TestLessThanOrEqualAddress = 'TestLessThanOrEqualAddress'
TestLessThanOrEqualAddress = 'TestLessThanOrEqualAddress',
}
2 changes: 1 addition & 1 deletion src/hints/hintSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const hint = z.union([
shouldContinueSquashLoopParser,
shouldSkipSquashLoopParser,
testLessThanParser,
testLessThanOrEqualAddressParser
testLessThanOrEqualAddressParser,
]);

/** Zod object to parse an array of hints grouped on a given PC */
Expand Down
31 changes: 20 additions & 11 deletions src/hints/math/testLessThanOrEqualAddress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const TEST_LESS_THAN_OR_EQUAL_ADDRESS = {

describe('TestLessThanOrEqualAddress', () => {
test('should properly parse TestLessThanOrEqualAddress hint', () => {
const hint = testLessThanOrEqualAddressParser.parse(TEST_LESS_THAN_OR_EQUAL_ADDRESS);
const hint = testLessThanOrEqualAddressParser.parse(
TEST_LESS_THAN_OR_EQUAL_ADDRESS
);

expect(hint).toEqual({
type: HintName.TestLessThanOrEqualAddress,
Expand Down Expand Up @@ -62,15 +64,22 @@ describe('TestLessThanOrEqualAddress', () => {
[new Relocatable(1, 1), new Relocatable(1, 0), new Felt(0n)],
[new Relocatable(1, 1), new Relocatable(1, 1), new Felt(1n)],
[new Relocatable(0, 0), new Relocatable(1, 0), new Felt(1n)],
])('should properly execute TestLessThanOrEqualAddress hint', (lhs, rhs, expected) => {
const hint = testLessThanOrEqualAddressParser.parse(TEST_LESS_THAN_OR_EQUAL_ADDRESS);
const vm = new VirtualMachine();
vm.memory.addSegment();
vm.memory.addSegment();
vm.memory.assertEq(vm.ap, lhs);
vm.memory.assertEq(vm.ap.add(1), rhs);
])(
'should properly execute TestLessThanOrEqualAddress hint',
(lhs, rhs, expected) => {
const hint = testLessThanOrEqualAddressParser.parse(
TEST_LESS_THAN_OR_EQUAL_ADDRESS
);
const vm = new VirtualMachine();
vm.memory.addSegment();
vm.memory.addSegment();
vm.memory.assertEq(vm.ap, lhs);
vm.memory.assertEq(vm.ap.add(1), rhs);

vm.executeHint(hint);
expect(vm.memory.get(vm.cellRefToRelocatable(hint.dst))).toEqual(expected);
});
vm.executeHint(hint);
expect(vm.memory.get(vm.cellRefToRelocatable(hint.dst))).toEqual(
expected
);
}
);
});
16 changes: 11 additions & 5 deletions src/hints/math/testLessThanOrEqualAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import { Relocatable } from 'primitives/relocatable';
/** Zod object to parse TestLessThanOrEqualAddress hint */
export const testLessThanOrEqualAddressParser = z
.object({
TestLessThanOrEqualAddress: z.object({ lhs: resOperand, rhs: resOperand, dst: cellRef }),
TestLessThanOrEqualAddress: z.object({
lhs: resOperand,
rhs: resOperand,
dst: cellRef,
}),
})
.transform(({ TestLessThanOrEqualAddress: { lhs, rhs, dst } }) => ({
type: HintName.TestLessThanOrEqualAddress,
Expand All @@ -29,13 +33,15 @@ export const testLessThanOrEqualAddressParser = z
*
* Check whether the Relocatable value at `lhs` is inferior or equal to the value at `rhs`
*/
export type TestLessThanOrEqualAddress = z.infer<typeof testLessThanOrEqualAddressParser>;
export type TestLessThanOrEqualAddress = z.infer<
typeof testLessThanOrEqualAddressParser
>;

/**
* TestLessThanOrEqualAddress hint
*
* Compares the values at the relocatable values `lhs` and `rhs` and stores
* the result in `dst`. The result is `1` if the value at `lhs` is
* Compares the values at the relocatable values `lhs` and `rhs` and stores
* the result in `dst`. The result is `1` if the value at `lhs` is
* less than or equal to the value at `rhs`, and `0` otherwise.
*
* @param {VirtualMachine} vm - The virtual machine instance.
Expand All @@ -53,7 +59,7 @@ export const testLessThanOrEqualAddress = (
const rhsValue = vm.getResOperandRelocatable(rhs);

const isLessThanOrEqual = lhsValue <= rhsValue;

const result = new Felt(isLessThanOrEqual ? 1n : 0n);

vm.memory.assertEq(vm.cellRefToRelocatable(dst), result);
Expand Down

0 comments on commit 17227a8

Please sign in to comment.