Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Jan 29, 2024
1 parent 9a57fb8 commit 86af083
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ describe('Arithmetic Instructions', () => {

describe('Sub', () => {
it('Should subtract correctly over field elements', async () => {
const a = new Field(1n);
const b = new Field(2n);

machineState.memory.set(0, a);
machineState.memory.set(1, b);

await new Sub(0, 1, 2).execute(machineState, journal);
Expand Down
17 changes: 17 additions & 0 deletions yarn-project/acir-simulator/src/avm/opcodes/bitwise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ describe('Bitwise instructions', () => {
machineState.memory.set(1, b);

await new Or(TypeTag.UINT32, 0, 1, 2).execute(machineState, journal);

const expected = new Uint32(0b11111110111011101111n);
const actual = machineState.memory.get(2);
expect(actual).toEqual(expected);
});

it('Should XOR correctly over integral types', async () => {
Expand All @@ -59,7 +62,11 @@ describe('Bitwise instructions', () => {
machineState.memory.set(1, b);

await new Shr(TypeTag.UINT32, 0, 1, 2).execute(machineState, journal);

const expected = a;
const actual = machineState.memory.get(2);
expect(actual).toEqual(expected);
});

it('Should shift correctly 2 positions over integral types', async () => {
const a = new Uint32(0b11111110010011100100n);
Expand All @@ -76,6 +83,10 @@ describe('Bitwise instructions', () => {
});

it('Should shift correctly 19 positions over integral types', async () => {
const a = new Uint32(0b11111110010011100100n);
const b = new Uint32(19n);

machineState.memory.set(0, a);
machineState.memory.set(1, b);

await new Shr(TypeTag.UINT32, 0, 1, 2).execute(machineState, journal);
Expand Down Expand Up @@ -109,7 +120,10 @@ describe('Bitwise instructions', () => {
machineState.memory.set(1, b);

await new Shl(TypeTag.UINT32, 0, 1, 2).execute(machineState, journal);

const expected = new Uint32(0b1111111001001110010000n);
const actual = machineState.memory.get(2);
expect(actual).toEqual(expected);
});

it('Should shift correctly over bit limit over integral types', async () => {
Expand All @@ -134,7 +148,10 @@ describe('Bitwise instructions', () => {
machineState.memory.set(1, b);

await new Shl(TypeTag.UINT16, 0, 1, 2).execute(machineState, journal);

const expected = new Uint16(0b1001001110011100n);
const actual = machineState.memory.get(2);
expect(actual).toEqual(expected);
});
});

Expand Down

0 comments on commit 86af083

Please sign in to comment.