<commit_before>#include "gtest/gtest.h"
#include "Rand.h"

TEST(RandTest, RandNotAlwaysZero)
{
	Rand r1;
	int bit_sum = 0;
	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		bit_sum += r1.randbit();
	}
	EXPECT_LT(0, bit_sum);
}

TEST(RandTest, RandNotAlwaysOne)
{
	Rand r1;
	int bit_sum = 0;
	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		bit_sum += r1.randbit();
	}
	EXPECT_GT(iters, bit_sum);
}

TEST(RandTest, HalfBitsAreOne)
{
	Rand r1;
	int iters = 10000;
	int bit_sum = 0;

	for(int i = 0; i < iters; i++)
	{
		bit_sum += r1.randbit();
	}

	//Give ourselves a range to allow +/- the exact mean
	int low = iters * 2 / 5;
	int high = iters * 3 / 5;

	EXPECT_LE(low, bit_sum);
	EXPECT_GE(high, bit_sum);
}

TEST(RandTest, SameSeedsAreEqual)
{
	Rand r1(0xACE01u);
	Rand r2(0xACE01u);

	int iters = 10000;
	int equal = 1;
	
	for(int i = 0; i < iters; i++)
	{
		equal &= r1.randbit() == r2.randbit();
	}

	EXPECT_EQ(1, equal);
}

TEST(RandTest, DifferentSeedsAreNotEqual)
{
	Rand r1(0xACE01u);
	Rand r2(0x10ECAu);

	int iters = 10000;
	int equal = 1;
	
	for(int i = 0; i < iters; i++)
	{
		equal &= r1.randbit() == r2.randbit();
	}

	EXPECT_NE(1, equal);
}

TEST(RandTest, GetNBits)
{
	Rand r1;

	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		ASSERT_GE(0xFF, r1.randn(8));
	}
}

TEST(RandTest, 8BitsEqual)
{
	Rand r1(0xACE01u);
	Rand r2(0xACE01u);

	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		ASSERT_EQ(r1.rand8(), r2.randn(8));
	}
}

TEST(RandTest, 16BitsEqual)
{
	Rand r1(0xACE01u);
	Rand r2(0xACE01u);

	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		ASSERT_EQ(r1.rand16(), r2.randn(16));
	}
}

TEST(RandTest, 32BitsEqual)
{
	Rand r1(0xACE01u);
	Rand r2(0xACE01u);

	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		ASSERT_EQ(r1.rand32(), r2.randn(32));
	}
}


int main(int argc, char **argv)
{
	::testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
}
<commit_msg>New unit tests for Rand::randn() method to ensure it's returning values<commit_after>#include "gtest/gtest.h"
#include "Rand.h"

TEST(RandTest, RandNotAlwaysZero)
{
	Rand r1;
	int bit_sum = 0;
	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		bit_sum += r1.randbit();
	}
	EXPECT_LT(0, bit_sum);
}

TEST(RandTest, RandNotAlwaysOne)
{
	Rand r1;
	int bit_sum = 0;
	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		bit_sum += r1.randbit();
	}
	EXPECT_GT(iters, bit_sum);
}

TEST(RandTest, HalfBitsAreOne)
{
	Rand r1;
	int iters = 10000;
	int bit_sum = 0;

	for(int i = 0; i < iters; i++)
	{
		bit_sum += r1.randbit();
	}

	//Give ourselves a range to allow +/- the exact mean
	int low = iters * 2 / 5;
	int high = iters * 3 / 5;

	EXPECT_LE(low, bit_sum);
	EXPECT_GE(high, bit_sum);
}

TEST(RandTest, SameSeedsAreEqual)
{
	Rand r1(0xACE01u);
	Rand r2(0xACE01u);

	int iters = 10000;
	int equal = 1;
	
	for(int i = 0; i < iters; i++)
	{
		equal &= r1.randbit() == r2.randbit();
	}

	EXPECT_EQ(1, equal);
}

TEST(RandTest, DifferentSeedsAreNotEqual)
{
	Rand r1(0xACE01u);
	Rand r2(0x10ECAu);

	int iters = 10000;
	int equal = 1;
	
	for(int i = 0; i < iters; i++)
	{
		equal &= r1.randbit() == r2.randbit();
	}

	EXPECT_NE(1, equal);
}

TEST(RandTest, GetNBits)
{
	Rand r1;

	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		ASSERT_GE(0xFF, r1.randn(8));
	}
}

TEST(RandTest, RandNNotAlwaysZero)
{
	Rand r1;
	int bit_sum = 0;
	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		bit_sum += r1.randn(8);
	}
	EXPECT_LT(0, bit_sum);
}

TEST(RandTest, RandNNotAlwaysMax)
{
	Rand r1;
	int bit_sum = 0;
	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		bit_sum += r1.randn(8);
	}
	EXPECT_GT(iters * 0xFF, bit_sum);
}

TEST(RandTest, 8BitsEqual)
{
	Rand r1(0xACE01u);
	Rand r2(0xACE01u);

	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		ASSERT_EQ(r1.rand8(), r2.randn(8));
	}
}

TEST(RandTest, 16BitsEqual)
{
	Rand r1(0xACE01u);
	Rand r2(0xACE01u);

	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		ASSERT_EQ(r1.rand16(), r2.randn(16));
	}
}

TEST(RandTest, 32BitsEqual)
{
	Rand r1(0xACE01u);
	Rand r2(0xACE01u);

	int iters = 1000;

	for(int i = 0; i < iters; i++)
	{
		ASSERT_EQ(r1.rand32(), r2.randn(32));
	}
}


int main(int argc, char **argv)
{
	::testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
}

{'fraction_non_alphanumeric': 0.17498833411105927, 'fraction_numerical': 0.06766215585627625, 'mean_word_length': 3.4984260230849946, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 3, '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': '2447711', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2049, 'n_words': 463}