]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/csharp/test/Apache.Arrow.Tests/ArrayTypeComparer.cs
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / csharp / test / Apache.Arrow.Tests / ArrayTypeComparer.cs
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15
16 using System.Diagnostics;
17 using Apache.Arrow.Types;
18 using Xunit;
19
20 namespace Apache.Arrow.Tests
21 {
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>
31 {
32 private readonly IArrowType _expectedType;
33
34 public ArrayTypeComparer(IArrowType expectedType)
35 {
36 Debug.Assert(expectedType != null);
37 _expectedType = expectedType;
38 }
39
40 public void Visit(TimestampType actualType)
41 {
42 Assert.IsAssignableFrom<TimestampType>(_expectedType);
43
44 var expectedType = (TimestampType)_expectedType;
45
46 Assert.Equal(expectedType.Timezone, actualType.Timezone);
47 Assert.Equal(expectedType.Unit, actualType.Unit);
48 }
49
50 public void Visit(Date32Type actualType)
51 {
52 Assert.IsAssignableFrom<Date32Type>(_expectedType);
53 var expectedType = (Date32Type)_expectedType;
54
55 Assert.Equal(expectedType.Unit, actualType.Unit);
56 }
57
58 public void Visit(Date64Type actualType)
59 {
60 Assert.IsAssignableFrom<Date64Type>(_expectedType);
61 var expectedType = (Date64Type)_expectedType;
62
63 Assert.Equal(expectedType.Unit, actualType.Unit);
64 }
65
66 public void Visit(Time32Type actualType)
67 {
68 Assert.IsAssignableFrom<Time32Type>(_expectedType);
69 var expectedType = (Time32Type)_expectedType;
70
71 Assert.Equal(expectedType.Unit, actualType.Unit);
72 }
73
74 public void Visit(Time64Type actualType)
75 {
76 Assert.IsAssignableFrom<Time64Type>(_expectedType);
77 var expectedType = (Time64Type)_expectedType;
78
79 Assert.Equal(expectedType.Unit, actualType.Unit);
80 }
81
82 public void Visit(FixedSizeBinaryType actualType)
83 {
84 Assert.IsAssignableFrom<FixedSizeBinaryType>(_expectedType);
85 var expectedType = (FixedSizeBinaryType)_expectedType;
86
87 Assert.Equal(expectedType.ByteWidth, actualType.ByteWidth);
88 }
89
90 public void Visit(ListType actualType)
91 {
92 Assert.IsAssignableFrom<ListType>(_expectedType);
93 var expectedType = (ListType)_expectedType;
94
95 CompareNested(expectedType, actualType);
96 }
97
98 public void Visit(StructType actualType)
99 {
100 Assert.IsAssignableFrom<StructType>(_expectedType);
101 var expectedType = (StructType)_expectedType;
102
103 CompareNested(expectedType, actualType);
104 }
105
106 private static void CompareNested(NestedType expectedType, NestedType actualType)
107 {
108 Assert.Equal(expectedType.Fields.Count, actualType.Fields.Count);
109
110 for (int i = 0; i < expectedType.Fields.Count; i++)
111 {
112 FieldComparer.Compare(expectedType.Fields[i], actualType.Fields[i]);
113 }
114 }
115
116 public void Visit(IArrowType actualType)
117 {
118 Assert.IsAssignableFrom(actualType.GetType(), _expectedType);
119 }
120 }
121 }