1 // Licensed to the Apache Software Foundation (ASF) under one or more
2 // contributor license agreements. See the NOTICE file distributed with
3 // this work for additional information regarding copyright ownership.
4 // The ASF licenses this file to You under the Apache License, Version 2.0
5 // (the "License"); you may not use this file except in compliance with
6 // the License. You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 using System.Diagnostics;
17 using Apache.Arrow.Types;
20 namespace Apache.Arrow.Tests
22 public class ArrayTypeComparer :
23 IArrowTypeVisitor<TimestampType>,
24 IArrowTypeVisitor<Date32Type>,
25 IArrowTypeVisitor<Date64Type>,
26 IArrowTypeVisitor<Time32Type>,
27 IArrowTypeVisitor<Time64Type>,
28 IArrowTypeVisitor<FixedSizeBinaryType>,
29 IArrowTypeVisitor<ListType>,
30 IArrowTypeVisitor<StructType>
32 private readonly IArrowType _expectedType;
34 public ArrayTypeComparer(IArrowType expectedType)
36 Debug.Assert(expectedType != null);
37 _expectedType = expectedType;
40 public void Visit(TimestampType actualType)
42 Assert.IsAssignableFrom<TimestampType>(_expectedType);
44 var expectedType = (TimestampType)_expectedType;
46 Assert.Equal(expectedType.Timezone, actualType.Timezone);
47 Assert.Equal(expectedType.Unit, actualType.Unit);
50 public void Visit(Date32Type actualType)
52 Assert.IsAssignableFrom<Date32Type>(_expectedType);
53 var expectedType = (Date32Type)_expectedType;
55 Assert.Equal(expectedType.Unit, actualType.Unit);
58 public void Visit(Date64Type actualType)
60 Assert.IsAssignableFrom<Date64Type>(_expectedType);
61 var expectedType = (Date64Type)_expectedType;
63 Assert.Equal(expectedType.Unit, actualType.Unit);
66 public void Visit(Time32Type actualType)
68 Assert.IsAssignableFrom<Time32Type>(_expectedType);
69 var expectedType = (Time32Type)_expectedType;
71 Assert.Equal(expectedType.Unit, actualType.Unit);
74 public void Visit(Time64Type actualType)
76 Assert.IsAssignableFrom<Time64Type>(_expectedType);
77 var expectedType = (Time64Type)_expectedType;
79 Assert.Equal(expectedType.Unit, actualType.Unit);
82 public void Visit(FixedSizeBinaryType actualType)
84 Assert.IsAssignableFrom<FixedSizeBinaryType>(_expectedType);
85 var expectedType = (FixedSizeBinaryType)_expectedType;
87 Assert.Equal(expectedType.ByteWidth, actualType.ByteWidth);
90 public void Visit(ListType actualType)
92 Assert.IsAssignableFrom<ListType>(_expectedType);
93 var expectedType = (ListType)_expectedType;
95 CompareNested(expectedType, actualType);
98 public void Visit(StructType actualType)
100 Assert.IsAssignableFrom<StructType>(_expectedType);
101 var expectedType = (StructType)_expectedType;
103 CompareNested(expectedType, actualType);
106 private static void CompareNested(NestedType expectedType, NestedType actualType)
108 Assert.Equal(expectedType.Fields.Count, actualType.Fields.Count);
110 for (int i = 0; i < expectedType.Fields.Count; i++)
112 FieldComparer.Compare(expectedType.Fields[i], actualType.Fields[i]);
116 public void Visit(IArrowType actualType)
118 Assert.IsAssignableFrom(actualType.GetType(), _expectedType);