<commit_before>#include <tuple>
#include <type_traits>
#include <utility>
#include <nek/utility/pointer_traits.hpp>
#include <gtest/gtest.h>

namespace
{
  template <class T>
  class complete_smart_pointer_mock
  {
  private:
    T* ptr_ = nullptr;

  public:
    using element_type = T;
    using difference_type = char;

    complete_smart_pointer_mock() = default;

    explicit complete_smart_pointer_mock(T& p)
      : ptr_(&p)
    {
    }

    template <class U>
    struct rebind
    {
      using other = complete_smart_pointer_mock<U>;
    };

    static complete_smart_pointer_mock pointer_to(T& p)
    {
      return complete_smart_pointer_mock(p);
    }

    friend bool operator==(complete_smart_pointer_mock const& l, complete_smart_pointer_mock const& r)
    {
      return l.ptr_ == r.ptr_;
    }
  };

  template <class T>
  class simple_smart_pointer_mock
  {
  private:
    T* ptr_ = nullptr;

  public:
    simple_smart_pointer_mock() = default;

    simple_smart_pointer_mock(T* p)
      : ptr_(p)
    {
    }

    friend bool operator==(simple_smart_pointer_mock const& l, simple_smart_pointer_mock const& r)
    {
      return l.ptr_ == r.ptr_;
    }
  };
}

template <class T>
class pointer_traits_test
  : public ::testing::Test
{
protected:
  using ptr_t = typename std::tuple_element<0, T>::type;
  using elem_t = typename std::tuple_element<1, T>::type;
  using diff_t = typename std::tuple_element<2, T>::type;
  using pointer_t = typename std::tuple_element<3, T>::type;
};

TYPED_TEST_CASE_P(pointer_traits_test);

TYPED_TEST_P(pointer_traits_test, element_type)
{
  using actual_t = typename nek::pointer_traits<ptr_t>::element_type;
  static_assert(std::is_same<actual_t, elem_t>::value, "");
}

TYPED_TEST_P(pointer_traits_test, difference_type)
{
  using actual_t = typename nek::pointer_traits<ptr_t>::difference_type;
  static_assert(std::is_same<actual_t, diff_t>::value, "");
}

TYPED_TEST_P(pointer_traits_test, pointer)
{
  using actual_t = typename nek::pointer_traits<ptr_t>::pointer;
  static_assert(std::is_same<actual_t, pointer_t>::value, "");
}

TYPED_TEST_P(pointer_traits_test, rebind)
{
  using actual_t = typename nek::pointer_traits<ptr_t>::template rebind<double>::other;
  using expect_t = typename std::tuple_element<4, TypeParam>::type;
  static_assert(std::is_same<actual_t, expect_t>::value, "");
}

TEST(pointer_to_test, raw_type)
{
  int val = 0;
  EXPECT_EQ(&val, nek::pointer_traits<int*>::pointer_to(val));
}

TEST(pointer_to_test, complete_smart_ptr)
{
  int val = 0;
  EXPECT_EQ(complete_smart_pointer_mock<int>(val), nek::pointer_traits<complete_smart_pointer_mock<int>>::pointer_to(val));
}

TEST(pointer_to_test, simple_smart_pointer)
{
  // when pointer does not provide a static member function pointer_to,
  // instantiation of this function must be  a compile-time error.
  //int val = 0;
  //EXPECT_EQ(simple_smart_pointer_mock<int>(&val), nek::pointer_traits<simple_smart_pointer_mock<int>>::pointer_to(val));
}

REGISTER_TYPED_TEST_CASE_P(
  pointer_traits_test,
  element_type,
  difference_type,
  pointer,
  rebind);

using types = ::testing::Types<
  //        <pointer_type,                     element_type, difference_type, pointer,                          rebind<double>::other,
  std::tuple<int*,                             int,          std::ptrdiff_t,  int*,                             double*>,
  std::tuple<complete_smart_pointer_mock<int>, int,          char,            complete_smart_pointer_mock<int>, complete_smart_pointer_mock<double>>,
  std::tuple<simple_smart_pointer_mock<int>,   int,          std::ptrdiff_t,  simple_smart_pointer_mock<int>,   simple_smart_pointer_mock<double>>
>;

INSTANTIATE_TYPED_TEST_CASE_P(parameterized, pointer_traits_test, types);<commit_msg>fix typo<commit_after>#include <tuple>
#include <type_traits>
#include <utility>
#include <nek/utility/pointer_traits.hpp>
#include <gtest/gtest.h>

