<commit_before>// Copyright (c) 2014, 2015 <NAME>
// This code is distributed under the MIT license. See LICENSE for details.

#pragma once

#include "arbitrary.h"
#include "test.h"

#include <cstddef>
#include <limits>
#include <random>

namespace testinator
{

  namespace detail
  {
    template <typename T>
    struct Arbitrary_Arithmetic
    {
      static T generate(std::size_t generation, unsigned long int randomSeed)
      {
        switch (generation)
        {
          case 0:
            return 0;
          case 1:
            return std::numeric_limits<T>::min();
          case 2:
            return std::numeric_limits<T>::max();

          default:
          {
            std::mt19937& gen = testinator::GetTestRegistry().RNG();
            gen.seed(randomSeed);
            std::uniform_int_distribution<T> dis(
                std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
            return dis(gen);
          }
        }
      }

      static T generate_n(std::size_t n, unsigned long int randomSeed)
      {
        return generate(n, randomSeed);
      }

      static std::vector<T> shrink(const T&)
      {
        return std::vector<T>();
      }
    };

    template <typename T>
    struct Arbitrary_Arithmetic_IntCast
    {
      static T generate(std::size_t generation, unsigned long int randomSeed)
      {
        switch (generation)
        {
          case 0:
            return 0;
          case 1:
            return std::numeric_limits<T>::min();
          case 2:
            return std::numeric_limits<T>::max();

          default:
          {
            std::mt19937& gen = testinator::GetTestRegistry().RNG();
            gen.seed(randomSeed);
            std::uniform_int_distribution<int> dis(
                std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
            return static_cast<T>(dis(gen));
          }
        }
      }

      static T generate_n(std::size_t n, unsigned long int randomSeed)
      {
        return generate(n, randomSeed);
      }

      static std::vector<T> shrink(const T&)
      {
        return std::vector<T>();
      }
    };

    template <typename T>
    struct Arbitrary_Arithmetic_Real
    {
      static T generate(std::size_t generation, unsigned long int randomSeed)
      {
        switch (generation)
        {
          case 0:
            return 0;
          case 1:
            return std::numeric_limits<T>::min();
          case 2:
            return std::numeric_limits<T>::max();

          default:
          {
            std::mt19937& gen = testinator::GetTestRegistry().RNG();
            gen.seed(randomSeed);
            std::uniform_real_distribution<T> dis(
                std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
            return dis(gen);
          }
        }
      }

      static T generate_n(std::size_t n, unsigned long int randomSeed)
      {
        return generate(n, randomSeed);
      }

      static std::vector<T> shrink(const T&)
      {
        return std::vector<T>();
      }
    };

  }

  //------------------------------------------------------------------------------
  // specializations for arithmetic types
  //------------------------------------------------------------------------------<commit_msg>Improve correctness of random use<commit_after>// Copyright (c) 2014, 2015 <NAME>
// This code is distributed under the MIT license. See LICENSE for details.

#pragma once

#include "arbitrary.h"
#include "test.h"

#include <cstddef>
#include <limits>
#include <random>

namespace testinator
{

  namespace detail
  {
    template <typename T>
    struct Arbitrary_Arithmetic
    {
      static T generate(std::size_t generation, unsigned long int randomSeed)
      {
        switch (generation)
        {
          case 0:
            return 0;
          case 1:
            return std::numeric_limits<T>::min();
          case 2:
            return std::numeric_limits<T>::max();

          default:
          {
            std::mt19937& gen = testinator::GetTestRegistry().RNG();
            gen.seed(randomSeed);
            std::uniform_int_distribution<T> dis(
                std::numeric_limits<T>::min() + 1, std::numeric_limits<T>::max() - 1);
            return dis(gen);
          }
        }
      }

      static T generate_n(std::size_t n, unsigned long int randomSeed)
      {
        return generate(n, randomSeed);
      }

      static std::vector<T> shrink(const T&)
      {
        return std::vector<T>();
      }
    };

    template <typename T>
    struct Arbitrary_Arithmetic_IntCast
    {
      static T generate(std::size_t generation, unsigned long int randomSeed)
      {
        switch (generation)
        {
          case 0:
            return 0;
          case 1:
            return std::numeric_limits<T>::min();
          case 2:
            return std::numeric_limits<T>::max();

          default:
          {
            std::mt19937& gen = testinator::GetTestRegistry().RNG();
            gen.seed(randomSeed);
            std::uniform_int_distribution<int> dis(
                std::numeric_limits<T>::min() + 1, std::numeric_limits<T>::max() - 1);
            return static_cast<T>(dis(gen));
          }
        }
      }

      static T generate_n(std::size_t n, unsigned long int randomSeed)
      {
        return generate(n, randomSeed);
      }

      static std::vector<T> shrink(const T&)
      {
        return std::vector<T>();
      }
    };

    template <typename T>
    struct Arbitrary_Arithmetic_Real
    {
      static T generate(std::size_t generation, unsigned long int randomSeed)
      {
        switch (generation)
        {
          case 0:
            return 0;
          case 1:
            return std::numeric_limits<T>::min();
          case 2:
            return std::numeric_limits<T>::max();
          case 3:
            return std::numeric_limits<T>::lowest();

          default:
          {
            std::mt19937& gen = testinator::GetTestRegistry().RNG();
            gen.seed(randomSeed);
            std::uniform_real_distribution<T> dis(
                std::numeric_limits<T>::lowest(), std::numeric_limits<T>::max());
            return dis(gen);
          }
        }
      }

      static T generate_n(std::size_t n, unsigned long int randomSeed)
      {
        return generate(n, randomSeed);
      }

      static std::vector<T> shrink(const T&)
      {
        return std::vector<T>();
      }
    };

  }

  //------------------------------------------------------------------------------
  // specializations for arithmetic types
  //------------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.16144434497165025, 'fraction_numerical': 0.011190689346463742, 'mean_word_length': 1.6091864538731024, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 62, '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': '5648847', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1825, 'n_words': 418}