Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let vals = vec![0x1,
- 0x6,
- 0x9,
- 0xc,
- 0xf,
- 0x12,
- 0x19,
- 0x1c,
- 0x1f,
- 0x22,
- 0x32,
- 0x35,
- 0x38,
- 0x3b,
- 0x3e,
- 0x57,
- 0x65,
- 0x7e,
- 0x8c,
- 0x9d,
- 0xb6,
- 0xd0,
- 0xe2,
- 0xf0,
- 0x102,
- 0x116];
- let tests = vec![
- 0x5b,
- 0x32,
- 0xe4,
- 0x3a,
- 0x3c,
- 0x1a,
- 0x7e,
- 0x36,
- ];
- let exp_res = vec![
- 0x57,
- 0x32,
- 0xe2,
- 0x38,
- 0x3b,
- 0x19,
- 0x7e,
- 0x35,
- ];
- for (i, test) in tests.iter().enumerate() {
- let res = vals.binary_search(test);
- println!("{:?}", res);
- let val = match res {
- Ok(idx) => vals[idx],
- Err(idx) => vals[idx-1],
- };
- println!("{:#x} == {:#x}", val, exp_res[i]);
- assert_eq!(val, exp_res[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement