()
| 38 | |
| 39 | #[test] |
| 40 | fn test_store_multiple_nodes() { |
| 41 | let path = PathBuf::from_str("tests/data") |
| 42 | .unwrap() |
| 43 | .join(uuid::Uuid::new_v4().to_string()) |
| 44 | .join("test.bin"); |
| 45 | fs::create_dir_all(&path.parent().unwrap()).expect("Failed to create directory"); |
| 46 | |
| 47 | let mut storage_manager: StorageManager<i32, String> = |
| 48 | StorageManager::new(path.clone()).unwrap(); |
| 49 | |
| 50 | let mut node1 = Node::new_leaf(0); |
| 51 | node1.keys.push(1); |
| 52 | node1.values.push(Some("one".to_string())); |
| 53 | |
| 54 | let mut node2 = Node::new_leaf(0); |
| 55 | node2.keys.push(2); |
| 56 | node2.values.push(Some("two".to_string())); |
| 57 | |
| 58 | // Store the first node |
| 59 | let offset1 = storage_manager.store_node(&mut node1).unwrap(); |
| 60 | assert_eq!(offset1, HEADER_SIZE); |
| 61 | |
| 62 | // Store the second node |
| 63 | let offset2 = storage_manager.store_node(&mut node2).unwrap(); |
| 64 | assert!(offset2 > offset1); // Ensure that the second node is stored after the first |
| 65 | |
| 66 | // Load the first node |
| 67 | let loaded_node1 = storage_manager.load_node(offset1).unwrap(); |
| 68 | assert_eq!(loaded_node1.keys, vec![1]); |
| 69 | assert_eq!(loaded_node1.values, vec![Some("one".to_string())]); |
| 70 | |
| 71 | // Load the second node |
| 72 | let loaded_node2 = storage_manager.load_node(offset2).unwrap(); |
| 73 | assert_eq!(loaded_node2.keys, vec![2]); |
| 74 | assert_eq!(loaded_node2.values, vec![Some("two".to_string())]); |
| 75 | } |
| 76 | |
| 77 | // #[test] |
| 78 | // fn test_resize_storage() { |
nothing calls this directly
no test coverage detected