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

Function test_integer

arrow-arith/src/numeric.rs:1107–1172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1105
1106 #[test]
1107 fn test_integer() {
1108 let a = Int32Array::from(vec![4, 3, 5, -6, 100]);
1109 let b = Int32Array::from(vec![6, 2, 5, -7, 3]);
1110 let result = add(&a, &b).unwrap();
1111 assert_eq!(
1112 result.as_ref(),
1113 &Int32Array::from(vec![10, 5, 10, -13, 103])
1114 );
1115 let result = sub(&a, &b).unwrap();
1116 assert_eq!(result.as_ref(), &Int32Array::from(vec![-2, 1, 0, 1, 97]));
1117 let result = div(&a, &b).unwrap();
1118 assert_eq!(result.as_ref(), &Int32Array::from(vec![0, 1, 1, 0, 33]));
1119 let result = mul(&a, &b).unwrap();
1120 assert_eq!(result.as_ref(), &Int32Array::from(vec![24, 6, 25, 42, 300]));
1121 let result = rem(&a, &b).unwrap();
1122 assert_eq!(result.as_ref(), &Int32Array::from(vec![4, 1, 0, -6, 1]));
1123
1124 let a = Int8Array::from(vec![Some(2), None, Some(45)]);
1125 let b = Int8Array::from(vec![Some(5), Some(3), None]);
1126 let result = add(&a, &b).unwrap();
1127 assert_eq!(result.as_ref(), &Int8Array::from(vec![Some(7), None, None]));
1128
1129 let a = UInt8Array::from(vec![56, 5, 3]);
1130 let b = UInt8Array::from(vec![200, 2, 5]);
1131 let err = add(&a, &b).unwrap_err().to_string();
1132 assert_eq!(err, "Arithmetic overflow: Overflow happened on: 56 + 200");
1133 let result = add_wrapping(&a, &b).unwrap();
1134 assert_eq!(result.as_ref(), &UInt8Array::from(vec![0, 7, 8]));
1135
1136 let a = UInt8Array::from(vec![34, 5, 3]);
1137 let b = UInt8Array::from(vec![200, 2, 5]);
1138 let err = sub(&a, &b).unwrap_err().to_string();
1139 assert_eq!(err, "Arithmetic overflow: Overflow happened on: 34 - 200");
1140 let result = sub_wrapping(&a, &b).unwrap();
1141 assert_eq!(result.as_ref(), &UInt8Array::from(vec![90, 3, 254]));
1142
1143 let a = UInt8Array::from(vec![34, 5, 3]);
1144 let b = UInt8Array::from(vec![200, 2, 5]);
1145 let err = mul(&a, &b).unwrap_err().to_string();
1146 assert_eq!(err, "Arithmetic overflow: Overflow happened on: 34 * 200");
1147 let result = mul_wrapping(&a, &b).unwrap();
1148 assert_eq!(result.as_ref(), &UInt8Array::from(vec![144, 10, 15]));
1149
1150 let a = Int16Array::from(vec![i16::MIN]);
1151 let b = Int16Array::from(vec![-1]);
1152 let err = div(&a, &b).unwrap_err().to_string();
1153 assert_eq!(
1154 err,
1155 "Arithmetic overflow: Overflow happened on: -32768 / -1"
1156 );
1157
1158 let a = Int16Array::from(vec![i16::MIN]);
1159 let b = Int16Array::from(vec![-1]);
1160 let result = rem(&a, &b).unwrap();
1161 assert_eq!(result.as_ref(), &Int16Array::from(vec![0]));
1162
1163 let a = Int16Array::from(vec![21]);
1164 let b = Int16Array::from(vec![0]);

Callers

nothing calls this directly

Calls 8

addFunction · 0.85
subFunction · 0.85
divFunction · 0.85
mulFunction · 0.85
remFunction · 0.85
add_wrappingFunction · 0.85
sub_wrappingFunction · 0.85
mul_wrappingFunction · 0.85

Tested by

no test coverage detected