]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/csharp/test/Apache.Arrow.Tests/Date32ArrayTests.cs
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / csharp / test / Apache.Arrow.Tests / Date32ArrayTests.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;
17 using System.Collections.Generic;
18 using System.Linq;
19 using Xunit;
20
21 namespace Apache.Arrow.Tests
22 {
23 public class Date32ArrayTests
24 {
25 public static IEnumerable<object[]> GetDatesData() =>
26 TestDateAndTimeData.ExampleDates.Select(d => new object[] { d });
27
28 public static IEnumerable<object[]> GetDateTimesData() =>
29 TestDateAndTimeData.ExampleDateTimes.Select(dt => new object[] { dt });
30
31 public static IEnumerable<object[]> GetDateTimeOffsetsData() =>
32 TestDateAndTimeData.ExampleDateTimeOffsets.Select(dto => new object[] { dto });
33
34 public class AppendNull
35 {
36 [Fact]
37 public void AppendThenGetGivesNull()
38 {
39 // Arrange
40 var builder = new Date32Array.Builder();
41
42 // Act
43 builder = builder.AppendNull();
44
45 // Assert
46 var array = builder.Build();
47 Assert.Equal(1, array.Length);
48 Assert.Null(array.GetDateTime(0));
49 Assert.Null(array.GetDateTimeOffset(0));
50 Assert.Null(array.GetValue(0));
51 }
52 }
53
54 public class AppendDateTime
55 {
56 [Theory]
57 [MemberData(nameof(GetDatesData), MemberType = typeof(Date32ArrayTests))]
58 public void AppendDateGivesSameDate(DateTime date)
59 {
60 // Arrange
61 var builder = new Date32Array.Builder();
62 var expectedDateTime = date;
63 var expectedDateTimeOffset =
64 new DateTimeOffset(DateTime.SpecifyKind(date, DateTimeKind.Unspecified), TimeSpan.Zero);
65 int expectedValue = (int)date.Subtract(new DateTime(1970, 1, 1)).TotalDays;
66
67 // Act
68 builder = builder.Append(date);
69
70 // Assert
71 var array = builder.Build();
72 Assert.Equal(1, array.Length);
73 Assert.Equal(expectedDateTime, array.GetDateTime(0));
74 Assert.Equal(expectedDateTimeOffset, array.GetDateTimeOffset(0));
75 Assert.Equal(expectedValue, array.GetValue(0));
76 }
77
78 [Theory]
79 [MemberData(nameof(GetDateTimesData), MemberType = typeof(Date32ArrayTests))]
80 public void AppendWithTimeGivesSameWithTimeIgnored(DateTime dateTime)
81 {
82 // Arrange
83 var builder = new Date32Array.Builder();
84 var expectedDateTime = dateTime.Date;
85 var expectedDateTimeOffset =
86 new DateTimeOffset(DateTime.SpecifyKind(dateTime.Date, DateTimeKind.Unspecified), TimeSpan.Zero);
87 int expectedValue = (int)dateTime.Date.Subtract(new DateTime(1970, 1, 1)).TotalDays;
88
89 // Act
90 builder = builder.Append(dateTime);
91
92 // Assert
93 var array = builder.Build();
94 Assert.Equal(1, array.Length);
95 Assert.Equal(expectedDateTime, array.GetDateTime(0));
96 Assert.Equal(expectedDateTimeOffset, array.GetDateTimeOffset(0));
97 Assert.Equal(expectedValue, array.GetValue(0));
98 }
99 }
100
101 public class AppendDateTimeOffset
102 {
103 [Theory]
104 [MemberData(nameof(GetDateTimeOffsetsData), MemberType = typeof(Date32ArrayTests))]
105 public void AppendGivesUtcDate(DateTimeOffset dateTimeOffset)
106 {
107 // Arrange
108 var builder = new Date32Array.Builder();
109 var expectedDateTime = dateTimeOffset.UtcDateTime.Date;
110 var expectedDateTimeOffset = new DateTimeOffset(dateTimeOffset.UtcDateTime.Date, TimeSpan.Zero);
111 int expectedValue = (int)dateTimeOffset.UtcDateTime.Date.Subtract(new DateTime(1970, 1, 1)).TotalDays;
112
113 // Act
114 builder = builder.Append(dateTimeOffset);
115
116 // Assert
117 var array = builder.Build();
118 Assert.Equal(1, array.Length);
119 Assert.Equal(expectedDateTime, array.GetDateTime(0));
120 Assert.Equal(expectedDateTimeOffset, array.GetDateTimeOffset(0));
121 Assert.Equal(expectedValue, array.GetValue(0));
122 }
123 }
124 }
125 }