Add date16 unit test
this is an attempt
@@ -26,12 +26,89 @@ use crate::scalars::dates::number_function::ToDayOfYearFunction;
use crate::scalars::dates::number_function::ToMinuteFunction;
use crate::scalars::dates::number_function::ToMondayFunction;
use crate::scalars::dates::number_function::ToMonthFunction;
-use crate::scalars::ToHourFunction;
+use crate::scalars::{ToHourFunction, Function};
use crate::scalars::ToSecondFunction;
use crate::scalars::ToYYYYMMDDFunction;
use crate::scalars::ToYYYYMMDDhhmmssFunction;
use crate::scalars::ToYYYYMMFunction;
+#[test]
+fn test_toyyyymm_function() -> Result<()> {
+ #[allow(dead_code)]
+ struct Test {
+ name: &'static str,
+ display: &'static str,
+ arg_names: Vec<&'static str>,
+ func: Box<dyn Function>,
+ columns: Vec<DataColumn>,
+ expect: DataColumn,
+ error: &'static str,
+ nullable:bool,
+ }
+ let schema = DataSchemaRefExt::create(vec![
+ DataField::new("a", DataType::DateTime32(None), false),
+ DataField::new("b", DataType::Date32, false),
+ DataField::new("c", DataType::Date16, false),
+ ]);
+
+ let tests = vec![
+ Test {
+ name: "test_toyyyymm_date16",
+ display: "c()",
+ arg_names: vec!["c"],
+ func: ToYYYYMMFunction::try_create("c")?,
+ columns: vec![
+ Series::new(vec![0u16]).into(),
+ ],
+ nullable:false,
+ expect: Series::new(vec![197001]).into(),
+ error:""
+ }
+ ];
+
+ for t in tests {
+ let rows = t.columns[0].len();
+
+ // Type check
+ let mut args = vec![];
+ let mut fields = vec![];
+ for name in t.arg_names {
+ args.push(schema.field_with_name(name)?.data_type().clone());
+ fields.push(schema.field_with_name(name)?.clone());
+ }
+
+ let columns: Vec<DataColumnWithField> = t.columns
+ .iter()
+ .zip(fields.iter())
+ .map(|(c, f)| DataColumnWithField::new(c.clone(), f.clone()))
+ .collect();
+
+ let func = t.func;
+ if let Err(e) = func.eval(&columns, rows) {
+ assert_eq!(t.error, e.to_string());
+ }
+
+ // Display check
+ let expect_display = t.display.to_string();
+ let actual_display = format!("{}", func);
+ assert_eq!(expect_display, actual_display);
+
+ // Nullable check.
+ let expect_null = t.nullable;
+ let actual_null = func.nullable(&schema)?;
+ assert_eq!(expect_null, actual_null);
+
+ let expect_type = func.return_type(&args)?.clone();
+ let v = &(func.eval(&columns, rows)?);
+ let actual_type = v.data_type().clone();
+ assert_eq!(expect_type, actual_type);
+
+ assert_eq!(v, &t.expect);
+ }
+
+ Ok(())
+}
+
#[test]
fn test_toyyyymm_date16_function() -> Result<()> {
let schema = DataSchemaRefExt::create(vec![DataField::new("a", DataType::Date16, false)]);
