{
  "spec_version": "0.3.0",
  "cases": [
    {
      "id": "r1_genebench_overall",
      "formula": "measured_savings",
      "input": {
        "raw_tokens": 489273,
        "optimized_tokens": 182943
      },
      "expected": {
        "tokens_saved": 306330,
        "savings_pct": 62.61
      }
    },
    {
      "id": "r1_genebench_max_single",
      "formula": "measured_savings",
      "input": {
        "raw_tokens": 14340,
        "optimized_tokens": 2179
      },
      "expected": {
        "tokens_saved": 12161,
        "savings_pct": 84.8
      }
    },
    {
      "id": "r1_zero_raw",
      "formula": "measured_savings",
      "input": {
        "raw_tokens": 0,
        "optimized_tokens": 500
      },
      "expected": {
        "tokens_saved": 0,
        "savings_pct": 0
      }
    },
    {
      "id": "r1_optimized_exceeds_raw_clamps",
      "formula": "measured_savings",
      "input": {
        "raw_tokens": 1000,
        "optimized_tokens": 1200
      },
      "expected": {
        "tokens_saved": 0,
        "savings_pct": 0
      }
    },
    {
      "id": "r2_genebench_avg_rollout",
      "formula": "rollout_fold",
      "input": {
        "n_avg_rollouts": 1.48
      },
      "expected": {
        "rollout_fold_pct": 32.43
      }
    },
    {
      "id": "r2_single_rollout",
      "formula": "rollout_fold",
      "input": {
        "n_avg_rollouts": 1
      },
      "expected": {
        "rollout_fold_pct": 0
      }
    },
    {
      "id": "e1_all_event_types_default_coeffs",
      "formula": "entropy_total",
      "input": {
        "events": [
          {
            "type": "dedup_quarantine",
            "count": 2
          },
          {
            "type": "dedup_warning",
            "count": 1
          },
          {
            "type": "hub_search_hit",
            "count": 3
          },
          {
            "type": "hub_search_miss",
            "count": 5
          },
          {
            "type": "fetch_reuse",
            "count": 4
          }
        ]
      },
      "expected": {
        "total_tokens_saved": 67600,
        "total_events": 15
      }
    },
    {
      "id": "e1_caller_supplied_measured_takes_precedence",
      "formula": "entropy_total",
      "input": {
        "events": [
          {
            "type": "fetch_reuse",
            "count": 1,
            "tokensEstSaved": 7777
          }
        ]
      },
      "expected": {
        "total_tokens_saved": 7777,
        "total_events": 1
      }
    },
    {
      "id": "e1_negative_coerces_to_zero",
      "formula": "entropy_total",
      "input": {
        "events": [
          {
            "type": "hub_search_hit",
            "count": 1,
            "tokensEstSaved": -50
          }
        ]
      },
      "expected": {
        "total_tokens_saved": 0,
        "total_events": 1
      }
    },
    {
      "id": "e1_unknown_type_ignored",
      "formula": "entropy_total",
      "input": {
        "events": [
          {
            "type": "mystery_event",
            "count": 9
          },
          {
            "type": "fetch_reuse",
            "count": 1
          }
        ]
      },
      "expected": {
        "total_tokens_saved": 4000,
        "total_events": 1
      }
    },
    {
      "id": "e2_mixed_asset_types",
      "formula": "fetch_usage_estimate",
      "input": {
        "byType": {
          "Gene": 10,
          "Capsule": 3,
          "EvolutionEvent": 7
        }
      },
      "expected": {
        "estimated_token_saved": 25500
      }
    },
    {
      "id": "e2_unknown_type_contributes_zero",
      "formula": "fetch_usage_estimate",
      "input": {
        "byType": {
          "Gene": 1,
          "Artifact": 99
        }
      },
      "expected": {
        "estimated_token_saved": 1500
      }
    },
    {
      "id": "h1_homepage_style_hit_rate",
      "formula": "hit_rate",
      "input": {
        "hits": 1531,
        "misses": 60
      },
      "expected": {
        "hit_rate_pct": 96.23
      }
    },
    {
      "id": "h1_empty_denominator",
      "formula": "hit_rate",
      "input": {
        "hits": 0,
        "misses": 0
      },
      "expected": {
        "hit_rate_pct": 0
      }
    },
    {
      "id": "u1_round_two_decimals",
      "formula": "usd_saved",
      "input": {
        "tokens": 67600
      },
      "expected": {
        "usd_saved": 0.61
      }
    },
    {
      "id": "u1_two_million_tokens",
      "formula": "usd_saved",
      "input": {
        "tokens": 2000000
      },
      "expected": {
        "usd_saved": 18
      }
    },
    {
      "id": "c1_anthropic_one_million_cache_reads",
      "formula": "cache_saved_usd",
      "input": {
        "provider": "anthropic",
        "cache_read_tokens": 1000000
      },
      "expected": {
        "cache_saved_usd": 2.7
      }
    },
    {
      "id": "c1_round_four_decimals",
      "formula": "cache_saved_usd",
      "input": {
        "provider": "anthropic",
        "cache_read_tokens": 123456
      },
      "expected": {
        "cache_saved_usd": 0.3333
      }
    },
    {
      "id": "c1_unknown_provider_zero",
      "formula": "cache_saved_usd",
      "input": {
        "provider": "acme",
        "cache_read_tokens": 1000000
      },
      "expected": {
        "cache_saved_usd": 0
      }
    },
    {
      "id": "e3_default_direct_anchors_legacy_blanket",
      "formula": "reuse_estimate",
      "input": {
        "blast_radius_lines": null,
        "mode": "direct"
      },
      "expected": {
        "tokens_saved": 180000,
        "basis": "estimated_default"
      }
    },
    {
      "id": "e3_median_patch_75_lines",
      "formula": "reuse_estimate",
      "input": {
        "blast_radius_lines": 75,
        "mode": "direct"
      },
      "expected": {
        "tokens_saved": 180000,
        "basis": "estimated_blast_radius"
      }
    },
    {
      "id": "e3_small_patch_scales_down",
      "formula": "reuse_estimate",
      "input": {
        "blast_radius_lines": 2,
        "mode": "direct"
      },
      "expected": {
        "tokens_saved": 121600,
        "basis": "estimated_blast_radius"
      }
    },
    {
      "id": "e3_pathological_blast_radius_capped",
      "formula": "reuse_estimate",
      "input": {
        "blast_radius_lines": 1000,
        "mode": "direct"
      },
      "expected": {
        "tokens_saved": 600000,
        "basis": "estimated_blast_radius"
      }
    },
    {
      "id": "e3_reference_mode_fractional",
      "formula": "reuse_estimate",
      "input": {
        "blast_radius_lines": null,
        "mode": "reference"
      },
      "expected": {
        "tokens_saved": 72000,
        "basis": "estimated_default"
      }
    },
    {
      "id": "e3_zero_lines_falls_back_to_default",
      "formula": "reuse_estimate",
      "input": {
        "blast_radius_lines": 0,
        "mode": "direct"
      },
      "expected": {
        "tokens_saved": 180000,
        "basis": "estimated_default"
      }
    }
  ]
}
