// Copyright © 2024 Mikhail Hogrefe // // This file is part of Malachite. // // Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU // Lesser General Public License (LGPL) as published by the Free Software Foundation; either version // 3 of the License, or (at your option) any later version. See . use malachite_base::chars::random::graphic_weighted_random_ascii_chars; use malachite_base::random::EXAMPLE_SEED; use malachite_base::test_util::stats::common_values_map::common_values_map_debug; use malachite_base::test_util::stats::median; fn graphic_weighted_random_ascii_chars_helper( p_numerator: u64, p_denominator: u64, expected_values: &str, expected_common_values: &[(char, usize)], expected_median: (char, Option), ) { let xs = graphic_weighted_random_ascii_chars(EXAMPLE_SEED, p_numerator, p_denominator); let values = xs.clone().take(200).collect::(); let common_values = common_values_map_debug(1000000, 10, xs.clone()); let median = median(xs.take(1000000)); assert_eq!( (values.as_str(), common_values.as_slice(), median), (expected_values, expected_common_values, expected_median) ); } #[test] fn test_graphic_weighted_random_ascii_chars() { // p = 1/2 graphic_weighted_random_ascii_chars_helper( 1, 2, "\u{1b}x\u{8}1\r4\u{2}N\u{11}\u{11}(\u{13}bcXr$g)\t7/E\u{11}+fY\u{10}Po\u{1}\u{17}\u{17}\ \u{13}o\u{1}.\u{0}\u{b}\u{3}$\u{6}\nV2R.\u{f}\u{5}\u{19}$\u{1f}V=\u{1c}\u{6}\u{15}\u{6}\ \u{11}\r\u{19}6\u{2}\u{19}=\u{12}\u{18}Dq\u{6}S<\u{6}\u{1d}C\u{b}M\u{8}\u{15}\u{16}\u{f}W_\ \u{0}\u{12}%\u{18}\u{10}\u{10}OX?\u{1f}\u{12}b\u{c}}\u{10}rJa\u{e}D\u{1e}`o635\u{2}Q:w\u{3}\ \u{1}3m\u{5}Y\u{1f}=\u{7}8\tn\r\u{1}\nq\u{13}\u{3}\t\u{f}fR:/\u{f}2\u{2}\u{1c}6\u{13}\u{13}\ z\u{15}r\u{f}\u{4}<\u{1d}pr\u{2}+UFFc;8P:", &[ ('d', 10548), ('C', 10506), ('7', 10501), ('R', 10486), ('D', 10484), ('q', 10476), ('1', 10468), ('6', 10463), ('\'', 10452), ('$', 10448), ], ('N', None), ); } #[test] #[should_panic] fn graphic_weighted_random_ascii_chars_fail_1() { graphic_weighted_random_ascii_chars(EXAMPLE_SEED, 1, 0); } #[test] #[should_panic] fn graphic_weighted_random_ascii_chars_fail_2() { graphic_weighted_random_ascii_chars(EXAMPLE_SEED, 2, 1); }