Files
pokerfreak/tests/pipeline_extras_neutral.rs
mmintel 04d5251acf Welt ohne fremden Namen: Pruefordner vollstaendig mitkopieren, Engine nur im eigenen Baum
Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete
Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
2026-11-01 23:37:11 +01:00

60 lines
2.4 KiB
Rust

//! Without `boardDouble` and `ritOffered` nothing changes: `respond` gives exactly what the
//! pipeline gave before these fields existed (decode → check → decide → enforce → encode).
mod support;
use rechner::engine::decide::decide;
use rechner::game::Decision;
use rechner::guard::enforce::enforce;
use rechner::guard::validate::check;
use rechner::json::parse;
use rechner::wire::decode::decode;
use rechner::wire::encode::encode;
use rechner::wire::respond::respond;
use support::{board_json, cards_json, short};
fn before(line: &str) -> String {
let decision = parse(line)
.and_then(|value| decode(&value))
.and_then(check)
.map(|spot| enforce(&spot, decide(&spot)))
.unwrap_or_else(|fault| Decision::abstain(format!("invalid request: {fault}")));
encode(&decision)
}
fn requests() -> Vec<String> {
let mut lines = Vec::new();
for variant in ["NLHE", "AOF", "K_POKER"] {
for (hero, board) in [("Ah Kh", ""), ("7h 7d", "7c Ks 2d"), ("Qs Jd", "Ts 9h 2c 3d"),
("7h 2c", "Ks Qd 9c 4h 2s"), ("Ah 5h", "Ac")] {
for (to_call, legal) in [(0.0, r#"["CHECK","RAISE"]"#), (0.4, r#"["FOLD","CALL","RAISE"]"#)] {
let cards = short(board);
let street = match cards.len() { 0 => "PREFLOP", 3 => "FLOP", 4 => "TURN", 5 => "RIVER", _ => "FLOP" };
lines.push(format!(
r#"{{"variant":"{variant}","bigBlind":0.1,"seats":6,"heroSeat":5,"heroCards":{},"board":{},"street":"{street}","pot":1.2,"toCall":{to_call},"heroStack":6.0,"minRaiseTo":0.8,"maxRaiseTo":6.0,"legalActions":{legal},"allowedSizes":[0.8,2.4],"villains":[{{"seat":2,"stack":10.4,"folded":false}}]}}"#,
cards_json(&short(hero)),
board_json(&cards),
));
}
}
}
lines.push("not json".to_string());
lines.push(r#"{"variant":"NLHE"}"#.to_string());
lines
}
#[test]
fn without_the_new_fields_every_answer_is_unchanged() {
for line in requests() {
assert_eq!(respond(&line), before(&line), "{line}");
}
}
#[test]
fn ritoffered_false_and_boarddouble_null_are_the_same_as_absent() {
for line in requests().into_iter().filter(|l| l.ends_with("}]}")) {
let with = format!("{},\"ritOffered\":false,\"boardDouble\":null}}", &line[..line.len() - 1]);
assert_eq!(respond(&with), respond(&line), "{with}");
}
}