Skip to content

Commit

Permalink
Test: improve bitwise tests (#73)
Browse files Browse the repository at this point in the history
* improve bitwise tests

* fix test

* assert xor,or and uptade ptr

* delete bitwise_test.cairo

* rename file

* Add let to declaration

* Rename test

* Re order values in the correct way

* Fix expect order

* Format and clean file

* Format code

* Remove non-used imports

* Add missing import and run tests

---------

Co-authored-by: danielcdz <[email protected]>
  • Loading branch information
danielcdz and danielcdz authored Jun 17, 2024
1 parent c713512 commit 56aefcd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
15 changes: 15 additions & 0 deletions cairo_programs/cairo_0/bitwise_builtin.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%builtins bitwise

from starkware.cairo.common.cairo_builtins import BitwiseBuiltin

func main{bitwise_ptr: BitwiseBuiltin*}() {
assert bitwise_ptr.x = 12; // Binary 1100
assert bitwise_ptr.y = 10; // Binary 1010
assert bitwise_ptr.x_and_y = 8; // Binary 1000
assert bitwise_ptr.x_xor_y = 6; // Binary 0110
assert bitwise_ptr.x_or_y = 14; // Binary 1110

let bitwise_ptr = bitwise_ptr + BitwiseBuiltin.SIZE;

return ();
}
20 changes: 0 additions & 20 deletions cairo_programs/cairo_0/bitwise_builtin_test.cairo

This file was deleted.

12 changes: 0 additions & 12 deletions cairo_programs/cairo_0/bitwise_test.cairo

This file was deleted.

10 changes: 7 additions & 3 deletions src/runners/cairoRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const FIBONACCI_PROGRAM_STRING = fs.readFileSync(
'utf8'
);
const BITWISE_PROGRAM_STRING = fs.readFileSync(
'cairo_programs/cairo_0/bitwise_test.json',
'cairo_programs/cairo_0/bitwise_builtin.json',
'utf8'
);
const EC_OP_PROGRAM_STRING = fs.readFileSync(
Expand Down Expand Up @@ -152,13 +152,17 @@ describe('cairoRunner', () => {

describe('builtins', () => {
describe('bitwise', () => {
test('should compute bitwise 12 & 10', () => {
test('should compute bitwise operations 12 & 10, 12 ^10 and 12 | 10', () => {
const runner = new CairoRunner(BITWISE_PROGRAM);
const config: RunOptions = { relocate: true, offset: 1 };
runner.run(config);
const executionSize = runner.vm.memory.getSegmentSize(1);
const executionEnd = runner.executionBase.add(executionSize);
expect(runner.vm.memory.get(executionEnd.sub(2))).toEqual(new Felt(8n));
expect(runner.vm.memory.get(executionEnd.sub(4))).toEqual(new Felt(8n));
expect(runner.vm.memory.get(executionEnd.sub(3))).toEqual(new Felt(6n));
expect(runner.vm.memory.get(executionEnd.sub(2))).toEqual(
new Felt(14n)
);
});
});

Expand Down

0 comments on commit 56aefcd

Please sign in to comment.