<commit_before>/*******************************************************************************
 * tests/api/reduce_node_test.cpp
 *
 * Part of Project c7a.
 *
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 *
 * This file has no license. Only Chuck Norris can compile it.
 ******************************************************************************/

#include <c7a/api/allgather.hpp>
#include <c7a/api/bootstrap.hpp>
#include <c7a/api/dia.hpp>
#include <c7a/api/generate.hpp>
#include <c7a/api/sort.hpp>

#include <gtest/gtest.h>

#include <algorithm>
#include <string>
#include <vector>

using c7a::api::Context;
using c7a::api::DIARef;



TEST(Sort, SortRandomIntegers) {

    std::function<void(Context&)> start_func =
        [](Context& ctx) {

		
		std::random_device random_device;
		std::default_random_engine generator(random_device());
		std::uniform_int_distribution<int> distribution(1, 10000);

		auto integers = Generate(
			ctx,
			[&distribution, &generator](const size_t&) -> int {
				int toret = distribution(generator);
				return toret;
			},
			100);

		auto sorted = integers.Sort();

		std::vector<int> out_vec;

		sorted.AllGather(&out_vec);

		for (size_t i = 0; i < out_vec.size() - 1; i++) {
			ASSERT_FALSE(out_vec[i + 1] < out_vec[i]);
		}

		ASSERT_EQ(100u, out_vec.size());
	};

	c7a::api::ExecuteLocalTests(start_func);
}

TEST(Sort, SortRandomIntegersCustomCompareFunction) {

    std::function<void(Context&)> start_func =
        [](Context& ctx) {

		
		std::random_device random_device;
		std::default_random_engine generator(random_device());
		std::uniform_int_distribution<int> distribution(1, 10000);

		auto integers = Generate(
			ctx,
			[&distribution, &generator](const size_t&) -> int {
				int toret = distribution(generator);
				return toret;
			},
			100);

		auto compare_fn = [](int in1, int in2) {
			return in1 > in2;
		};

		auto sorted = integers.Sort(compare_fn);

		std::vector<int> out_vec;

		sorted.AllGather(&out_vec);

		for (size_t i = 0; i < out_vec.size() - 1; i++) {
			ASSERT_FALSE(out_vec[i + 1] > out_vec[i]);
		}

		ASSERT_EQ(100u, out_vec.size());
	};

	c7a::api::ExecuteLocalTests(start_func);
}

TEST(Sort, SortRandomIntIntStructs) {

    std::function<void(Context&)> start_func =
        [](Context& ctx) {

		using Pair = std::pair<int, int>;

		std::random_device random_device;
		std::default_random_engine generator(random_device());
		std::uniform_int_distribution<int> distribution(1, 10);

		auto integers = Generate(
			ctx,
			[&distribution, &generator](const size_t&) -> Pair {
				int ele1 = distribution(generator);
				int ele2 = distribution(generator);
				return std::make_pair(ele1, ele2);
			},<commit_msg>add test with known integers<commit_after>/*******************************************************************************
 * tests/api/reduce_node_test.cpp
 *
 * Part of Project c7a.
 *
 * Copyright (C) 2015 <NAME> <<EMAIL>>
 *
 * This file has no license. Only Chuck Norris can compile it.
 ******************************************************************************/

#include <c7a/api/allgather.hpp>
#include <c7a/api/bootstrap.hpp>
#include <c7a/api/dia.hpp>
#include <c7a/api/generate.hpp>
#include <c7a/api/sort.hpp>

#include <gtest/gtest.h>

#include <algorithm>
#include <string>
#include <vector>

using c7a::api::Context;
using c7a::api::DIARef;

TEST(Sort, SortKnownIntegers) {

    std::function<void(Context&)> start_func =
        [](Context& ctx) {

		
		std::random_device random_device;
		std::default_random_engine generator(random_device());
		std::uniform_int_distribution<int> distribution(1, 10000);

		auto integers = Generate(
			ctx,
			[](const size_t& index) -> int {
				return index;
			},
			100);

		auto sorted = integers.Sort();

		std::vector<int> out_vec;

		sorted.AllGather(&out_vec);

		for (size_t i = 0; i < out_vec.size() - 1; i++) {
			ASSERT_EQ((int) i, out_vec[i]);
		}

		ASSERT_EQ(100u, out_vec.size());
	};

	c7a::api::ExecuteLocalTests(start_func);
}

TEST(Sort, SortRandomIntegers) {

    std::function<void(Context&)> start_func =
        [](Context& ctx) {

		
		std::random_device random_device;
		std::default_random_engine generator(random_device());
		std::uniform_int_distribution<int> distribution(1, 10000);

		auto integers = Generate(
			ctx,
			[&distribution, &generator](const size_t&) -> int {
				return distribution(generator);
			},
			100);

		auto sorted = integers.Sort();

		std::vector<int> out_vec;

		sorted.AllGather(&out_vec);

		for (size_t i = 0; i < out_vec.size() - 1; i++) {
			ASSERT_FALSE(out_vec[i + 1] < out_vec[i]);
		}

		ASSERT_EQ(100u, out_vec.size());
	};

	c7a::api::ExecuteLocalTests(start_func);
}

TEST(Sort, SortRandomIntegersCustomCompareFunction) {

    std::function<void(Context&)> start_func =
        [](Context& ctx) {

		
		std::random_device random_device;
		std::default_random_engine generator(random_device());
		std::uniform_int_distribution<int> distribution(1, 10000);

		auto integers = Generate(
			ctx,
			[&distribution, &generator](const size_t&) -> int {
				return distribution(generator);
			},
			100);

		auto compare_fn = [](int in1, int in2) {
			return in1 > in2;
		};

		auto sorted = integers.Sort(compare_fn);

		std::vector<int> out_vec;

		sorted.AllGather(&out_vec);

		for (size_t i = 0; i < out_vec.size() - 1; i++) {
			ASSERT_FALSE(out_vec[i + 1] > out_vec[i]);
		}

		ASSERT_EQ(100u, out_vec.size());
	};

	c7a::api::ExecuteLocalTests(start_func);
}

TEST(Sort, SortRandomIntIntStructs) {

    std::function<void(Context&)> start_func =
        [](Context& ctx) {

		using Pair = std::pair<int, int>;

		std::random_device random_device;
		std::default_random_engine generator(random_device());
		std::uniform_int_distribution<int> distribution(1, 10);

		auto integers = Generate(
			ctx,
			[&distribution, &generator](const size_t&) -> Pair {
				return std::make_pair(distribution(generator), distribution(generator));
			},
{'fraction_non_alphanumeric': 0.20046932618169627, 'fraction_numerical': 0.020281595709017768, 'mean_word_length': 4.555865921787709, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 59, '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': '6692054', 'n_tokens_mistral': 2361, 'n_tokens_neox': 2006, 'n_words': 398}