]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | // Licensed to the Apache Software Foundation (ASF) under one |
2 | // or more contributor license agreements. See the NOTICE file | |
3 | // distributed with this work for additional information | |
4 | // regarding copyright ownership. The ASF licenses this file | |
5 | // to you under the Apache License, Version 2.0 (the | |
6 | // "License"); you may not use this file except in compliance | |
7 | // with the License. You may obtain a copy of the License at | |
8 | // | |
9 | // http://www.apache.org/licenses/LICENSE-2.0 | |
10 | // | |
11 | // Unless required by applicable law or agreed to in writing, | |
12 | // software distributed under the License is distributed on an | |
13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | // KIND, either express or implied. See the License for the | |
15 | // specific language governing permissions and limitations | |
16 | // under the License. | |
17 | ||
18 | #include <gtest/gtest.h> | |
19 | ||
20 | #include "arrow/testing/gtest_util.h" | |
21 | #include "arrow/util/time.h" | |
22 | ||
23 | namespace arrow { | |
24 | namespace util { | |
25 | ||
26 | TEST(TimeTest, ConvertTimestampValue) { | |
27 | auto convert = [](TimeUnit::type in, TimeUnit::type out, int64_t value) { | |
28 | return ConvertTimestampValue(timestamp(in), timestamp(out), value).ValueOrDie(); | |
29 | }; | |
30 | ||
31 | auto units = { | |
32 | TimeUnit::SECOND, | |
33 | TimeUnit::MILLI, | |
34 | TimeUnit::MICRO, | |
35 | TimeUnit::NANO, | |
36 | }; | |
37 | ||
38 | // Test for identity | |
39 | for (auto unit : units) { | |
40 | EXPECT_EQ(convert(unit, unit, 0), 0); | |
41 | EXPECT_EQ(convert(unit, unit, INT64_MAX), INT64_MAX); | |
42 | EXPECT_EQ(convert(unit, unit, INT64_MIN), INT64_MIN); | |
43 | } | |
44 | ||
45 | EXPECT_EQ(convert(TimeUnit::SECOND, TimeUnit::MILLI, 2), 2000); | |
46 | EXPECT_EQ(convert(TimeUnit::SECOND, TimeUnit::MICRO, 2), 2000000); | |
47 | EXPECT_EQ(convert(TimeUnit::SECOND, TimeUnit::NANO, 2), 2000000000); | |
48 | ||
49 | EXPECT_EQ(convert(TimeUnit::MILLI, TimeUnit::SECOND, 7000), 7); | |
50 | EXPECT_EQ(convert(TimeUnit::MILLI, TimeUnit::MICRO, 7), 7000); | |
51 | EXPECT_EQ(convert(TimeUnit::MILLI, TimeUnit::NANO, 7), 7000000); | |
52 | ||
53 | EXPECT_EQ(convert(TimeUnit::MICRO, TimeUnit::SECOND, 4000000), 4); | |
54 | EXPECT_EQ(convert(TimeUnit::MICRO, TimeUnit::MILLI, 4000), 4); | |
55 | EXPECT_EQ(convert(TimeUnit::MICRO, TimeUnit::SECOND, 4000000), 4); | |
56 | ||
57 | EXPECT_EQ(convert(TimeUnit::NANO, TimeUnit::SECOND, 6000000000), 6); | |
58 | EXPECT_EQ(convert(TimeUnit::NANO, TimeUnit::MILLI, 6000000), 6); | |
59 | EXPECT_EQ(convert(TimeUnit::NANO, TimeUnit::MICRO, 6000), 6); | |
60 | } | |
61 | ||
62 | } // namespace util | |
63 | } // namespace arrow |