<commit_before>#include <mix/computer.h>
#include <mix/command.h>

#include <gtest/gtest.h>

using namespace mix;

namespace {

Command MakeSTA(int address, const WordField& field = Word::MaxField(), std::size_t index_register = 0)
{
	return Command{24, address, index_register, field};
}

Command MakeLDA(int address, const WordField& field = Word::MaxField(), std::size_t index_register = 0)
{
	return Command{8, address, index_register, field};
}

Command MakeADD(int address, const WordField& field = Word::MaxField(), std::size_t index_register = 0)
{
	return Command{1, address, index_register, field};
}

class ADD_TAOCP_Book_Test : public ::testing::Test
{
private:
	void SetUp() override
	{
		Register ra;
		ra.set_byte(1, Byte{1});
		ra.set_byte(2, Byte{1});
		ra.set_byte(3, Byte{1});
		ra.set_byte(4, Byte{1});
		ra.set_byte(5, Byte{1});
		mix.set_ra(ra);
	}

protected:
	Computer mix;
};

} // namespace

TEST_F(ADD_TAOCP_Book_Test, Register_A_Bytes_Sum)
{
	mix.execute(MakeSTA(2000));
	mix.execute(MakeLDA(2000, WordField{5, 5}));

	mix.execute(MakeADD(2000, WordField{4, 4}));
	mix.execute(MakeADD(2000, WordField{3, 3}));
	mix.execute(MakeADD(2000, WordField{2, 2}));
	mix.execute(MakeADD(2000, WordField{1, 1}));

	ASSERT_EQ(5, mix.ra().value());
}
<commit_msg>Add second example of ADD from TAOCP<commit_after>#include <mix/computer.h>
#include <mix/command.h>

#include <gtest/gtest.h>

using namespace mix;

namespace {

Command MakeSTA(int address, const WordField& field = Word::MaxField(), std::size_t index_register = 0)
{
	return Command{24, address, index_register, field};
}

Command MakeLDA(int address, const WordField& field = Word::MaxField(), std::size_t index_register = 0)
{
	return Command{8, address, index_register, field};
}

Command MakeADD(int address, const WordField& field = Word::MaxField(), std::size_t index_register = 0)
{
	return Command{1, address, index_register, field};
}
} // namespace

TEST(ADD_TAOCP_Book_Test, Register_A_Bytes_Sum)
{
	Computer mix;

	{
		Register ra;
		ra.set_byte(1, Byte{1});
		ra.set_byte(2, Byte{1});
		ra.set_byte(3, Byte{1});
		ra.set_byte(4, Byte{1});
		ra.set_byte(5, Byte{1});
		mix.set_ra(ra);
	}

	mix.execute(MakeSTA(2000));
	mix.execute(MakeLDA(2000, WordField{5, 5}));

	mix.execute(MakeADD(2000, WordField{4, 4}));
	mix.execute(MakeADD(2000, WordField{3, 3}));
	mix.execute(MakeADD(2000, WordField{2, 2}));
	mix.execute(MakeADD(2000, WordField{1, 1}));

	const auto result = mix.ra().value();
	const auto expected_result = 1 * 5;
	ASSERT_EQ(expected_result, result);
}

TEST(ADD_TAOCP_Book_Test, Simple_Addition)
{
	Computer mix;

	{
		Register ra;
		ra.set_value(1234, WordField{0, 2});
		ra.set_byte(3, Byte{1});
		ra.set_value(150, WordField{4, 5});
		mix.set_ra(ra);
	}

	{
		Word w;
		w.set_value(100, WordField{0, 2});
		w.set_byte(3, Byte{5});
		w.set_value(50, WordField{4, 5});
		mix.set_memory(1000, w);
	}

	mix.execute(MakeADD(1000));

	{
		ASSERT_EQ(1334, mix.ra().value(WordField{0, 2}));
		ASSERT_EQ(6, mix.ra().value(WordField{3, 3}));
		ASSERT_EQ(200, mix.ra().value(WordField{4, 5}));
	}
}


{'fraction_non_alphanumeric': 0.16419294990723562, 'fraction_numerical': 0.04669140383426098, 'mean_word_length': 4.2859477124183005, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '125263', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1243, 'n_words': 243}