소스 검색

test: move the rest of tests to local files

chore: fix includes
Sam Jaffe 2 년 전
부모
커밋
74e0adb327

+ 4 - 2
include/stream/algorithm/fold.h

@@ -9,10 +9,12 @@
 
 #include <optional>
 
+#include <stream/forward.h>
+
 #include <stream/detail/identity.h>
 #include <stream/detail/traits.h>
 
-#define FWD(x) std::forward<decltype(x)>(x)
+#include <stream/detail/macro.h>
 
 namespace stream::ranges {
 template <typename It, typename S, typename T, typename F>
@@ -38,4 +40,4 @@ auto fold_left_with_first(Stream && stream, F reduce) {
 }
 }
 
-#undef FWD
+#include <stream/detail/undef.h>

+ 4 - 2
include/stream/algorithm/for_each.h

@@ -7,10 +7,12 @@
 
 #pragma once
 
+#include <stream/forward.h>
+
 #include <stream/detail/identity.h>
 #include <stream/detail/named_pair.h>
 
-#define FWD(x) std::forward<decltype(x)>(x)
+#include <stream/detail/macro.h>
 
 namespace stream::ranges {
 template <typename It, typename S, typename F, typename Proj = detail::identity>
@@ -27,4 +29,4 @@ auto for_each(Stream && stream, F func, Proj proj = {}) {
 }
 }
 
-#undef FWD
+#include <stream/detail/undef.h>

