From dc506de8aa22d06ea455e6d3747d944e1f3cc03b Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 12 May 2024 02:47:12 +0200 Subject: [PATCH] test: split-numbers #76 test if splitting of numbers into Vec works correctly --- members/libpt-bintols/tests/split_numbers.rs | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 members/libpt-bintols/tests/split_numbers.rs diff --git a/members/libpt-bintols/tests/split_numbers.rs b/members/libpt-bintols/tests/split_numbers.rs new file mode 100644 index 0000000..52b5ac5 --- /dev/null +++ b/members/libpt-bintols/tests/split_numbers.rs @@ -0,0 +1,35 @@ +use libpt_bintols::split_numbers::*; + +#[test] +fn split_u128() { + let source = [16, 255, 256, 0, u128::MAX, u64::MAX as u128]; + let correct = [ + vec![16], + vec![255], + vec![255, 1], + vec![0], + vec![ + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + ], + vec![255, 255, 255, 255, 255, 255, 255, 255], + ]; + for (i, n) in source.iter().enumerate() { + assert_eq!(unsigned_to_vec(*n), correct[i]); + } +} + +#[test] +fn split_u64() { + let source = [16, 255, 256, 0, u64::MAX, u32::MAX as u64]; + let correct = [ + vec![16], + vec![255], + vec![255, 1], + vec![0], + vec![255, 255, 255, 255, 255, 255, 255, 255], + vec![255, 255, 255, 255], + ]; + for (i, n) in source.iter().enumerate() { + assert_eq!(unsigned_to_vec(*n), correct[i]); + } +}