<commit_before><commit_msg>Test primesieve_next_prime()<commit_after>///
/// @file   next_prime1.cpp
/// @brief  Test primesieve_next_prime().
///
/// Copyright (C) 2017 <NAME>, <<EMAIL>>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#include <primesieve.h>

#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>

void check(int OK)
{
  if (OK)
    printf("   OK\n");
  else
  {
    printf("   ERROR\n");
    exit(1);
  }
}

int main()
{
  size_t size = 0;
  uint64_t* primes = (uint64_t*) primesieve_generate_primes(0, 100000, &size, UINT64_PRIMES);
  primesieve_iterator it;
  primesieve_init(&it);

  uint64_t i;
  uint64_t prime;
  uint64_t max_prime = primes[size - 1];
  uint64_t sum = 0;

  for (i = 0; i < size - i; i++)
  {
    primesieve_skipto(&it, primes[i] - 1, max_prime);
    prime = primesieve_next_prime(&it);
    printf("next_prime(%" PRIu64 ") = %" PRIu64, primes[i] - 1, prime);
    check(prime == primes[i]);

    primesieve_skipto(&it, primes[i], max_prime);
    prime = primesieve_next_prime(&it);
    printf("next_prime(%" PRIu64 ") = %" PRIu64, primes[i], prime);
    check(prime == primes[i + 1]);
  }

  primesieve_skipto(&it, 0, max_prime);

  // iterate over the primes below 10^9
  while ((prime = primesieve_next_prime(&it)) < 1000000000)
    sum += prime;

  printf("Sum of the primes below 10^9 = %" PRIu64, sum);
  check(sum == 24739512092254535ull);

  primesieve_skipto(&it, 18446744073709551533ull, 0);
  prime = primesieve_next_prime(&it);
  printf("next_prime(%" PRIu64 ") = %" PRIu64, 18446744073709551533ull, prime);
  check(prime == 18446744073709551557ull);

  prime = primesieve_next_prime(&it);
  printf("next_prime(%" PRIu64 ") = %" PRIu64, 18446744073709551533ull, prime);
  check(prime == 18446744073709551615ull);

  primesieve_free(primes);
  primesieve_free_iterator(&it);

  printf("\n");
  printf("All tests passed successfully!\n");

  return 0;
}
{'fraction_non_alphanumeric': 0.16182364729458917, 'fraction_numerical': 0.09418837675350701, 'mean_word_length': 4.005012531328321, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '4289548', 'n_tokens_mistral': 916, 'n_tokens_neox': 762, 'n_words': 165}