/*
==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--
Bi
Copyright (C) 2019, 2021-2022, 2024 Anonymous
There are several releases over multiple years,
they are listed as ranges, such as: "2021-2022".
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--::--
*/
use {
std::{
sync::Arc,
thread,
},
bi::{Bi, IoResult, Options},
zeros::keccak::Hash,
};
#[test]
fn bi() -> IoResult<()> {
const BUF: &[u8] = &[
0x99, 0x8c, 0x64, 0x0e, 0xfc, 0x71, 0x80, 0xfe, 0x97, 0xe8, 0x55, 0x20, 0x45, 0x01, 0x8c, 0x19, 0xf4, 0xf7, 0x67, 0x31, 0x94, 0x7d,
0xb7, 0x72, 0xfe, 0xc7, 0xe4, 0xf6, 0x9c, 0x7f, 0xf4, 0x53, 0x0a, 0xbe, 0x2f, 0x18, 0x0f, 0x32, 0xff, 0x60, 0xac, 0xc7, 0xb7, 0x73,
0x85, 0xb6, 0x73, 0x71, 0xa3, 0xc4, 0x46, 0xcd, 0x8c, 0x13, 0x22, 0x2b, 0xed, 0x03, 0x38, 0xc6, 0xda, 0x69, 0x61, 0x8e,
];
const HASH: Hash = Hash::Sha3_512;
let hash = HASH.hash(BUF);
let bi = Arc::new(Bi::from(Options::default()));
let threads = (0..100).map(|_| {
let bi = bi.clone();
thread::spawn(move || bi.read(&mut &BUF[..], BUF.len()).map(|b| HASH.hash(&*b)))
}).collect::>();
let mut ok_count = 0;
let mut err_count = 0;
for t in threads {
match t.join().unwrap() {
Ok(h) if h == hash => ok_count += 1,
_ => err_count += 1,
};
}
println!("Ok: {ok_count} -- Errors: {err_count}", ok_count=ok_count, err_count=err_count);
assert!(ok_count > 0);
Ok(())
}