MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_from_bitwise_unary_op

Function test_from_bitwise_unary_op

arrow-buffer/src/buffer/boolean.rs:992–1027  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

990
991 #[test]
992 fn test_from_bitwise_unary_op() {
993 // Use 1024 boolean values so that at least some of the tests cover multiple u64 chunks and
994 // perfect alignment
995 let input_bools = (0..1024)
996 .map(|_| rand::random::<bool>())
997 .collect::<Vec<bool>>();
998 let input_buffer = BooleanBuffer::from(&input_bools[..]);
999
1000 // Note ensure we test offsets over 100 to cover multiple u64 chunks
1001 for offset in 0..1024 {
1002 let result = BooleanBuffer::from_bitwise_unary_op(
1003 input_buffer.values(),
1004 offset,
1005 input_buffer.len() - offset,
1006 |a| !a,
1007 );
1008 let expected = input_bools[offset..]
1009 .iter()
1010 .map(|b| !*b)
1011 .collect::<BooleanBuffer>();
1012 assert_eq!(result, expected);
1013 }
1014
1015 // Also test when the input doesn't cover the entire buffer
1016 for offset in 0..512 {
1017 let len = 512 - offset; // fixed length less than total
1018 let result =
1019 BooleanBuffer::from_bitwise_unary_op(input_buffer.values(), offset, len, |a| !a);
1020 let expected = input_bools[offset..]
1021 .iter()
1022 .take(len)
1023 .map(|b| !*b)
1024 .collect::<BooleanBuffer>();
1025 assert_eq!(result, expected);
1026 }
1027 }
1028
1029 #[test]
1030 fn test_from_bitwise_unary_op_unaligned_fallback() {

Callers

nothing calls this directly

Calls 4

valuesMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected