tourbillon.rs
5.8 kB · rust · 164 lines
1use mrlycore::json::parse;2use mrlydemo::tourbillon::*;34fn read(5 top: usize,6 size: usize,7 schedule: &str,8 increment: f64,9 set: &str,10 weights: &str,11 blend: &str,12) -> mrlycore::Json {13 let field = tourbillon(14 top, size, schedule, increment, set, weights, "cells", blend, 1,15 )16 .unwrap();17 parse(18 &tourbillon_stats(19 &field, size, top, schedule, increment, set, weights, blend, 1,20 )21 .unwrap(),22 )23 .unwrap()24}2526#[test]27fn the_unspun_centre_is_the_layers_three_mod_four() {28 let stack = read(55, 512, "unspun", 0.0, "odd", "plain", "mean");29 assert_eq!(stack["layers"], 28);30 assert_eq!(stack["centre"].as_f64().unwrap(), 14.0 / 28.0);31 let counted = read(55, 512, "unspun", 0.0, "odd", "plain", "sum");32 assert_eq!(counted["centre"].as_f64().unwrap(), 14.0);33}3435#[test]36fn the_unspun_stack_tops_out_at_eighteen_of_the_twenty_eight() {37 let counted = read(55, 512, "unspun", 0.0, "odd", "plain", "sum");38 assert_eq!(counted["high"].as_f64().unwrap(), 18.0);39 assert_eq!(counted["low"].as_f64().unwrap(), 0.0);40 let shared = read(55, 512, "unspun", 0.0, "odd", "plain", "mean");41 assert_eq!(42 format!("{:.6}", shared["high"].as_f64().unwrap()),43 format!("{:.6}", 18.0 / 28.0)44 );45}4647#[test]48fn no_turn_of_the_layers_moves_the_centre() {49 for step in 0..8 {50 let spun = read(55, 64, "degrees", f64::from(step), "odd", "plain", "mean");51 assert_eq!(spun["centre"].as_f64().unwrap(), 14.0 / 28.0);52 }53 for schedule in ["golden", "primes", "random", "gaussian"] {54 let spun = read(55, 64, schedule, 0.0, "odd", "plain", "mean");55 assert_eq!(spun["centre"].as_f64().unwrap(), 14.0 / 28.0);56 }57}5859#[test]60fn the_parity_blend_folds_the_centre_count_to_its_parity() {61 let folded = read(55, 64, "unspun", 0.0, "odd", "plain", "parity");62 assert_eq!(folded["centre"].as_f64().unwrap(), 0.0);63 assert_eq!(folded["weighted"], false);64 let odd = read(51, 64, "unspun", 0.0, "odd", "plain", "sum");65 assert_eq!(odd["centre"].as_f64().unwrap(), 13.0);66 let flipped = read(51, 64, "unspun", 0.0, "odd", "plain", "parity");67 assert_eq!(flipped["centre"].as_f64().unwrap(), 1.0);68}6970#[test]71fn the_primes_only_stack_drops_the_even_prime() {72 let stack = read(199, 64, "unspun", 0.0, "primes", "plain", "mean");73 assert_eq!(stack["layers"], 45);74 let sets: Vec<String> = ["odd", "primes", "squarefree", "prime powers"]75 .iter()76 .map(|set| read(55, 64, "unspun", 0.0, set, "plain", "mean")["layers"].to_string())77 .collect();78 assert_eq!(sets.join(","), "28,15,23,19");79}8081#[test]82fn the_prime_schedule_turns_layer_k_by_the_k_th_prime() {83 let stack = read(55, 64, "primes", 0.0, "odd", "plain", "mean");84 let angles: Vec<String> = stack["angles"]85 .as_array()86 .unwrap()87 .iter()88 .map(|value| format!("{:.1}", value.as_f64().unwrap()))89 .collect();90 assert_eq!(angles.join(" "), "0.0 2.0 3.0 5.0 7.0 11.0 13.0 17.0");91 let scales: Vec<String> = stack["scales"]92 .as_array()93 .unwrap()94 .iter()95 .map(|value| value.to_string())96 .collect();97 assert_eq!(scales.join(" "), "1 3 5 7 9 11 13 15");98}99100#[test]101fn the_caps_and_the_names_are_held() {102 assert!(tourbillon(54, 64, "unspun", 0.0, "odd", "plain", "cells", "mean", 1).is_err());103 assert!(tourbillon(201, 64, "unspun", 0.0, "odd", "plain", "cells", "mean", 1).is_err());104 assert!(tourbillon(55, 4096, "unspun", 0.0, "odd", "plain", "cells", "mean", 1).is_err());105 assert!(tourbillon(55, 64, "spiral", 0.0, "odd", "plain", "cells", "mean", 1).is_err());106 assert!(tourbillon(55, 64, "unspun", 0.0, "even", "plain", "cells", "mean", 1).is_err());107 assert!(tourbillon(55, 64, "unspun", 0.0, "odd", "zeta", "cells", "mean", 1).is_err());108 assert!(tourbillon(55, 64, "unspun", 0.0, "odd", "plain", "dots", "mean", 1).is_err());109 assert!(tourbillon(55, 64, "unspun", 0.0, "odd", "plain", "cells", "blur", 1).is_err());110}111112#[test]113fn the_three_modes_read_the_same_layers_apart() {114 let shares: Vec<String> = ["cells", "edges", "corners"]115 .iter()116 .map(|mode| {117 let field =118 tourbillon(55, 256, "golden", 0.0, "odd", "plain", mode, "mean", 1).unwrap();119 let read = parse(120 &tourbillon_stats(&field, 256, 55, "golden", 0.0, "odd", "plain", "mean", 1)121 .unwrap(),122 )123 .unwrap();124 format!("{:.6}", read["mean"].as_f64().unwrap())125 })126 .collect();127 assert_eq!(shares.join(" "), "0.231722 0.111924 0.141211");128}129130#[test]131fn the_quarter_turn_lattice_lists_its_angles_smallest_first() {132 let list = parse(&tourbillon_eyes(12).unwrap()).unwrap();133 let rows = list.as_array().unwrap();134 assert_eq!(rows.len(), 185);135 let first: Vec<String> = rows136 .iter()137 .take(8)138 .map(|row| format!("{:.6}", row[0].as_f64().unwrap()))139 .collect();140 assert_eq!(141 first.join(" "),142 "0.000000 7.500000 8.181818 9.000000 10.000000 11.250000 12.857143 15.000000"143 );144 assert_eq!(145 format!("{} {}", rows[1][1], rows[1][2]),146 format!("{} {}", 90, 12)147 );148 assert!(tourbillon_eyes(0).is_err());149 assert!(tourbillon_eyes(61).is_err());150}151152#[test]153fn a_ninetieth_increment_folds_the_layers_into_angle_classes() {154 let stack = read(55, 64, "degrees", 18.0, "odd", "plain", "mean");155 assert_eq!(stack["period"], 5);156 assert_eq!(stack["classes"], 5);157 assert_eq!(stack["pairs"], 65);158 let fine = read(55, 64, "degrees", 7.5, "odd", "plain", "mean");159 assert_eq!(fine["period"], 12);160 assert_eq!(fine["classes"], 12);161 let loose = read(55, 64, "golden", 0.0, "odd", "plain", "mean");162 assert_eq!(loose["classes"], 28);163 assert_eq!(loose["pairs"], 0);164}