import { Bool, Circuit, isReady, shutdown, Int64 } from 'snarkyjs'; describe('circuit', () => { beforeAll(() => isReady); afterAll(() => setTimeout(shutdown, 0)); it('Circuit.switch picks the right value', () => { const x = Circuit.switch([Bool(false), Bool(true), Bool(false)], Int64, [ Int64.from(-1), Int64.from(-2), Int64.from(-3), ]); expect(x.toString()).toBe('-2'); }); it('Circuit.switch returns 0 if the mask has only false elements', () => { const x = Circuit.switch([Bool(false), Bool(false), Bool(false)], Int64, [ Int64.from(-1), Int64.from(-2), Int64.from(-3), ]); expect(x.toString()).toBe('0'); }); it('Circuit.switch throws when mask has >1 true elements', () => { expect(() => Circuit.switch([Bool(true), Bool(true), Bool(false)], Int64, [ Int64.from(-1), Int64.from(-2), Int64.from(-3), ]) ).toThrow(/`mask` must have 0 or 1 true element, found 2/); }); });