From ddb73d8351013e128949b7c0be80dd1124fea2a8 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 21 Feb 2021 20:06:28 +0100 Subject: [PATCH] Added some missing tests --- src/algorithms/utils.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/algorithms/utils.rs b/src/algorithms/utils.rs index 622b2ee..26575fd 100644 --- a/src/algorithms/utils.rs +++ b/src/algorithms/utils.rs @@ -150,3 +150,43 @@ fn test_unique() { .collect::>(); assert_eq!(u, vec![('a', 0), ('c', 2)]); } + +#[test] +fn test_common_prefix_len() { + assert_eq!( + common_prefix_len("".as_bytes(), 0..0, "".as_bytes(), 0..0), + 0 + ); + assert_eq!( + common_prefix_len("foobarbaz".as_bytes(), 0..9, "foobarblah".as_bytes(), 0..10), + 7 + ); + assert_eq!( + common_prefix_len("foobarbaz".as_bytes(), 0..9, "blablabla".as_bytes(), 0..9), + 0 + ); + assert_eq!( + common_prefix_len("foobarbaz".as_bytes(), 3..9, "foobarblah".as_bytes(), 3..10), + 4 + ); +} + +#[test] +fn test_common_suffix_len() { + assert_eq!( + common_suffix_len("".as_bytes(), 0..0, "".as_bytes(), 0..0), + 0 + ); + assert_eq!( + common_suffix_len("1234".as_bytes(), 0..4, "X0001234".as_bytes(), 0..8), + 4 + ); + assert_eq!( + common_suffix_len("1234".as_bytes(), 0..4, "Xxxx".as_bytes(), 0..4), + 0 + ); + assert_eq!( + common_suffix_len("1234".as_bytes(), 2..4, "01234".as_bytes(), 2..5), + 2 + ); +}