import { describe, it, expect } from 'vitest';
import { handle as SGT } from './0x13_SGT.js';
describe('SGT (0x13)', () => {
it('returns 1 when a > b (both positive)', () => {
const frame = createFrame([30n, 20n]);
expect(SGT(frame)).toBeNull();
expect(frame.stack).toEqual([1n]);
expect(frame.gasRemaining).toBe(997n);
});
it('returns 1 when positive > negative', () => {
const NEG_1 = (1n << 256n) - 1n;
const frame = createFrame([10n, NEG_1]);
expect(SGT(frame)).toBeNull();
expect(frame.stack).toEqual([1n]); // 10 > -1
});
it('returns 0 when negative < positive', () => {
const NEG_1 = (1n << 256n) - 1n;
const frame = createFrame([NEG_1, 10n]);
expect(SGT(frame)).toBeNull();
expect(frame.stack).toEqual([0n]); // -1 < 10
});
it('compares negative numbers correctly', () => {
const NEG_5 = (1n << 256n) - 5n;
const NEG_10 = (1n << 256n) - 10n;
const frame = createFrame([NEG_5, NEG_10]);
expect(SGT(frame)).toBeNull();
expect(frame.stack).toEqual([1n]); // -5 > -10
});
it('handles 0 > -1', () => {
const NEG_1 = (1n << 256n) - 1n;
const frame = createFrame([0n, NEG_1]);
expect(SGT(frame)).toBeNull();
expect(frame.stack).toEqual([1n]);
});
it('handles MAX_INT256 > MIN_INT256', () => {
const MIN = 1n << 255n;
const MAX = (1n << 255n) - 1n;
const frame = createFrame([MAX, MIN]);
expect(SGT(frame)).toBeNull();
expect(frame.stack).toEqual([1n]);
});
it('returns 0 when a <= b (equal)', () => {
const frame = createFrame([20n, 20n]);
expect(SGT(frame)).toBeNull();
expect(frame.stack).toEqual([0n]);
});
it('returns StackUnderflow with insufficient stack', () => {
const frame = createFrame([10n]);
expect(SGT(frame)).toEqual({ type: 'StackUnderflow' });
});
it('preserves stack below compared values', () => {
const frame = createFrame([100n, 200n, 30n, 20n]);
expect(SGT(frame)).toBeNull();
expect(frame.stack).toEqual([100n, 200n, 1n]);
});
});