SHARE
TWEET

Untitled

a guest Oct 21st, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn main() {
  2.     let vals = vec![0x1,
  3.     0x6,
  4.     0x9,
  5.     0xc,
  6.     0xf,
  7.     0x12,
  8.     0x19,
  9.     0x1c,
  10.     0x1f,
  11.     0x22,
  12.     0x32,
  13.     0x35,
  14.     0x38,
  15.     0x3b,
  16.     0x3e,
  17.     0x57,
  18.     0x65,
  19.     0x7e,
  20.     0x8c,
  21.     0x9d,
  22.     0xb6,
  23.     0xd0,
  24.     0xe2,
  25.     0xf0,
  26.     0x102,
  27.     0x116];
  28.     let tests = vec![
  29.         0x5b,
  30.         0x32,
  31.         0xe4,
  32.         0x3a,
  33.         0x3c,
  34.         0x1a,
  35.         0x7e,
  36.         0x36,
  37.     ];
  38.     let exp_res = vec![
  39.         0x57,
  40.         0x32,
  41.         0xe2,
  42.         0x38,
  43.         0x3b,
  44.         0x19,
  45.         0x7e,
  46.         0x35,
  47.     ];
  48.     for (i, test) in tests.iter().enumerate() {
  49.         let res = vals.binary_search(test);
  50.         println!("{:?}", res);
  51.         let val = match res {
  52.             Ok(idx) => vals[idx],
  53.             Err(idx) => vals[idx-1],
  54.         };
  55.         println!("func for addr {:#x} is {:#x}; expected {:#x}", test, val, exp_res[i]);
  56.         assert_eq!(val, exp_res[i]);
  57.     }
  58.    
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top