registry_integers.rs

4.0 kB · rust · 142 lines

1use mrlycore::json::parse;2use mrlycore::Json;3use mrlydemo::census::{4    census_champions, census_misses, census_report, census_walk, census_window, census_writers,5};67const TIERS: [(&str, u64); 4] = [8    ("closed", 7692),9    ("convolved", 5044),10    ("side", 2665),11    ("level", 2665),12];1314const LADDER: [u64; 4] = [783, 929, 955, 959];1516const MISSES: [u64; 10] = [269, 362, 422, 443, 446, 487, 502, 538, 607, 611];1718const CHAMPIONS: [(u64, u64); 10] = [19    (16, 2858),20    (9, 2811),21    (4, 2559),22    (12, 2303),23    (36, 2270),24    (64, 2176),25    (3, 1951),26    (6, 1883),27    (8, 1790),28    (33, 1777),29];3031// THE WINDOW3233pub fn the_census_of_1_100000_over_the() -> Result<(), String> {34    let window = read(&census_window())?;35    let rows = number("registry", &window["registry"])?;36    if rows != 18066 {37        return Err(format!("the registry lists {rows} rows"));38    }39    let mut total = 0;40    for (slot, (tier, keys)) in TIERS.iter().enumerate() {41        let listed = &window["tiers"][slot];42        if listed["tier"] != *tier {43            return Err(format!("tier {slot} is not {tier}"));44        }45        let count = number(tier, &listed["keys"])?;46        if count != *keys {47            return Err(format!("the {tier} tier lists {count} rows"));48        }49        total += count;50    }51    if total != rows {52        return Err(format!("the tiers list {total} rows against {rows}"));53    }54    Ok(())55}5657// THE DEEP SWEEP5859pub fn the_miss_set_s_arithmetic_269_a() -> Result<(), String> {60    loop {61        let walk = read(&census_walk(500))?;62        if walk["complete"] == true {63            break;64        }65    }66    let report = read(&census_report())?;67    for (field, want) in [68        ("rows", 18066),69        ("depth", 48),70        ("never", 41),71        ("once", 31),72        ("multiple", 928),73        ("written", 959),74        ("first_miss", 269),75        ("run", 268),76        ("low", 29144),77        ("incidences", 193419),78    ] {79        let got = number(field, &report[field])?;80        if got != want {81            return Err(format!("the sweep reads {field} at {got}"));82        }83    }84    let missed = number("missed", &report["bands"][2]["missed"])?;85    if missed != 41 {86        return Err(format!("the third band misses {missed}"));87    }88    let ladder = column(&report["depths"], "written")?;89    if ladder != LADDER {90        return Err(format!("the depth ladder reads {ladder:?}"));91    }92    let champions = read(&census_champions(10))?;93    let top: Vec<(u64, u64)> = column(&champions, "value")?94        .into_iter()95        .zip(column(&champions, "rows")?)96        .collect();97    if top != CHAMPIONS {98        return Err(format!("the champions read {top:?}"));99    }100    let misses = read(&census_misses(10))?;101    let opening: Vec<u64> = misses102        .as_array()103        .ok_or("the miss list is not an array")?104        .iter()105        .filter_map(Json::as_u64)106        .collect();107    if opening != MISSES {108        return Err(format!("the miss set opens {opening:?}"));109    }110    let writers = number("rows", &read(&census_writers(269, 0, 1))?["rows"])?;111    if writers != 0 {112        return Err(format!("the first miss is written by {writers} rows"));113    }114    let champion = read(&census_writers(16, 0, 1))?;115    let rows = number("rows", &champion["rows"])?;116    if rows != 2858 {117        return Err(format!("the champion is written by {rows} rows"));118    }119    let by_tier = column(&champion["tiers"], "rows")?;120    if by_tier != [666, 1529, 530, 133] {121        return Err(format!("the champion splits {by_tier:?}"));122    }123    Ok(())124}125126// READING127128fn read(text: &str) -> Result<Json, String> {129    parse(text).map_err(|_| "the census does not print json".to_string())130}131132fn number(field: &str, value: &Json) -> Result<u64, String> {133    value.as_u64().ok_or(format!("{field} is not a number"))134}135136fn column(rows: &Json, field: &str) -> Result<Vec<u64>, String> {137    rows.as_array()138        .ok_or(format!("the {field} column is not an array"))?139        .iter()140        .map(|row| number(field, &row[field]))141        .collect()142}