MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / test_leaf_linked_list

Function test_leaf_linked_list

rust/tests/bplus_tree.rs:941–1041  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

939
940#[test]
941fn test_leaf_linked_list() {
942 let mut tree = BPlusTreeMap::<i32, String>::new(4).unwrap();
943
944 // Create three leaf nodes
945 let leaf1 = bplustree::LeafNode::new(4);
946 let leaf2 = bplustree::LeafNode::new(4);
947 let leaf3 = bplustree::LeafNode::new(4);
948
949 let id1 = tree.allocate_leaf(leaf1);
950 let id2 = tree.allocate_leaf(leaf2);
951 let id3 = tree.allocate_leaf(leaf3);
952
953 // Initially, all next pointers should be NULL
954 assert_eq!(tree.get_leaf_next(id1), None, "Initial next should be None");
955 assert_eq!(tree.get_leaf_next(id2), None, "Initial next should be None");
956 assert_eq!(tree.get_leaf_next(id3), None, "Initial next should be None");
957
958 // Set up a linked list: id1 -> id2 -> id3 -> NULL
959 assert!(
960 tree.set_leaf_next(id1, id2),
961 "Should be able to set next pointer"
962 );
963 assert!(
964 tree.set_leaf_next(id2, id3),
965 "Should be able to set next pointer"
966 );
967
968 // Verify the linked list structure
969 assert_eq!(
970 tree.get_leaf_next(id1),
971 Some(id2),
972 "id1 should point to id2"
973 );
974 assert_eq!(
975 tree.get_leaf_next(id2),
976 Some(id3),
977 "id2 should point to id3"
978 );
979 assert_eq!(tree.get_leaf_next(id3), None, "id3 should point to NULL");
980
981 // Test setting next to NULL_NODE explicitly
982 assert!(
983 tree.set_leaf_next(id2, bplustree::NULL_NODE),
984 "Should be able to set next to NULL"
985 );
986 assert_eq!(
987 tree.get_leaf_next(id2),
988 None,
989 "id2 should now point to NULL"
990 );
991
992 // Test invalid operations
993 assert!(
994 !tree.set_leaf_next(999, id1),
995 "Should fail to set next on invalid ID"
996 );
997 assert_eq!(
998 tree.get_leaf_next(999),

Callers

nothing calls this directly

Calls 4

allocate_leafMethod · 0.80
containsMethod · 0.80
get_leaf_nextMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected