dissection.rs
1.9 kB · rust · 56 lines
1use demos::dissection::*;2use mrlyrs::core::error::parse;3use mrlyrs::core::Json;45fn six(v: &Json) -> String {6 format!("{:.6}", v.as_f64().unwrap())7}89#[test]10fn the_read_of_base_ten_missing_seven_sits_outside_every_wall() {11 let read = parse(&dissection_read(10, 7).unwrap()).unwrap();12 assert_eq!(read["kappa"].to_string(), "[5,6]");13 assert_eq!(read["consecutive"].as_bool(), Some(true));14 assert_eq!(read["level"].as_u64(), Some(6));15 assert_eq!(16 format!("{:.2}", read["masses"][6].as_f64().unwrap()),17 "57350894.06"18 );19 assert_eq!(six(&read["reading"]), "0.346831");20 assert_eq!(six(&read["chain"]), "0.494642");21 assert_eq!(22 read["walls"].to_string(),23 r#"{"chain":584,"window":301,"digit":115,"first":65}"#24 );25 assert_eq!(read["reach"].as_str(), Some("none"));26 assert_eq!(read["depths"].to_string(), "[3,7]");27}2829#[test]30fn the_tally_holds_the_meter_and_the_prime_count() {31 let tally = dissection_tally(10, 7, 6).unwrap();32 let read = parse(&tally.read).unwrap();33 assert_eq!(read["count"].as_u64(), Some(531440));34 assert_eq!(read["meter"].as_i64(), Some(-9));35 assert_eq!(six(&read["root"]), "-0.012346");36 assert_eq!(six(&read["primes"]), "0.997990");37 assert_eq!(tally.logx.len(), 720);38}3940#[test]41fn the_grid_cuts_the_paper_regions_and_weighs_them() {42 let grid = dissection_grid(10, 7, 3, 8).unwrap();43 let read = parse(&grid.read).unwrap();44 assert_eq!(read["counts"].to_string(), "[732,202,26,40]");45 let shares: Vec<String> = (0..4).map(|i| six(&read["shares"][i])).collect();46 assert_eq!(shares, ["0.505350", "0.191985", "0.006843", "0.295822"]);47 assert_eq!(six(&read["reading"]), "0.330865");48 assert_eq!(grid.weight[0], 1.0);49}5051#[test]52fn the_chain_first_drops_below_a_fifth_at_584() {53 let chain = dissection_chain();54 let first = chain.iter().position(|&a| a < 0.2).unwrap() + 3;55 assert_eq!((chain.len(), first), (4094, 584));56}