arcs.rs
1.3 kB · rust · 36 lines
1use demos::arcs::*;2use mrlyrs::core::error::parse;34fn loops(code: &str, base: usize, levels: std::ops::RangeInclusive<usize>) -> String {5 levels6 .map(|n| parse(&arcs_read(code, base, n).unwrap()).unwrap()["loops"].to_string())7 .collect::<Vec<String>>()8 .join(",")9}1011#[test]12fn the_arcs_exports_answer() {13 assert_eq!(loops("495", 3, 1..=4), "0,3,50,509");14 assert_eq!(loops("7", 2, 1..=4), "0,0,2,12");1516 let carpet = parse(&arcs_read("495", 3, 4).unwrap()).unwrap();17 assert_eq!(carpet["side"], 81);18 assert_eq!(carpet["filled"], 4096);19 assert_eq!(carpet["strands"], 162);20 assert_eq!(carpet["law"]["formula"], "(8^n - 1)/7 - 3^n + n + 1");21 assert_eq!(carpet["law"]["loops"], 509);2223 let seven = parse(&arcs_read("7", 2, 6).unwrap()).unwrap();24 assert_eq!(seven["loops"], 180);25 assert_eq!(seven["law"]["loops"], 180);26 assert_eq!(parse(&arcs_read("9", 2, 8).unwrap()).unwrap()["loops"], 255);27 assert!(parse(&arcs_read("511", 3, 2).unwrap()).unwrap()["law"].is_null());2829 let grid = arcs_grid("9", 2, 1).unwrap();30 assert_eq!((grid.width, grid.height), (2, 2));31 assert_eq!(grid.types, [5, 4, 2, 3]);3233 assert_eq!([2, 3, 4, 5].map(arcs_cap), [8, 5, 4, 3]);34 assert!(arcs_read("16", 2, 2).is_err());35 assert!(arcs_grid("7", 2, 9).is_err());36}