alamb commented on a change in pull request #273:
URL: https://github.com/apache/arrow-rs/pull/273#discussion_r629255080



##########
File path: arrow/src/util/display.rs
##########
@@ -296,3 +297,48 @@ fn dict_array_value_to_string<K: ArrowPrimitiveType>(
 
     array_value_to_string(&dict_array.values(), dict_index)
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use crate::{
+        array::ArrayRef,
+        array::{ArrayData, DecimalArray, Int32Array},
+    };
+    use crate::{buffer::Buffer, datatypes::DataType};
+    use std::sync::Arc;
+
+    #[test]
+    fn test_int_display() -> Result<()> {
+        let array = Arc::new(Int32Array::from(vec![6, 3])) as ArrayRef;
+        let actual_one = array_value_to_string(&array, 0).unwrap();
+        let expected_one = String::from("6");

Review comment:
       ```suggestion
           let expected_one = "6";
   ```
   
   I don't think you need to create a `String` you can just compare with the 
`&str`

##########
File path: arrow/src/util/display.rs
##########
@@ -296,3 +297,48 @@ fn dict_array_value_to_string<K: ArrowPrimitiveType>(
 
     array_value_to_string(&dict_array.values(), dict_index)
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use crate::{
+        array::ArrayRef,
+        array::{ArrayData, DecimalArray, Int32Array},
+    };
+    use crate::{buffer::Buffer, datatypes::DataType};
+    use std::sync::Arc;
+
+    #[test]
+    fn test_int_display() -> Result<()> {
+        let array = Arc::new(Int32Array::from(vec![6, 3])) as ArrayRef;
+        let actual_one = array_value_to_string(&array, 0).unwrap();
+        let expected_one = String::from("6");
+
+        let actual_two = array_value_to_string(&array, 1).unwrap();
+        let expected_two = String::from("3");
+        assert_eq!(actual_one, expected_one);
+        assert_eq!(actual_two, expected_two);
+        Ok(())
+    }
+
+    #[test]
+    fn test_decimal_display() -> Result<()> {
+        let values: [u8; 32] = [

Review comment:
       This is a pretty low level way to make a `DecimalArray`
   
   What would you think of using the `DecimalBuilder` -- something like the 
following
   
   ```
           let capacity = 10;
           let precision = 10; // total number of digits
           let scale = 2; // 2 digits after the decimal point
           let mut builder = DecimalBuilder::new(capacity, precision, scale);
           builder.append_value(101).unwrap();
           builder.append_null().unwrap();
           builder.append_value(200).unwrap();
           builder.append_value(3040).unwrap();
   
           let dm = Arc::new(builder.finish()) as ArrayRef;
   ```
   
   
   Note in this case, I would expect the display values to be something like 
the following (always have 2 decimal places):
   ```
   1.01
   
   2.00
   30.40
   ```
   
   

##########
File path: arrow/src/util/display.rs
##########
@@ -296,3 +297,48 @@ fn dict_array_value_to_string<K: ArrowPrimitiveType>(
 
     array_value_to_string(&dict_array.values(), dict_index)
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use crate::{
+        array::ArrayRef,
+        array::{ArrayData, DecimalArray, Int32Array},
+    };
+    use crate::{buffer::Buffer, datatypes::DataType};
+    use std::sync::Arc;
+
+    #[test]

Review comment:
       There are a few more tests of `pretty-printing` which uses this display 
code in 
https://github.com/apache/arrow-rs/blob/master/arrow/src/util/pretty.rs#L229 
   
   You might find writing tests following that style (perhaps putting the tests 
in that module) easier

##########
File path: arrow/src/util/display.rs
##########
@@ -296,3 +297,48 @@ fn dict_array_value_to_string<K: ArrowPrimitiveType>(
 
     array_value_to_string(&dict_array.values(), dict_index)
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use crate::{
+        array::ArrayRef,
+        array::{ArrayData, DecimalArray, Int32Array},
+    };
+    use crate::{buffer::Buffer, datatypes::DataType};
+    use std::sync::Arc;
+
+    #[test]
+    fn test_int_display() -> Result<()> {
+        let array = Arc::new(Int32Array::from(vec![6, 3])) as ArrayRef;
+        let actual_one = array_value_to_string(&array, 0).unwrap();
+        let expected_one = String::from("6");
+
+        let actual_two = array_value_to_string(&array, 1).unwrap();
+        let expected_two = String::from("3");

Review comment:
       ```suggestion
           let expected_two = "3";
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to