// Generated by bynkc — do not edit by hand.
// test target: demo.meter

import { Ok, Err, Some, None, makeTestState, type Result, type Option, type ValidationError } from "../runtime.js";
import * as demo_meter from "./../demo/meter.js";

class AssertionError extends Error {
  constructor(public location: string, public start: number, public end: number) {
    super(`assertion failed at ${location}`);
  }
}
function __bynkAssertionFailure(location: string, start: number, end: number) {
  return new AssertionError(location, start, end);
}
function __bynkAssert(cond: boolean, location: string, start: number, end: number): void {
  if (!cond) { throw __bynkAssertionFailure(location, start, end); }
}

function makeTestDeps() {
  return {  };
}

async function test_a_fresh_Meter_key_reads_nested_zeros() {
  try {
    demo_meter.__resetAgents();
    const deps = makeTestDeps();
    const { Meter, MeterError, MeterId, Totals, __makeMeter, hits } = demo_meter as any;
    void (await (async (__d) => {
        switch (__d.tag) {
          case "Err": {
            return __bynkAssert((false), "offset 195", 195, 200);
          }
          case "Ok": {
            const id = __d.value;
            const reading = await hits.call(id, deps);
            switch (reading.tag) {
              case "Ok": {
                const n = reading.value;
                return __bynkAssert((n === 0), "offset 287", 287, 293);
              }
              case "Err": {
                return __bynkAssert((false), "offset 315", 315, 320);
              }
            }
            throw new Error("non-exhaustive match");
          }
        }
        throw new Error("non-exhaustive match");
      })(MeterId.of("fresh")));
    return { pass: true };
  } catch (e) {
    if (e instanceof AssertionError) {
      return { pass: false, error: { message: e.message, location: e.location } };
    }
    return { pass: false, error: { message: String(e), location: "unknown" } };
  }
}

export async function run() {
  const results = [];
  results.push({ name: "a fresh Meter key reads nested zeros", ...(await test_a_fresh_Meter_key_reads_nested_zeros()) });
  return results;
}
