use std::any::type_name; use bloock_storage::kv::KeyValue; use std::collections::HashMap; fn init_hashmap() -> HashMap, Vec> { //let config: HashMapConfig = HashMapConfig {}; HashMap::, Vec>::new() } fn type_of(_: T) -> &'static str { type_name::() } #[test] fn test_read_exist() { let mut hashmap = init_hashmap(); hashmap.put(&[1; 32], &[1; 32]).unwrap(); assert_eq!( , Vec> as KeyValue>::get(&hashmap, &[1; 32]).unwrap(), Some(vec![1; 32]), "The value should be none" ); } #[test] fn test_read_not_exist() { let hashmap = init_hashmap(); assert_eq!( , Vec> as KeyValue>::get(&hashmap, &[1; 32]) .unwrap() .is_none(), true, "The value should be none" ); } #[test] fn test_read_error() { /* TO DO: fill, don't know how to make hashmap return error" */ } #[test] fn test_put() { let mut hashmap = init_hashmap(); HashMap::, Vec>::put(&mut hashmap, &[1; 32], &[0; 32]).unwrap(); assert_eq!( , Vec> as KeyValue>::get(&hashmap, &[1; 32]) .unwrap() .unwrap(), [0; 32], "The value read was not written or unable to read" ); } #[test] fn test_put_error() { /* No idea de com fer que peti escribint */ } #[test] fn test_ini_batch() { assert_eq!( "std::collections::hash::map::HashMap, alloc::vec::Vec>", type_of(HashMap::, Vec>::ini_batch().unwrap()), "ini_batch does not work correctly" ) } #[test] fn test_put_batch() { let mut b = HashMap::, Vec>::new(); assert_eq!( true, HashMap::, Vec>::put_batch(&mut b, &[2u8], &[3u8]).is_ok(), "put batch not working" ) } #[test] fn test_end_batch() { let mut db = init_hashmap(); let b = HashMap::, Vec>::new(); assert_eq!(true, db.end_batch(b).is_ok(), "put batch not working"); }