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

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

class AssertionError extends Error {
  location: string;
  start: number;
  end: number;
  constructor(location: string, start: number, end: number) {
    super(`assertion failed at ${location}`);
    this.location = location;
    this.start = start;
    this.end = end;
  }
}
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_Tally_key_reads_count_as_0() {
  try {
    demo_tally.__resetAgents();
    const deps = makeTestDeps();
    const { Tally, TallyError, TallyId, __makeTally, read } = demo_tally as any;
    void (await (async (__d) => {
        switch (__d.tag) {
          case "Err": {
            return __bynkAssert((false), "tests/demo/tally.bynk:8:20", 167, 172);
          }
          case "Ok": {
            const id = __d.value;
            const reading = await read.call(id, deps);
            switch (reading.tag) {
              case "Ok": {
                const n = reading.value;
                return __bynkAssert((n === 0), "tests/demo/tally.bynk:12:22", 259, 265);
              }
              case "Err": {
                return __bynkAssert((false), "tests/demo/tally.bynk:13:22", 287, 292);
              }
            }
            throw new Error("non-exhaustive match");
          }
        }
        throw new Error("non-exhaustive match");
      })(TallyId.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 Tally key reads count as 0", ...(await test_a_fresh_Tally_key_reads_count_as_0()) });
  return results;
}
