Skip to content
Snippets Groups Projects
Select Git revision
  • e826dd7e642f56c84a5dffb6398ec4b0f2dea68e
  • master default protected
  • github/fork/hrani/master
  • github/fork/dilawar/master
  • chamcham
  • chhennapoda
  • wheel
  • 3.2.0-pre0
  • v3.1.3
  • 3.1.2
  • 3.1.1
  • chamcham-3.1.1
  • 3.1.0
  • ghevar_3.0.2_pre2
  • ghevar_3.0.2
15 results

Ksolve.h

  • test_range.cpp 11.77 KiB
    #include "gtest.h"
    
    #include <algorithm>
    #include <iterator>
    #include <sstream>
    #include <list>
    #include <numeric>
    #include <type_traits>
    
    #ifdef WITH_TBB
    #include <tbb/tbb_stddef.h>
    #endif
    
    #include <util/counter.hpp>
    #include <util/meta.hpp>
    #include <util/range.hpp>
    #include <util/rangeutil.hpp>
    #include <util/sentinel.hpp>
    #include <util/transform.hpp>
    
    using namespace nest::mc;
    
    TEST(range, list_iterator) {
        std::list<int> l = { 2, 4, 6, 8, 10 };
    
        auto s  = util::make_range(l.begin(), l.end());
    
        EXPECT_EQ(s.left, l.begin());
        EXPECT_EQ(s.right, l.end());
    
        EXPECT_EQ(s.begin(), l.begin());
        EXPECT_EQ(s.end(), l.end());
    
        EXPECT_EQ(s.size(), l.size());
        EXPECT_EQ(s.front(), *l.begin());
        EXPECT_EQ(s.back(), *std::prev(l.end()));
    
        int check = std::accumulate(l.begin(), l.end(), 0);
        int sum = 0;
        for (auto i: s) {
            sum += i;
        }
    
        EXPECT_EQ(check, sum);
    
        auto sum2 = std::accumulate(s.begin(), s.end(), 0);
        EXPECT_EQ(check, sum2);
    
        // Check that different begin/end iterators are treated correctly
        auto sc = util::make_range(l.begin(), l.cend());
        EXPECT_EQ(l.size(), sc.size());
    }
    
    TEST(range, pointer) {
        int xs[] = { 10, 11, 12, 13, 14, 15, 16 };
        int l = 2;
        int r = 5;
    
        util::range<int *> s(&xs[l], &xs[r]);
        auto s_deduced = util::make_range(xs+l, xs+r);
    
        EXPECT_TRUE((std::is_same<decltype(s), decltype(s_deduced)>::value));
        EXPECT_EQ(s.left, s_deduced.left);
        EXPECT_EQ(s.right, s_deduced.right);
    
        EXPECT_EQ(3u, s.size());
    
        EXPECT_EQ(xs[l], *s.left);
        EXPECT_EQ(xs[l], *s.begin());
        EXPECT_EQ(xs[l], s[0]);