()
| 671 | |
| 672 | #[test] |
| 673 | fn leaf() { |
| 674 | let mut leaf = NodeData::<TF>::leaf('d', SetValue()); |
| 675 | assert_eq!(leaf.to_string(), "[ d ]"); |
| 676 | |
| 677 | assert!(leaf.try_leaf_insert(0, 'a', SetValue())); |
| 678 | assert_eq!(leaf.to_string(), "[ a d ]"); |
| 679 | assert!(leaf.try_leaf_insert(1, 'b', SetValue())); |
| 680 | assert!(leaf.try_leaf_insert(2, 'c', SetValue())); |
| 681 | assert_eq!(leaf.to_string(), "[ a b c d ]"); |
| 682 | for i in 4..15 { |
| 683 | assert!(leaf.try_leaf_insert(usize::from(i), ('a' as u8 + i) as char, SetValue())); |
| 684 | } |
| 685 | assert_eq!(leaf.to_string(), "[ a b c d e f g h i j k l m n o ]"); |
| 686 | |
| 687 | // Now the node is full and insertion should fail anywhere. |
| 688 | assert!(!leaf.try_leaf_insert(0, 'x', SetValue())); |
| 689 | assert!(!leaf.try_leaf_insert(8, 'x', SetValue())); |
| 690 | assert!(!leaf.try_leaf_insert(15, 'x', SetValue())); |
| 691 | |
| 692 | // The index given to `split` is not the split position, it's a hint for balancing the node. |
| 693 | let saved = leaf; |
| 694 | let sp = leaf.split(12); |
| 695 | assert_eq!(sp.lhs_entries, 8); |
| 696 | assert_eq!(sp.rhs_entries, 7); |
| 697 | assert_eq!(sp.crit_key, 'i'); |
| 698 | assert_eq!(leaf.to_string(), "[ a b c d e f g h ]"); |
| 699 | assert_eq!(sp.rhs_data.to_string(), "[ i j k l m n o ]"); |
| 700 | |
| 701 | assert!(leaf.try_leaf_insert(8, 'i', SetValue())); |
| 702 | assert_eq!(leaf.leaf_remove(2), Removed::Healthy); |
| 703 | assert_eq!(leaf.to_string(), "[ a b d e f g h i ]"); |
| 704 | assert_eq!(leaf.leaf_remove(7), Removed::Underflow); |
| 705 | assert_eq!(leaf.to_string(), "[ a b d e f g h ]"); |
| 706 | |
| 707 | leaf = saved; |
| 708 | let sp = leaf.split(7); |
| 709 | assert_eq!(sp.lhs_entries, 7); |
| 710 | assert_eq!(sp.rhs_entries, 8); |
| 711 | assert_eq!(sp.crit_key, 'h'); |
| 712 | assert_eq!(leaf.to_string(), "[ a b c d e f g ]"); |
| 713 | assert_eq!(sp.rhs_data.to_string(), "[ h i j k l m n o ]"); |
| 714 | } |
| 715 | |
| 716 | #[test] |
| 717 | fn optimal_split_pos() { |
no test coverage detected