Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:27:10

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include <iosfwd>
0021 
0022 #include "arrow/testing/gtest_util.h"
0023 #include "arrow/util/iterator.h"
0024 
0025 namespace arrow {
0026 
0027 struct TestInt {
0028   TestInt();
0029   TestInt(int i);  // NOLINT runtime/explicit
0030   int value;
0031 
0032   bool operator==(const TestInt& other) const;
0033 
0034   friend std::ostream& operator<<(std::ostream& os, const TestInt& v);
0035 };
0036 
0037 template <>
0038 struct IterationTraits<TestInt> {
0039   static TestInt End() { return TestInt(); }
0040   static bool IsEnd(const TestInt& val) { return val == IterationTraits<TestInt>::End(); }
0041 };
0042 
0043 struct TestStr {
0044   TestStr();
0045   TestStr(const std::string& s);  // NOLINT runtime/explicit
0046   TestStr(const char* s);         // NOLINT runtime/explicit
0047   explicit TestStr(const TestInt& test_int);
0048   std::string value;
0049 
0050   bool operator==(const TestStr& other) const;
0051 
0052   friend std::ostream& operator<<(std::ostream& os, const TestStr& v);
0053 };
0054 
0055 template <>
0056 struct IterationTraits<TestStr> {
0057   static TestStr End() { return TestStr(); }
0058   static bool IsEnd(const TestStr& val) { return val == IterationTraits<TestStr>::End(); }
0059 };
0060 
0061 std::vector<TestInt> RangeVector(unsigned int max, unsigned int step = 1);
0062 
0063 template <typename T>
0064 inline Iterator<T> VectorIt(std::vector<T> v) {
0065   return MakeVectorIterator<T>(std::move(v));
0066 }
0067 
0068 template <typename T>
0069 inline Iterator<T> PossiblySlowVectorIt(std::vector<T> v, bool slow = false) {
0070   auto iterator = MakeVectorIterator<T>(std::move(v));
0071   if (slow) {
0072     return MakeTransformedIterator<T, T>(std::move(iterator),
0073                                          [](T item) -> Result<TransformFlow<T>> {
0074                                            SleepABit();
0075                                            return TransformYield(item);
0076                                          });
0077   } else {
0078     return iterator;
0079   }
0080 }
0081 
0082 template <typename T>
0083 inline void AssertIteratorExhausted(Iterator<T>& it) {
0084   ASSERT_OK_AND_ASSIGN(T next, it.Next());
0085   ASSERT_TRUE(IsIterationEnd(next));
0086 }
0087 
0088 Transformer<TestInt, TestStr> MakeFilter(std::function<bool(TestInt&)> filter);
0089 
0090 }  // namespace arrow