interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / zmij / tests / exhaustive.rs

58 lines · 1910 bytes Raw Blame History
1#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))]
2
3use std::sync::atomic::{AtomicU32, Ordering};
4use std::sync::Arc;
5use std::thread;
6
7#[test]
8#[cfg_attr(not(exhaustive), ignore = "requires cfg(exhaustive)")]
9fn test_exhaustive() {
10 const BATCH_SIZE: u32 = 1_000_000;
11 let counter = Arc::new(AtomicU32::new(0));
12 let finished = Arc::new(AtomicU32::new(0));
13
14 let mut workers = Vec::new();
15 for _ in 0..num_cpus::get() {
16 let counter = counter.clone();
17 let finished = finished.clone();
18 workers.push(thread::spawn(move || loop {
19 let batch = counter.fetch_add(1, Ordering::Relaxed);
20 if batch > u32::MAX / BATCH_SIZE {
21 return;
22 }
23
24 let min = batch * BATCH_SIZE;
25 let max = if batch == u32::MAX / BATCH_SIZE {
26 u32::MAX
27 } else {
28 min + BATCH_SIZE - 1
29 };
30
31 let mut zmij_buffer = zmij::Buffer::new();
32 let mut ryu_buffer = ryu::Buffer::new();
33 for u in min..=max {
34 let f = f32::from_bits(u);
35 if !f.is_finite() {
36 continue;
37 }
38 let zmij = zmij_buffer.format_finite(f);
39 assert_eq!(Ok(f), zmij.parse(), "{zmij:?}");
40 let ryu = ryu_buffer.format_finite(f);
41 let matches = if ryu.contains('e') && !ryu.contains("e-") {
42 ryu.split_once('e') == zmij.split_once("e+")
43 } else {
44 ryu == zmij
45 };
46 assert!(matches, "{ryu} != {zmij}");
47 }
48
49 let increment = max - min + 1;
50 let update = finished.fetch_add(increment, Ordering::Relaxed);
51 println!("{}", u64::from(update) + u64::from(increment));
52 }));
53 }
54
55 for w in workers {
56 w.join().unwrap();
57 }
58}