+ 2 - 0
include/stream/algorithm/size.h

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#include <stream/forward.h>
+
 #include <stream/detail/traits.h>
 
 namespace stream::ranges {

+ 4 - 0
include/stream/detail/identity.h

@@ -7,6 +7,10 @@
 
 #pragma once
 
+#include <utility>
+
+#include <stream/forward.h>
+
 namespace stream::detail {
 struct identity {
   template <typename T> decltype(auto) operator()(T && t) const {

+ 2 - 0
include/stream/detail/invoke.h

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#include <stream/forward.h>
+
 #include <stream/detail/macro.h>
 
 namespace stream::detail {

+ 2 - 2
include/stream/detail/traits.h

@@ -15,7 +15,7 @@
 
 #include <stream/forward.h>
 
-#include <iterator/detail/macro.h>
+#include <stream/detail/macro.h>
 
 namespace stream::detail {
 template <typename C> using begin_t = decltype(std::begin(VAL(C)));
@@ -59,4 +59,4 @@ template <typename It, typename S>
 constexpr bool is_sized_sentinel_v = is_sized_sentinel<It, S>{};
 }
 
-#include <iterator/detail/undef.h>
+#include <stream/detail/undef.h>

+ 1 - 0
include/stream/iterator/common_iterator.h

@@ -8,6 +8,7 @@
 #pragma once
 
 #include <iterator/proxy.h>
+
 #include <stream/forward.h>
 
 namespace stream::ranges {

+ 1 - 0
include/stream/iterator/transform_iterator.h

@@ -8,6 +8,7 @@
 #pragma once
 
 #include <iterator/proxy.h>
+
 #include <stream/forward.h>
 
 namespace stream::ranges {

+ 3 - 2
include/stream/to_container.h

@@ -12,9 +12,10 @@
 #include <vector>
 
 #include <stream/forward.h>
+
 #include <stream/view/common.h>
 
-#include <iterator/detail/macro.h>
+#include <stream/detail/macro.h>
 
 namespace stream::ranges {
 template <typename C> class store {
@@ -47,4 +48,4 @@ inline auto to_map() { return to<std::map>(); }
 inline auto to_set() { return to<std::set>(); }
 }
 
-#include <iterator/detail/undef.h>
+#include <stream/detail/undef.h>

+ 2 - 2
include/stream/view/all.h

@@ -9,7 +9,7 @@
 
 #include <stream/forward.h>
 
-#include <iterator/detail/macro.h>
+#include <stream/detail/macro.h>
 
 namespace stream::ranges {
 template <typename C> class all_view {
@@ -37,4 +37,4 @@ template <typename C> auto all(C && container) {
 }
 }
 
-#include <iterator/detail/undef.h>
+#include <stream/detail/undef.h>

+ 2 - 1
include/stream/view/any.h

@@ -9,8 +9,9 @@
 
 #include <memory>
 
-#include <stream/detail/traits.h>
 #include <stream/forward.h>
+
+#include <stream/detail/traits.h>
 #include <stream/view/any.h>
 #include <stream/view/common.h>
 

+ 2 - 1
include/stream/view/common.h

@@ -7,8 +7,9 @@
 
 #pragma once
 
-#include <stream/detail/traits.h>
 #include <stream/forward.h>
+
+#include <stream/detail/traits.h>
 #include <stream/iterator/common_iterator.h>
 
 #include <stream/detail/macro.h>

+ 2 - 0
include/stream/view/empty.h

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#include <stream/forward.h>
+
 namespace stream::ranges {
 template <typename T> struct empty_view {
   static T * begin() { return nullptr; }

+ 4 - 2
include/stream/view/filter.h

@@ -4,9 +4,11 @@
 
 #include <iterator/filter_iterator.h>
 
+#include <stream/forward.h>
+
 #include <stream/detail/traits.h>
 
-#define FWD(x) std::forward<decltype(x)>(x)
+#include <stream/detail/macro.h>
 
 namespace stream::ranges {
 template <typename S, typename P> class filter_view {
@@ -43,4 +45,4 @@ private:
 };
 }
 
-#undef FWD
+#include <stream/detail/undef.h>

+ 2 - 0
include/stream/view/iota.h

@@ -9,6 +9,8 @@
 
 #include <iterator/facade.h>
 
+#include <stream/forward.h>
+
 namespace stream::ranges {
 template <typename T, typename Bound>
 class iota_iterator : public facade<iota_iterator<T, Bound>> {

+ 4 - 2
include/stream/view/join.h

@@ -2,7 +2,9 @@
 
 #include <iterator/join_iterator.h>
 
-#define FWD(x) std::forward<decltype(x)>(x)
+#include <stream/forward.h>
+
+#include <stream/detail/macro.h>
 
 namespace stream::ranges {
 template <typename S> struct join_view {
@@ -27,4 +29,4 @@ struct join {
 };
 }
 
-#undef FWD
+#include <stream/detail/undef.h>

+ 2 - 0
include/stream/view/map.h

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#include <stream/forward.h>
+
 #include <stream/view/transform.h>
 
 namespace stream::ranges::views {

+ 2 - 0
include/stream/view/ref.h

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#include <stream/forward.h>
+
 #include <stream/view/transform.h>
 
 namespace stream::ranges::views {

+ 2 - 0
include/stream/view/single.h

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#include <stream/forward.h>
+
 namespace stream::ranges {
 template <typename T> class single_view {
 private:

+ 5 - 2
include/stream/view/subrange.h

@@ -3,9 +3,12 @@
 #include <iterator>
 
 #include <iterator/detail/facade_traits.h>
+
 #include <stream/forward.h>
 
-#include <iterator/detail/macro.h>
+#include <stream/detail/traits.h>
+
+#include <stream/detail/macro.h>
 
 namespace stream::ranges {
 template <typename It, typename S = It> class subrange {
@@ -36,4 +39,4 @@ template <typename C>
 subrange(C &&) -> subrange<detail::begin_t<C>, detail::end_t<C>>;
 }
 
-#include <iterator/detail/undef.h>
+#include <stream/detail/undef.h>

+ 2 - 1
include/stream/view/transform.h

@@ -2,8 +2,9 @@
 
 #include <functional>
 
-#include <stream/detail/traits.h>
 #include <stream/forward.h>
+
+#include <stream/detail/traits.h>
 #include <stream/iterator/transform_iterator.h>
 
 #include <stream/detail/macro.h>

+ 16 - 4
stream.xcodeproj/project.pbxproj

@@ -15,9 +15,12 @@
 		CD5A559E29DE35E900881E7E /* join_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD5A559D29DE35E900881E7E /* join_test.cxx */; };
 		CD5A55A029DE375B00881E7E /* composed_views_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD5A559F29DE375B00881E7E /* composed_views_test.cxx */; };
 		CD5A55A229DE37B400881E7E /* iota_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD5A55A129DE37B400881E7E /* iota_test.cxx */; };
+		CD5A55A429DF792000881E7E /* single_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD5A55A329DF792000881E7E /* single_test.cxx */; };
+		CD5A55A629DF8DEE00881E7E /* for_each_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD5A55A529DF8DEE00881E7E /* for_each_test.cxx */; };
+		CD5A55A829DF8E7B00881E7E /* subrange_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD5A55A729DF8E7B00881E7E /* subrange_test.cxx */; };
+		CD5A55AA29DF8EDB00881E7E /* ref_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD5A55A929DF8EDB00881E7E /* ref_test.cxx */; };
 		CDA37D4029D9D38E000A1F97 /* all_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDA37D3E29D9D38E000A1F97 /* all_test.cxx */; };
 		CDA54F9E29DA59C4006C0FAA /* common_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDA54F9D29DA59C4006C0FAA /* common_test.cxx */; };
-		CDEC1D7623514BEB0091D9F2 /* stream_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CD9337281E3CD78B00699FF5 /* stream_test.cxx */; };
 		CDEC1D7923514BF80091D9F2 /* GoogleMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDEC1D6323514BB50091D9F2 /* GoogleMock.framework */; };
 /* End PBXBuildFile section */
 
@@ -102,13 +105,16 @@
 		CD5A559D29DE35E900881E7E /* join_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = join_test.cxx; sourceTree = "<group>"; };
 		CD5A559F29DE375B00881E7E /* composed_views_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = composed_views_test.cxx; sourceTree = "<group>"; };
 		CD5A55A129DE37B400881E7E /* iota_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = iota_test.cxx; sourceTree = "<group>"; };
+		CD5A55A329DF792000881E7E /* single_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = single_test.cxx; sourceTree = "<group>"; };
+		CD5A55A529DF8DEE00881E7E /* for_each_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = for_each_test.cxx; sourceTree = "<group>"; };
+		CD5A55A729DF8E7B00881E7E /* subrange_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = subrange_test.cxx; sourceTree = "<group>"; };
+		CD5A55A929DF8EDB00881E7E /* ref_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ref_test.cxx; sourceTree = "<group>"; };
 		CD5A8D3529D63C05008C2A4F /* count.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = count.h; sourceTree = "<group>"; };
 		CD5A8D3B29D63DF5008C2A4F /* named_pair.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = named_pair.h; sourceTree = "<group>"; };
 		CD64CCB926232D6900770A30 /* xcode_gtest_helper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = xcode_gtest_helper.h; sourceTree = "<group>"; };
 		CD6EBE1C29D5C61700F387C1 /* common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = "<group>"; };
 		CD6EBE2329D5CAD900F387C1 /* size.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = size.h; sourceTree = "<group>"; };
 		CD6EBE2629D63B9E00F387C1 /* minmax.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = minmax.h; sourceTree = "<group>"; };
-		CD9337281E3CD78B00699FF5 /* stream_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = stream_test.cxx; sourceTree = "<group>"; };
 		CDA37D3929D9BDED000A1F97 /* macro.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = macro.h; sourceTree = "<group>"; };
 		CDA37D3A29D9BDF2000A1F97 /* undef.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = undef.h; sourceTree = "<group>"; };
 		CDA37D3B29D9C30B000A1F97 /* common_iterator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = common_iterator.h; sourceTree = "<group>"; };
@@ -232,14 +238,17 @@
 				CD64CCB926232D6900770A30 /* xcode_gtest_helper.h */,
 				CDA37D4429D9D55D000A1F97 /* stream_matchers.h */,
 				CD5A559429DCD12300881E7E /* stream_helpers.h */,
-				CD9337281E3CD78B00699FF5 /* stream_test.cxx */,
 				CDA37D3E29D9D38E000A1F97 /* all_test.cxx */,
 				CDA54F9D29DA59C4006C0FAA /* common_test.cxx */,
 				CD5A559F29DE375B00881E7E /* composed_views_test.cxx */,
 				CD5A559929DE34B800881E7E /* filter_test.cxx */,
 				CD5A559B29DE353800881E7E /* fold_test.cxx */,
+				CD5A55A529DF8DEE00881E7E /* for_each_test.cxx */,
 				CD5A55A129DE37B400881E7E /* iota_test.cxx */,
 				CD5A559D29DE35E900881E7E /* join_test.cxx */,
+				CD5A55A929DF8EDB00881E7E /* ref_test.cxx */,
+				CD5A55A329DF792000881E7E /* single_test.cxx */,
+				CD5A55A729DF8E7B00881E7E /* subrange_test.cxx */,
 				CD5A559529DE2B3400881E7E /* to_container_test.cxx */,
 				CD5A559729DE2DB900881E7E /* transform_test.cxx */,
 			);
@@ -498,12 +507,15 @@
 			files = (
 				CD5A559C29DE353800881E7E /* fold_test.cxx in Sources */,
 				CDA54F9E29DA59C4006C0FAA /* common_test.cxx in Sources */,
+				CD5A55A429DF792000881E7E /* single_test.cxx in Sources */,
 				CD5A559A29DE34B800881E7E /* filter_test.cxx in Sources */,
-				CDEC1D7623514BEB0091D9F2 /* stream_test.cxx in Sources */,
 				CD5A55A229DE37B400881E7E /* iota_test.cxx in Sources */,
 				CD5A559629DE2B3400881E7E /* to_container_test.cxx in Sources */,
 				CD5A55A029DE375B00881E7E /* composed_views_test.cxx in Sources */,
+				CD5A55A629DF8DEE00881E7E /* for_each_test.cxx in Sources */,
+				CD5A55AA29DF8EDB00881E7E /* ref_test.cxx in Sources */,
 				CD5A559E29DE35E900881E7E /* join_test.cxx in Sources */,
+				CD5A55A829DF8E7B00881E7E /* subrange_test.cxx in Sources */,
 				CDA37D4029D9D38E000A1F97 /* all_test.cxx in Sources */,
 				CD5A559829DE2DB900881E7E /* transform_test.cxx in Sources */,
 			);

+ 19 - 0
test/for_each_test.cxx

@@ -0,0 +1,19 @@
+//
+//  for_each_test.cxx
+//  stream-test
+//
+//  Created by Sam Jaffe on 4/6/23.
+//
+
+#include "stream/algorithm/for_each.h"
+
+#include "stream_helpers.h"
+#include "stream_matchers.h"
+
+TEST(ForEach, IteratesOverEachItem) {
+  int hits = 0;
+
+  ranges::for_each(std::vector<int>{1, 2, 3, 4, 5}, [&hits](int) { ++hits; });
+
+  EXPECT_THAT(hits, 5);
+}

+ 19 - 0
test/ref_test.cxx

@@ -0,0 +1,19 @@
+//
+//  ref_test.cxx
+//  stream-test
+//
+//  Created by Sam Jaffe on 4/6/23.
+//
+
+#include "stream/view/ref.h"
+
+#include "stream_helpers.h"
+#include "stream_matchers.h"
+
+TEST(RefView, CanDereference) {
+  int val = 5;
+  std::vector<int *> input{&val};
+  auto range = input | views::deref();
+
+  EXPECT_THAT(*range.begin(), val);
+}

+ 29 - 0
test/single_test.cxx

@@ -0,0 +1,29 @@
+//
+//  single_test.cxx
+//  stream-test
+//
+//  Created by Sam Jaffe on 4/6/23.
+//
+
+#include "stream/view/single.h"
+
+#include "stream_helpers.h"
+#include "stream_matchers.h"
+
+using testing::Address;
+using testing::Not;
+
+TEST(SingleView, CanBuild) {
+  auto range = views::single(0);
+
+  EXPECT_FALSE(range.empty());
+  EXPECT_THAT(range.size(), 1);
+  EXPECT_THAT(*range.begin(), 0);
+}
+
+TEST(SingleView, CopiesElement) {
+  int value = 0;
+  auto range = views::single(value);
+
+  EXPECT_THAT(*range.begin(), Not(Address(&value)));
+}

+ 0 - 75
test/stream_test.cxx

@@ -1,75 +0,0 @@
-//
-//  stream_td.hpp
-//  stream
-//
-//  Created by Sam Jaffe on 1/28/17.
-//
-
-#include "xcode_gtest_helper.h"
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "stream/streams.hpp"
-
-using ::testing::ElementsAre;
-using ::testing::ElementsAreArray;
-using ::testing::Eq;
-
-namespace views = stream::views;
-namespace ranges = stream::ranges;
-
-TEST(StreamTest, CanBuildFromSingleElement) {
-  int value = 11;
-  auto even = [](int i) { return i % 2 == 0; };
-  auto s = views::single(value) | views::filter(even);
-
-  EXPECT_THAT(ranges::size(s), 0);
-}
-
-TEST(StreamTest, CanBuildFromIterators) {
-  std::vector<int> input{1, 2, 3, 4, 5};
-  std::vector<int> expected{5, 7};
-  auto fmap = [](int i) { return 2 * i + 1; };
-  auto out = ranges::subrange(input.begin() + 1, input.begin() + 3) |
-             views::transform(fmap) | ranges::to_vector();
-
-  EXPECT_THAT(out, Eq(expected));
-}
-
-TEST(StreamTest, CanDereferenceElements) {
-  int val = 5;
-  std::vector<int *> input{&val};
-  auto data = input | views::deref() | ranges::to_vector();
-
-  EXPECT_THAT(data.front(), Eq(val));
-}
-
-TEST(StreamTest, CanForEachConsume) {
-  int hits = 0;
-  std::vector<int> input{1, 2, 3, 4, 5};
-  ranges::for_each(views::all(input), [&hits](int) { ++hits; });
-
-  EXPECT_THAT(hits, Eq(5));
-}
-
-//
-// TEST(StreamTest, CastStreamToParentType) {
-//  struct base {
-//    char cat[4] = "cat";
-//  };
-//  struct test : base {
-//    test(int v) : val(v) {}
-//    int val;
-//  };
-//  std::vector<test> input{{1}, {3}, {2}};
-//
-//  auto addressof_void = [](auto const & p) { return (void *)&p; };
-//
-//  auto strm = stream::of(input).cast<base>();
-//  auto first = stream::of(input).map(addressof_void).collect();
-//  auto second = strm.map(addressof_void).collect();
-//
-//  EXPECT_THAT(first, second);
-//}

+ 18 - 0
test/subrange_test.cxx

@@ -0,0 +1,18 @@
+//
+//  subrange_test.cxx
+//  stream-test
+//
+//  Created by Sam Jaffe on 4/6/23.
+//
+
+#include "stream/view/subrange.h"
+
+#include "stream_helpers.h"
+#include "stream_matchers.h"
+
+TEST(SubrangeView, CanBuildFromIterators) {
+  std::vector<int> input{1, 2, 3, 4, 5};
+  auto range = ranges::subrange(input.begin() + 1, input.begin() + 3);
+
+  EXPECT_THAT(range, RangesEq(std::vector{2, 3}));
+}