<commit_before>#include "tpunit++.hpp"
#include "fakeit.h"
#include <string>
#include "fakeit/Exceptions.h"
#include <queue>

struct BasicStubbing: tpunit::TestFixture {
	BasicStubbing() :
			tpunit::TestFixture(
					//
					TEST(BasicStubbing::calling_an_unstubbed_method_should_raise_UnmockedMethodCallException), //
					TEST(BasicStubbing::stub_method_to_default_behaviore), //
					TEST(BasicStubbing::stub_multiple_methods_to_default_behaviore),
					TEST(BasicStubbing::stub_a_function_to_return_a_specified_value),
					TEST(BasicStubbing::stub_a_method_to_throw_a_specified_exception), //
					TEST(BasicStubbing::stub_a_method_with_lambda_delegate), //
					TEST(BasicStubbing::stub_a_method_with_static_method_delegate), //
					TEST(BasicStubbing::stub_by_assignment_with_lambda_delegate), //
					TEST(BasicStubbing::stub_by_assignment_with_static_method_delegate), //
					TEST(BasicStubbing::stub_to_default_behavior_with_filter), //
					TEST(BasicStubbing::change_method_behavior_with_filter), //
					TEST(BasicStubbing::change_method_behavior_with_functor_filter), //
					TEST(BasicStubbing::change_method_behavior_with_matcher),  //
					TEST(BasicStubbing::change_method_behavior_with_functor_matcher),  //
					TEST(BasicStubbing::stub_multiple_return_values), //
					TEST(BasicStubbing::stub_multiple_return_values_using_quque), //
					TEST(BasicStubbing::stub_multiple_throws)
					//
							) {
	}

	struct SomeInterface {
		virtual int func(int) = 0;
		virtual void proc(int) = 0;
	};

	void calling_an_unstubbed_method_should_raise_UnmockedMethodCallException() {
		Mock<SomeInterface> mock;
		SomeInterface &i = mock.get();
		ASSERT_THROW(i.func(1), UnmockedMethodCallException);
		ASSERT_THROW(i.proc(1), UnmockedMethodCallException);
	}

	void stub_method_to_default_behaviore() {
		Mock<SomeInterface> mock;

		Stub(mock[&SomeInterface::func]);
		Stub(mock[&SomeInterface::proc]);

		SomeInterface &i = mock.get();

		ASSERT_EQUAL(0, i.func(1));
		ASSERT_NO_THROW(i.proc(1));
	}

	void stub_multiple_methods_to_default_behaviore() {
		Mock<SomeInterface> mock;

		Stub(mock[&SomeInterface::func], mock[&SomeInterface::proc]);

		SomeInterface &i = mock.get();

		ASSERT_EQUAL(0, i.func(1));
		ASSERT_NO_THROW(i.proc(1));
	}

	void stub_a_function_to_return_a_specified_value() {
		Mock<SomeInterface> mock;

		When(mock[&SomeInterface::func]).Return(1);

		SomeInterface &i = mock.get();

		ASSERT_EQUAL(1, i.func(1));
	}

	void stub_a_method_to_throw_a_specified_exception() {
		Mock<SomeInterface> mock;

		When(mock[&SomeInterface::func]).Throw(std::string("func exception"));
		When(mock[&SomeInterface::proc]).Throw(std::string("proc exception"));

		SomeInterface &i = mock.get();

		try {
			i.func(1);
		} catch (std::string e) {
			ASSERT_EQUAL(std::string("func exception"), e);
		}

		try {
			i.proc(1);
		} catch (std::string e) {
			ASSERT_EQUAL(std::string("proc exception"), e);
		}
	}
//
	void stub_a_method_with_lambda_delegate() {
		Mock<SomeInterface> mock;

		int a = 0;

		When(mock[&SomeInterface::func]).Do([](int val) {return val;});
		When(mock[&SomeInterface::proc]).Do([&a](int val) {a = val;});

		SomeInterface &i = mock.get();

		ASSERT_EQUAL(3, i.func(3));

		i.proc(3);
		ASSERT_EQUAL(3, a);
	}