namespace
{
  template <class T>
  class complete_smart_pointer_mock
  {
  private:
    T* ptr_ = nullptr;

  public:
    using element_type = T;
    using difference_type = char;

    complete_smart_pointer_mock() = default;

    explicit complete_smart_pointer_mock(T& p)
      : ptr_(&p)
    {
    }

    template <class U>
    struct rebind
    {
      using other = complete_smart_pointer_mock<U>;
    };

    static complete_smart_pointer_mock pointer_to(T& p)
    {
      return complete_smart_pointer_mock(p);
    }

    friend bool operator==(complete_smart_pointer_mock const& l, complete_smart_pointer_mock const& r)
    {
      return l.ptr_ == r.ptr_;
    }
  };

  template <class T>
  class simple_smart_pointer_mock
  {
  private:
    T* ptr_ = nullptr;

  public:
    simple_smart_pointer_mock() = default;

    simple_smart_pointer_mock(T* p)
      : ptr_(p)
    {
    }

    friend bool operator==(simple_smart_pointer_mock const& l, simple_smart_pointer_mock const& r)
    {
      return l.ptr_ == r.ptr_;
    }
  };
}

template <class T>
class pointer_traits_test
  : public ::testing::Test
{
protected:
  using ptr_t = typename std::tuple_element<0, T>::type;
  using elem_t = typename std::tuple_element<1, T>::type;
  using diff_t = typename std::tuple_element<2, T>::type;
  using pointer_t = typename std::tuple_element<3, T>::type;
};

TYPED_TEST_CASE_P(pointer_traits_test);

TYPED_TEST_P(pointer_traits_test, element_type)
{
  using actual_t = typename nek::pointer_traits<ptr_t>::element_type;
  static_assert(std::is_same<actual_t, elem_t>::value, "");
}

TYPED_TEST_P(pointer_traits_test, difference_type)
{
  using actual_t = typename nek::pointer_traits<ptr_t>::difference_type;
  static_assert(std::is_same<actual_t, diff_t>::value, "");
}

TYPED_TEST_P(pointer_traits_test, pointer)
{
  using actual_t = typename nek::pointer_traits<ptr_t>::pointer;
  static_assert(std::is_same<actual_t, pointer_t>::value, "");
}

TYPED_TEST_P(pointer_traits_test, rebind)
{
  using actual_t = typename nek::pointer_traits<ptr_t>::template rebind<double>::other;
  using expect_t = typename std::tuple_element<4, TypeParam>::type;
  static_assert(std::is_same<actual_t, expect_t>::value, "");
}

TEST(pointer_to_test, raw_type)
{
  int val = 0;
  EXPECT_EQ(&val, nek::pointer_traits<int*>::pointer_to(val));
}

TEST(pointer_to_test, complete_smart_ptr)
{
  int val = 0;
  EXPECT_EQ(complete_smart_pointer_mock<int>(val), nek::pointer_traits<complete_smart_pointer_mock<int>>::pointer_to(val));
}

TEST(pointer_to_test, simple_smart_pointer)
{
  // when smart pointer does not provide a static member function pointer_to,
  // instantiation of this function must be a compile-time error.
  //int val = 0;
  //EXPECT_EQ(simple_smart_pointer_mock<int>(&val), nek::pointer_traits<simple_smart_pointer_mock<int>>::pointer_to(val));
}

REGISTER_TYPED_TEST_CASE_P(
  pointer_traits_test,
  element_type,
  difference_type,
  pointer,
  rebind);

using types = ::testing::Types<
  //        <pointer_type,                     element_type, difference_type, pointer,                          rebind<double>::other,
  std::tuple<int*,                             int,          std::ptrdiff_t,  int*,                             double*>,
  std::tuple<complete_smart_pointer_mock<int>, int,          char,            complete_smart_pointer_mock<int>, complete_smart_pointer_mock<double>>,
  std::tuple<simple_smart_pointer_mock<int>,   int,          std::ptrdiff_t,  simple_smart_pointer_mock<int>,   simple_smart_pointer_mock<double>>
>;

INSTANTIATE_TYPED_TEST_CASE_P(parameterized, pointer_traits_test, types);
{'fraction_non_alphanumeric': 0.11823966065747614, 'fraction_numerical': 0.0021208907741251328, 'mean_word_length': 4.320874471086037, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3839857', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2596, 'n_words': 447}