// 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 <https://www.gnu.org/licenses/>. use malachite_base::chars::random::graphic_weighted_random_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_chars_helper( p_numerator: u64, p_denominator: u64, expected_values: &str, expected_common_values: &[(char, usize)], expected_median: (char, Option<char>), ) { let xs = graphic_weighted_random_chars(EXAMPLE_SEED, p_numerator, p_denominator); let values = xs.clone().take(200).collect::<String>(); 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_chars() { // p = 1/2 graphic_weighted_random_chars_helper( 1, 2, "\u{8daa8}𘋈\u{3805c}ð°’\u{d7447}ç¤\u{e75f4}깶\u{38f35}\u{d36da}ê…Š\u{8c379}æ½ì¡ð¬±â•±ð£‘ºâ¢ð°°¬\u{3899f}ç€‹ð±½ŠÕ \ \u{71fe9}𦧴𪂆𦾸\u{c760b}𥳓𡸦\u{c5038}\u{53690}\u{eea10}\u{36080}𲄱\u{f2260}ð µ€\u{160ea}\u{361e7}\ \u{5aa82}𱸆\u{dfef7}\u{c0a1d}厩ð¡—𫈃⋓\u{f9b20}\u{aaecc}\u{6e0f8}𑌡\u{eaa03}ð¦½âŽ‘\u{19dce}\u{332d6}\ \u{61ee4}\u{7720d}\u{b184a}\u{f69ce}\u{751fd}ð¢°\u{ec70b}\u{f1b30}æ‘–\u{34bae}\u{d830b}𰾓𘀤\ \u{a044b}𱡫蚇\u{a81cf}\u{74eca}ð“Ž™\u{fc609}𦤋\u{6e154}\u{4c9c4}\u{67d8a}\u{c87ff}𗄤ð¦¥\u{1aacd}\ \u{1013c4}𢎬\u{5f1c1}\u{7bf68}\u{5319c}뛟䂈𣋩\u{c5a5e}\u{d4fed}Ộ\u{14e64}ì€ \u{89ea2}𠊅𫬒𫺇\ \u{3a82a}𔕽\u{6220a}憓쇧𮢚ㆎìˆ\u{68db2}𤣷ð¬´ð“´\u{57a9e}\u{87fd2}ჵ𢰨\u{11c91}𮬜\u{9e6cd}🡗\u{ce878}𧗟\ \u{6ad98}죗\u{6e7e1}\u{c0136}\u{9f180}å‘·\u{b1905}\u{4247b}\u{d35c0}\u{857d4}ð½ä«ð¨·¥å§—\u{9cdeb}ð¯§\ \u{fda2c}\u{54070}ð§·\u{ba590}\u{8d48b}𱩕\u{50ede}ðŒ¶\u{f13ea}\u{a4714}ðŠ\u{e1c36}䆟ð«·\u{f3b0a}ð’¿\ \u{b300c}뎜\u{c5205}\u{e5d53}𢶥\u{43743}ð•»ð“‰ª\u{d9078}𦰥㨠ֆ뇵ð«„𧳜ð‘«\u{cc033}\u{57e04}𠉤\u{90835}\ \u{c51ea}è𤎌\u{b986c}\u{83547}ð…Ÿð ‚—\u{eda4}\u{b4c98}\u{fb04e}\u{12a4c}\u{ac2de}鎌\u{c512c}录𰗶\ \u{4005e}\u{9d70a}𦣱\u{cc2f3}𢋽\u{68a20}🄘\u{c9e61}\u{475b0}", &[ ('שּׁ', 13), ('𘕒', 13), ('𣱵', 13), ('𧀂', 13), ('ð©†', 13), ('𪾣', 13), ('𬃔', 13), ('༈', 12), ('á¹¾', 12), ('ã ', 12) ], ('ð°†', None) ); // p = 1/51 graphic_weighted_random_chars_helper( 1, 51, "\u{8daa8}\u{3805c}𘋈\u{d7447}\u{e75f4}\u{38f35}\u{d36da}\u{8c379}\u{3899f}\u{71fe9}\ \u{c760b}\u{c5038}\u{53690}\u{eea10}\u{36080}\u{f2260}\u{160ea}\u{361e7}\u{5aa82}\u{dfef7}\ \u{c0a1d}\u{f9b20}\u{aaecc}\u{6e0f8}\u{eaa03}\u{19dce}\u{332d6}\u{61ee4}\u{7720d}\u{b184a}\ \u{f69ce}\u{751fd}\u{ec70b}\u{f1b30}\u{34bae}\u{d830b}\u{a044b}\u{a81cf}ð°’\u{74eca}\ \u{fc609}\u{6e154}\u{4c9c4}\u{67d8a}\u{c87ff}\u{1aacd}\u{1013c4}\u{5f1c1}\u{7bf68}\ \u{5319c}\u{c5a5e}\u{d4fed}\u{14e64}\u{89ea2}\u{3a82a}\u{6220a}\u{68db2}\u{57a9e}\u{87fd2}\ \u{11c91}\u{9e6cd}\u{ce878}\u{6ad98}\u{6e7e1}\u{c0136}\u{9f180}\u{b1905}\u{4247b}\u{d35c0}\ \u{857d4}\u{9cdeb}\u{fda2c}\u{54070}\u{ba590}\u{8d48b}\u{50ede}\u{f13ea}\u{a4714}\u{e1c36}\ \u{f3b0a}\u{b300c}\u{c5205}\u{e5d53}\u{43743}\u{d9078}\u{cc033}\u{57e04}\u{90835}\u{c51ea}\ \u{b986c}\u{83547}\u{eda4}\u{b4c98}\u{fb04e}\u{12a4c}\u{ac2de}\u{c512c}\u{4005e}\u{9d70a}\ \u{cc2f3}\u{68a20}\u{c9e61}\u{475b0}\u{fc93b}\u{47840}\u{75aff}\u{420a6}\u{34056}ç¤\ \u{bb2d7}\u{e7bd0}\u{8fa93}\u{6eddb}\u{3a98a}\u{57fa6}\u{53434}\u{f7b00}\u{b8cef}\u{1007c}\ \u{9b254}\u{e8ab1}\u{f7f42}\u{e0cf2}\u{f7637}\u{1e0f3}\u{8bf53}\u{355f5}\u{74b61}\u{b4e32}\ 깶\u{a8491}\u{ddbb2}\u{10ae4f}\u{9074b}\u{f7a96}\u{404a9}\u{190b9}\u{ad6fb}\u{80af6}\ \u{71938}\u{41da0}\u{6fbe0}\u{101754}\u{786b9}\u{107252}\u{f0b67}\u{94a8c}\u{7efc6}\ \u{c0020}\u{aafcb}\u{ae1c8}\u{cb360}\u{cdff6}\u{f6ae7}\u{c438a}\u{b8107}\u{87007}\u{a0449}\ \u{106a6b}\u{d67b4}\u{5151c}\u{109779}\u{ccb94}\u{d0f86}\u{10de9d}\u{9ebd3}\u{c4077}\ \u{66470}\u{bb11d}\u{762b1}\u{c196b}\u{4f551}\u{4e038}\u{b77b5}\u{a0973}\u{f980d}\u{ee89e}\ \u{53f2d}\u{116d7}\u{1aeee}\u{33312}\u{3689f}\u{1658e}\u{ab097}\u{7b8d6}\u{51a55}\u{13b41}\ \u{3bee4}\u{fb838}\u{43aa6}\u{bb5ff}\u{5413d}\u{7cd9b}\u{b2111}\u{88727}\u{f4884}\u{df9cf}\ \u{b627a}\u{2f3b9}\u{e7877}", &[ ('\u{7a4b8}', 9), ('\u{9cc20}', 9), ('\u{37684}', 8), ('\u{3d034}', 8), ('\u{6441c}', 8), ('\u{6a52a}', 8), ('\u{7a8d2}', 8), ('\u{9b28c}', 8), ('\u{a735f}', 8), ('\u{c6073}', 8), ], ('\u{97cbe}', Some('\u{97cbf}')), ); // p = 50/51 graphic_weighted_random_chars_helper( 50, 51, "𘋈ð°’ç¤ê¹¶ê…Šæ½ì¡ð¬±â•±ð£‘ºâ¢ð°°¬ç€‹ð±½ŠÕ 𦧴𪂆𦾸𥳓𡸦𲄱𠵀𱸆厩ð¡—𫈃⋓𑌡ð¦½âŽ‘ð¢°æ‘–𰾓𘀤𱡫蚇𓎙𦤋𗄤ð¦¥ð¢Ž¬ë›Ÿä‚ˆð£‹©á»˜ì€ 𠊅𫬒𫺇𔕽憓쇧𮢚ㆎìˆð¤£·ð¬´ð“´áƒµð¢°¨ð®¬œðŸ¡—𧗟죗呷\u{8daa8}ð½ä«ð¨·¥å§—ð¯§ð§·ð±©•ðŒ¶ðŠä†Ÿð«·ð’¿ëŽœð¢¶¥ð•»\ 𓉪𦰥㨠ֆ뇵ð«„𧳜ð‘«ð ‰¤è𤎌ð…Ÿð ‚—鎌录𰗶𦣱𢋽🄘ð§½ð¬šœð™†ð‘ˆ¦è „𲈽𩿙é•ðŸ”©ã…考𥘡ꔻ𦱊ð§„æ¡ð¡´¹í‰µð¦‡€ð¥¢žç¬„羽𢓃ð€–𢴼ð—¾ð£¦¹ð²†€ð”ºæ•„\u{3805c}罯ð¦¶ð£±¦ð£žð¤®žð˜•’ᕳ붙삑ð–ð¨ƒé—’贜𩋅𓄬𮈯𥟽𪆚𤯆𑲌ð›ð°˜œð¤”ˆæŽ 𠦜✂㕶굦𗾉𦮽㾓𘀠\ 褲𖡶𮯉ð§¹ð‘‚¤íŠŸ\u{d7447}䯸🈸ð«¤ð ¬Ÿð˜¦•é‡¾ì¥šé•í˜ð¨€¨ð¬²ð›¹ð¡š‚🆀裴𧚼Çð«¼ä–ˆà³¨\u{e75f4}êºð±½¡ð¡ˆ™ä”¨íŒšð§šç¾«ð¡‡¼ð€¯", &[ ('𘚺', 23), ('𢤒', 20), ('𤉺', 20), ('ﱺ', 19), ('ð– –', 19), ('𢓆', 19), ('𤌅', 19), ('𤦵', 19), ('𦱃', 19), ('ð¦•', 19) ], ('ðŸ„', None) ); } #[test] #[should_panic] fn graphic_weighted_random_chars_fail_1() { graphic_weighted_random_chars(EXAMPLE_SEED, 0, 0); } #[test] #[should_panic] fn graphic_weighted_random_chars_fail_2() { graphic_weighted_random_chars(EXAMPLE_SEED, 1, 0); } #[test] #[should_panic] fn graphic_weighted_random_chars_fail_3() { graphic_weighted_random_chars(EXAMPLE_SEED, 2, 1); }