Skip to content

Commit

Permalink
feat: remove working
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Dec 23, 2023
1 parent d86952d commit 396242b
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 235 deletions.
248 changes: 124 additions & 124 deletions mast/src/operations/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,128 +183,128 @@ pub(crate) fn insert(

#[cfg(test)]
mod test {
// use crate::test::{test_operations, Entry};
// use proptest::prelude::*;
//
// proptest! {
// #[test]
// /// Test that upserting an entry with the same key in different tree shapes results in the
// /// expected structure
// fn test_upsert(random_entries in prop::collection::vec(
// (prop::collection::vec(any::<u8>(), 1), prop::collection::vec(any::<u8>(), 1)),
// 1..10,
// )) {
// let operations = random_entries.into_iter().map(|(key, value)| {
// Entry::insert(&key, &value)
// }).collect::<Vec<_>>();
//
// test_operations(&operations, None);
// }
//
// #[test]
// fn test_general_insertiong(random_entries in prop::collection::vec(
// (prop::collection::vec(any::<u8>(), 32), prop::collection::vec(any::<u8>(), 32)),
// 1..50,
// )) {
// let operations = random_entries.into_iter().map(|(key, value)| {
// Entry::insert(&key, &value)
// }).collect::<Vec<_>>();
//
// test_operations(&operations, None);
// }
// }
//
// #[test]
// fn insert_single_entry() {
// let case = ["A"];
//
// test_operations(
// &case.map(|key| Entry::insert(key.as_bytes(), &[b"v", key.as_bytes()].concat())),
// Some("78fd7507ef338f1a5816ffd702394999680a9694a85f4b8af77795d9fdd5854d"),
// )
// }
//
// #[test]
// fn sorted_alphabets() {
// let case = [
// "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
// "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
// ];
//
// test_operations(
// &case.map(|key| Entry::insert(key.as_bytes(), &[b"v", key.as_bytes()].concat())),
// Some("02af3de6ed6368c5abc16f231a17d1140e7bfec483c8d0aa63af4ef744d29bc3"),
// );
// }
//
// #[test]
// fn reverse_alphabets() {
// let mut case = [
// "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
// "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
// ];
// case.reverse();
//
// test_operations(
// &case.map(|key| Entry::insert(key.as_bytes(), &[b"v", key.as_bytes()].concat())),
// Some("02af3de6ed6368c5abc16f231a17d1140e7bfec483c8d0aa63af4ef744d29bc3"),
// )
// }
//
// #[test]
// fn unsorted() {
// let case = ["D", "N", "P", "X", "A", "G", "C", "M", "H", "I", "J"];
//
// test_operations(
// &case.map(|key| Entry::insert(key.as_bytes(), &[b"v", key.as_bytes()].concat())),
// Some("0957cc9b87c11cef6d88a95328cfd9043a3d6a99e9ba35ee5c9c47e53fb6d42b"),
// )
// }
//
// #[test]
// fn upsert_at_root() {
// let case = ["X", "X"];
//
// let mut i = 0;
//
// test_operations(
// &case.map(|key| {
// i += 1;
// Entry::insert(key.as_bytes(), i.to_string().as_bytes())
// }),
// Some("4538b4de5e58f9be9d54541e69fab8c94c31553a1dec579227ef9b572d1c1dff"),
// )
// }
//
// #[test]
// fn upsert_deeper() {
// // X has higher rank.
// let case = ["X", "F", "F"];
//
// let mut i = 0;
//
// test_operations(
// &case.map(|key| {
// i += 1;
// Entry::insert(key.as_bytes(), i.to_string().as_bytes())
// }),
// Some("c9f7aaefb18ec8569322b9621fc64f430a7389a790e0bf69ec0ad02879d6ce54"),
// )
// }
//
// #[test]
// fn upsert_root_with_children() {
// // X has higher rank.
// let case = ["F", "X", "X"];
//
// let mut i = 0;
//
// test_operations(
// &case.map(|key| {
// i += 1;
// Entry::insert(key.as_bytes(), i.to_string().as_bytes())
// }),
// Some("02e26311f2b55bf6d4a7163399f99e17c975891a05af2f1e09bc969f8bf0f95d"),
// )
// }
use crate::test::{test_operations, Entry};
use proptest::prelude::*;

proptest! {
#[test]
/// Test that upserting an entry with the same key in different tree shapes results in the
/// expected structure
fn test_upsert(random_entries in prop::collection::vec(
(prop::collection::vec(any::<u8>(), 1), prop::collection::vec(any::<u8>(), 1)),
1..10,
)) {
let operations = random_entries.into_iter().map(|(key, value)| {
Entry::insert(&key, &value)
}).collect::<Vec<_>>();

test_operations(&operations, None);
}

#[test]
fn test_general_insertiong(random_entries in prop::collection::vec(
(prop::collection::vec(any::<u8>(), 32), prop::collection::vec(any::<u8>(), 32)),
1..50,
)) {
let operations = random_entries.into_iter().map(|(key, value)| {
Entry::insert(&key, &value)
}).collect::<Vec<_>>();

test_operations(&operations, None);
}
}

#[test]
fn insert_single_entry() {
let case = ["A"];

test_operations(
&case.map(|key| Entry::insert(key.as_bytes(), &[b"v", key.as_bytes()].concat())),
Some("78fd7507ef338f1a5816ffd702394999680a9694a85f4b8af77795d9fdd5854d"),
)
}

#[test]
fn sorted_alphabets() {
let case = [
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
"R", "S", "T", "U", "V", "W", "X", "Y", "Z",
];

test_operations(
&case.map(|key| Entry::insert(key.as_bytes(), &[b"v", key.as_bytes()].concat())),
Some("02af3de6ed6368c5abc16f231a17d1140e7bfec483c8d0aa63af4ef744d29bc3"),
);
}

#[test]
fn reverse_alphabets() {
let mut case = [
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
"R", "S", "T", "U", "V", "W", "X", "Y", "Z",
];
case.reverse();

test_operations(
&case.map(|key| Entry::insert(key.as_bytes(), &[b"v", key.as_bytes()].concat())),
Some("02af3de6ed6368c5abc16f231a17d1140e7bfec483c8d0aa63af4ef744d29bc3"),
)
}

#[test]
fn unsorted() {
let case = ["D", "N", "P", "X", "A", "G", "C", "M", "H", "I", "J"];

test_operations(
&case.map(|key| Entry::insert(key.as_bytes(), &[b"v", key.as_bytes()].concat())),
Some("0957cc9b87c11cef6d88a95328cfd9043a3d6a99e9ba35ee5c9c47e53fb6d42b"),
)
}

#[test]
fn upsert_at_root() {
let case = ["X", "X"];

let mut i = 0;

test_operations(
&case.map(|key| {
i += 1;
Entry::insert(key.as_bytes(), i.to_string().as_bytes())
}),
Some("4538b4de5e58f9be9d54541e69fab8c94c31553a1dec579227ef9b572d1c1dff"),
)
}

#[test]
fn upsert_deeper() {
// X has higher rank.
let case = ["X", "F", "F"];

let mut i = 0;

test_operations(
&case.map(|key| {
i += 1;
Entry::insert(key.as_bytes(), i.to_string().as_bytes())
}),
Some("c9f7aaefb18ec8569322b9621fc64f430a7389a790e0bf69ec0ad02879d6ce54"),
)
}

#[test]
fn upsert_root_with_children() {
// X has higher rank.
let case = ["F", "X", "X"];

let mut i = 0;

test_operations(
&case.map(|key| {
i += 1;
Entry::insert(key.as_bytes(), i.to_string().as_bytes())
}),
Some("02e26311f2b55bf6d4a7163399f99e17c975891a05af2f1e09bc969f8bf0f95d"),
)
}
}
Loading

0 comments on commit 396242b

Please sign in to comment.