	static int func_delegate(int val) {<commit_msg>add unit tests<commit_after>#include "tpunit++.hpp"
#include "fakeit.h"
#include <string>
#include "fakeit/Exceptions.h"
#include <queue>

struct BasicStubbing: tpunit::TestFixture {
	BasicStubbing() :
			tpunit::TestFixture(
					//
					TEST(BasicStubbing::calling_an_unstubbed_method_should_raise_UnmockedMethodCallException), //
					TEST(BasicStubbing::stub_method_to_default_behaviore_will_always_return_do_the_default_behaviore), //
					TEST(BasicStubbing::stub_multiple_methods_to_default_behaviore),
					TEST(BasicStubbing::stub_a_function_to_return_a_specified_value_once),
					TEST(BasicStubbing::stub_a_function_to_return_a_specified_value_always),
					TEST(BasicStubbing::stub_a_method_to_throw_a_specified_exception_once), //
					TEST(BasicStubbing::stub_a_method_with_lambda_delegate_once), //
					TEST(BasicStubbing::stub_a_method_with_lambda_delegate_always), //
					TEST(BasicStubbing::stub_a_method_with_static_method_delegate), //
					TEST(BasicStubbing::stub_by_assignment_with_lambda_delegate), //
					TEST(BasicStubbing::stub_by_assignment_with_static_method_delegate), //
					TEST(BasicStubbing::stub_to_default_behavior_with_filter), //
					TEST(BasicStubbing::change_method_behavior_with_filter), //
					TEST(BasicStubbing::change_method_behavior_with_functor_filter), //
					TEST(BasicStubbing::change_method_behavior_with_matcher),  //
					TEST(BasicStubbing::change_method_behavior_with_functor_matcher),  //
					TEST(BasicStubbing::stub_multiple_return_values), //
					TEST(BasicStubbing::stub_multiple_return_values_using_quque), //
					TEST(BasicStubbing::stub_multiple_throws)
					//
							) {
	}

	struct SomeInterface {
		virtual int func(int) = 0;
		virtual void proc(int) = 0;
	};

	void calling_an_unstubbed_method_should_raise_UnmockedMethodCallException() {
		Mock<SomeInterface> mock;
		SomeInterface &i = mock.get();
		ASSERT_THROW(i.func(1), UnmockedMethodCallException);
		ASSERT_THROW(i.proc(1), UnmockedMethodCallException);
	}

	void stub_method_to_default_behaviore_will_always_return_do_the_default_behaviore() {
		Mock<SomeInterface> mock;

		Stub(mock[&SomeInterface::func]);
		Stub(mock[&SomeInterface::proc]);

		SomeInterface &i = mock.get();

		ASSERT_EQUAL(0, i.func(1));
		ASSERT_NO_THROW(i.proc(1));

		ASSERT_EQUAL(0, i.func(1));
		ASSERT_NO_THROW(i.proc(1));
	}

	void stub_multiple_methods_to_default_behaviore() {
		Mock<SomeInterface> mock;

		Stub(mock[&SomeInterface::func], mock[&SomeInterface::proc]);

		SomeInterface &i = mock.get();

		ASSERT_EQUAL(0, i.func(1));
		ASSERT_NO_THROW(i.proc(1));

		ASSERT_EQUAL(0, i.func(1));
		ASSERT_NO_THROW(i.proc(1));
	}

	void stub_a_function_to_return_a_specified_value_once() {
		Mock<SomeInterface> mock;

		When(mock[&SomeInterface::func]).Return(1);

		SomeInterface &i = mock.get();

		ASSERT_EQUAL(1, i.func(1));
		ASSERT_THROW(i.func(1), fakeit::UnmockedMethodCallException);

	}

	void stub_a_function_to_return_a_specified_value_always() {
		Mock<SomeInterface> mock;

		When(mock[&SomeInterface::func]).AlwaysReturn(1);

		SomeInterface &i = mock.get();

		ASSERT_EQUAL(1, i.func(1));
		ASSERT_EQUAL(1, i.func(1));
	}


	void stub_a_method_to_throw_a_specified_exception_once() {
		Mock<SomeInterface> mock;

		When(mock[&SomeInterface::func]).Throw(std::string("func exception"));
		When(mock[&SomeInterface::proc]).Throw(std::string("proc exception"));

		SomeInterface &i = mock.get();

		try {
			i.func(1);
		} catch (std::string e) {
			ASSERT_EQUAL(std::string("func exception"), e);
		}

		try {
			i.proc(1);
		} catch (std::string e) {
			ASSERT_EQUAL(std::string("proc exception"), e);
		}

		ASSERT_THROW(i.func(1), fakeit::UnmockedMethodCallException);
		ASSERT_THROW(i.proc(1), fakeit::UnmockedMethodCallException);
	}

	void stub_a_method_with_lambda_delegate_once() {
		Mock<SomeInterface> mock;

		int a = 0;

		When(mock[&SomeInterface::func]).Do([](int val) {return val;});
		When(mock[&SomeInterface::proc]).Do([&a](int val) {a = val;});

		SomeInterface &i = mock.get();

		ASSERT_EQUAL(3, i.func(3));

		i.proc(3);
		ASSERT_EQUAL(3, a);

		ASSERT_THROW(i.func(3), fakeit::UnmockedMethodCallException);
		ASSERT_THROW(i.proc(3), fakeit::UnmockedMethodCallException);
	}

	void stub_a_method_with_lambda_delegate_always() {
		Mock<SomeInterface> mock;

		int a = 0;

		When(mock[&SomeInterface::func]).AlwaysDo([](int val) {return val;});
		When(mock[&SomeInterface::proc]).AlwaysDo([&a](int val) {a = val;});

		SomeInterface &i = mock.get();

		ASSERT_EQUAL(3, i.func(3));
		ASSERT_EQUAL(3, i.func(3));

		i.proc(3);
		ASSERT_EQUAL(3, a);

		a = 0;
		i.proc(3);
		ASSERT_EQUAL(3, a);
	}

	static int func_delegate(int val) {
{'fraction_non_alphanumeric': 0.1425712856428214, 'fraction_numerical': 0.008254127063531767, 'mean_word_length': 5.8584905660377355, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '2326883', 'n_tokens_mistral': 3217, 'n_tokens_neox': 2909, 'n_words': 344}