minkowski.rs

1.7 kB · rust · 48 lines

1use demos::minkowski::*;2use mrlyrs::core::error::parse;3use std::f64::consts::SQRT_2;45#[test]6fn the_slice_reads_the_centre_and_a_subcube_centre() {7    let slice = minkowski_slice(0.5, 3).unwrap();8    assert_eq!(slice.len(), 9);9    assert_eq!(slice[4], (SQRT_2 / 6.0) as f32);10    assert_eq!(slice[0], (SQRT_2 / 18.0) as f32);11    assert!(minkowski_slice(0.5, 730).is_err());12}1314#[test]15fn the_read_holds_the_enclosures_and_the_open_window() {16    let read = parse(&minkowski_read(1.0 / 12.0)).unwrap();17    let tube = read["tube"].as_f64().unwrap();18    let profile = read["profile"].as_f64().unwrap();19    assert!((0.180947086..=0.180947093).contains(&tube));20    assert!((2.122718..=2.122723).contains(&profile));21    assert!(read["reading"].as_f64().unwrap() < profile);22    let open = parse(&minkowski_read(0.2)).unwrap();23    assert!(open["tube"].is_null() && open["profile"].is_null() && open["reading"].is_null());24}2526#[test]27fn the_walk_breaks_on_the_open_phases_and_swings() {28    let walk = parse(&minkowski_walk(8, 72).unwrap()).unwrap();29    let profile = walk["profile"].as_array().unwrap();30    let reading = walk["reading"].as_array().unwrap();31    assert_eq!(walk["u"].as_array().unwrap().len(), 576);32    let open = profile.iter().filter(|v| v.is_null()).count();33    assert_eq!(open, 8 * 23);34    assert!(profile35        .iter()36        .zip(reading)37        .all(|(p, r)| p.is_null() == r.is_null()));38    let (low, high) = (39        walk["low"].as_f64().unwrap(),40        walk["high"].as_f64().unwrap(),41    );42    assert!(low < 2.123 && high > 2.135);43    assert!(walk["swing"].as_f64().unwrap() >= 0.5792);44    assert!(profile45        .iter()46        .zip(reading)47        .all(|(p, r)| p.is_null() || r.as_f64() < p.as_f64()));48}