chladni.rs
1.2 kB · rust · 34 lines
1use demos::chladni::*;2use mrlyrs::core::error::parse;34#[test]5fn the_kernel_picture_centres_the_mask() {6 let picture = chladni_kernel("7", 3, 2, 32).unwrap();7 assert_eq!((picture.width, picture.height), (32, 32));8 assert_eq!(9 picture.types.iter().map(|&t| usize::from(t)).sum::<usize>(),10 6411 );12 assert_eq!(picture.types[16 * 32 + 16], 0);13 assert_eq!(picture.types[12 * 32 + 12], 1);14 assert_eq!(picture.types[11 * 32 + 12], 0);15 assert!(chladni_kernel("7", 3, 4, 64).is_err());16 assert!(chladni_kernel("7", 3, 1, 12).is_err());17}1819fn pinned(density: f64) -> (usize, u64) {20 let grid = chladni_run("7", 3, 3, 0.28, 0.375, 0.28, 0.48, 128, 32, density, 7).unwrap();21 let live = grid.types.iter().filter(|&&t| t != 0).count();22 let read = parse(&chladni_profile(&grid.types, 128).unwrap()).unwrap();23 println!(24 "chladni_run 7 3 3 0.28 0.375 0.28 0.48 128 32 {density} 7 live {live} peak_ring {} wavelength {}",25 read["peak_ring"], read["wavelength"]26 );27 (live, read["peak_ring"].as_u64().unwrap())28}2930#[test]31fn the_pinned_soups_and_their_profiles() {32 assert_eq!(pinned(0.5), (0, 1));33 assert_eq!(pinned(0.45), (3274, 1));34}