Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 92 additions & 90 deletions yarn-project/simulator/src/avm/avm_memory_types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,96 +39,98 @@ describe('TaggedMemory', () => {

type IntegralClass = typeof Uint8 | typeof Uint16 | typeof Uint32 | typeof Uint64 | typeof Uint128;
describe.each([Uint8, Uint16, Uint32, Uint64, Uint128])('Integral Types', (clsValue: IntegralClass) => {
it(`Should construct a new ${clsValue.name} from a number`, () => {
const x = new clsValue(5);
expect(x.toBigInt()).toStrictEqual(5n);
});

it(`Should construct a new ${clsValue.name} from a bigint`, () => {
const x = new clsValue(5n);
expect(x.toBigInt()).toStrictEqual(5n);
});

it(`Should build a new ${clsValue.name}`, () => {
const x = new clsValue(5);
const newX = x.build(10n);
expect(newX).toStrictEqual(new clsValue(10n));
});

it(`Should add two ${clsValue.name} correctly`, () => {
const a = new clsValue(5);
const b = new clsValue(10);
const result = a.add(b);
expect(result).toStrictEqual(new clsValue(15n));
});

it(`Should subtract two ${clsValue.name} correctly`, () => {
const a = new clsValue(10);
const b = new clsValue(5);
const result = a.sub(b);
expect(result).toStrictEqual(new clsValue(5n));
});

it(`Should multiply two ${clsValue.name} correctly`, () => {
const a = new clsValue(5);
const b = new clsValue(10);
const result = a.mul(b);
expect(result).toStrictEqual(new clsValue(50n));
});

it(`Should divide two ${clsValue.name} correctly`, () => {
const a = new clsValue(10);
const b = new clsValue(5);
const result = a.div(b);
expect(result).toStrictEqual(new clsValue(2n));
});

it('Should shift right ${clsValue.name} correctly', () => {
const uintA = new clsValue(10);
const result = uintA.shr(new clsValue(1n));
expect(result).toEqual(new clsValue(5n));
});

it('Should shift left ${clsValue.name} correctly', () => {
const uintA = new clsValue(10);
const result = uintA.shl(new clsValue(1n));
expect(result).toEqual(new clsValue(20n));
});

it('Should and two ${clsValue.name} correctly', () => {
const uintA = new clsValue(10);
const uintB = new clsValue(5);
const result = uintA.and(uintB);
expect(result).toEqual(new clsValue(0n));
});

it('Should or two ${clsValue.name} correctly', () => {
const uintA = new clsValue(10);
const uintB = new clsValue(5);
const result = uintA.or(uintB);
expect(result).toEqual(new clsValue(15n));
});

it('Should xor two ${clsValue.name} correctly', () => {
const uintA = new clsValue(10);
const uintB = new clsValue(5);
const result = uintA.xor(uintB);
expect(result).toEqual(new clsValue(15n));
});

it(`Should check equality of two ${clsValue.name} correctly`, () => {
const a = new clsValue(5);
const b = new clsValue(5);
const c = new clsValue(10);
expect(a.equals(b)).toBe(true);
expect(a.equals(c)).toBe(false);
});

it(`Should check if one ${clsValue.name} is less than another correctly`, () => {
const a = new clsValue(5);
const b = new clsValue(10);
expect(a.lt(b)).toBe(true);
expect(b.lt(a)).toBe(false);
describe(`${clsValue.name}`, () => {
it(`Should construct a new ${clsValue.name} from a number`, () => {
const x = new clsValue(5);
expect(x.toBigInt()).toStrictEqual(5n);
});

it(`Should construct a new ${clsValue.name} from a bigint`, () => {
const x = new clsValue(5n);
expect(x.toBigInt()).toStrictEqual(5n);
});

it(`Should build a new ${clsValue.name}`, () => {
const x = new clsValue(5);
const newX = x.build(10n);
expect(newX).toStrictEqual(new clsValue(10n));
});

it(`Should add two ${clsValue.name} correctly`, () => {
const a = new clsValue(5);
const b = new clsValue(10);
const result = a.add(b);
expect(result).toStrictEqual(new clsValue(15n));
});

it(`Should subtract two ${clsValue.name} correctly`, () => {
const a = new clsValue(10);
const b = new clsValue(5);
const result = a.sub(b);
expect(result).toStrictEqual(new clsValue(5n));
});

it(`Should multiply two ${clsValue.name} correctly`, () => {
const a = new clsValue(5);
const b = new clsValue(10);
const result = a.mul(b);
expect(result).toStrictEqual(new clsValue(50n));
});

it(`Should divide two ${clsValue.name} correctly`, () => {
const a = new clsValue(10);
const b = new clsValue(5);
const result = a.div(b);
expect(result).toStrictEqual(new clsValue(2n));
});

it(`Should shift right ${clsValue.name} correctly`, () => {
const uintA = new clsValue(10);
const result = uintA.shr(new clsValue(1n));
expect(result).toEqual(new clsValue(5n));
});

it(`Should shift left ${clsValue.name} correctly`, () => {
const uintA = new clsValue(10);
const result = uintA.shl(new clsValue(1n));
expect(result).toEqual(new clsValue(20n));
});

it(`Should and two ${clsValue.name} correctly`, () => {
const uintA = new clsValue(10);
const uintB = new clsValue(5);
const result = uintA.and(uintB);
expect(result).toEqual(new clsValue(0n));
});

it(`Should or two ${clsValue.name} correctly`, () => {
const uintA = new clsValue(10);
const uintB = new clsValue(5);
const result = uintA.or(uintB);
expect(result).toEqual(new clsValue(15n));
});

it(`Should xor two ${clsValue.name} correctly`, () => {
const uintA = new clsValue(10);
const uintB = new clsValue(5);
const result = uintA.xor(uintB);
expect(result).toEqual(new clsValue(15n));
});

it(`Should check equality of two ${clsValue.name} correctly`, () => {
const a = new clsValue(5);
const b = new clsValue(5);
const c = new clsValue(10);
expect(a.equals(b)).toBe(true);
expect(a.equals(c)).toBe(false);
});

it(`Should check if one ${clsValue.name} is less than another correctly`, () => {
const a = new clsValue(5);
const b = new clsValue(10);
expect(a.lt(b)).toBe(true);
expect(b.lt(a)).toBe(false);
});
});
});

Expand Down
Loading