diff --git a/QRCodeLibrary/QRCodeLibrary.vcxproj b/QRCodeLibrary/QRCodeLibrary.vcxproj
index 1101763..5606540 100644
--- a/QRCodeLibrary/QRCodeLibrary.vcxproj
+++ b/QRCodeLibrary/QRCodeLibrary.vcxproj
@@ -159,6 +159,7 @@
+
@@ -172,6 +173,7 @@
Create
+
diff --git a/QRCodeLibrary/QRCodeLibrary.vcxproj.filters b/QRCodeLibrary/QRCodeLibrary.vcxproj.filters
index f291a63..f8d1dab 100644
--- a/QRCodeLibrary/QRCodeLibrary.vcxproj.filters
+++ b/QRCodeLibrary/QRCodeLibrary.vcxproj.filters
@@ -39,6 +39,9 @@
Header Files
+
+ Header Files
+
@@ -59,5 +62,8 @@
Source Files
+
+ Source Files
+
\ No newline at end of file
diff --git a/QRCodeLibrary/TritMatrix.cpp b/QRCodeLibrary/TritMatrix.cpp
new file mode 100644
index 0000000..84b231e
--- /dev/null
+++ b/QRCodeLibrary/TritMatrix.cpp
@@ -0,0 +1,76 @@
+#include "pch.h"
+#include "TritMatrix.hpp"
+
+#include
+
+Trit TritMatrix::get(unsigned y, unsigned x) const
+{
+ return c[y][x];
+}
+
+void TritMatrix::set(unsigned y, unsigned x, Trit val)
+{
+ c[y][x] = val;
+}
+
+void TritMatrix::set(unsigned y, unsigned x, int32_t val, unsigned char size)
+{
+ if (x + size > c.at(0).size()) throw std::out_of_range("Value to write is out of matrix range");
+ for (unsigned char i = 0; i < size; i++)
+ set(y, x + i, ((val >> (size - 1 - i)) & 1) ? Trit::T : Trit::F);
+}
+
+void TritMatrix::set(unsigned y, unsigned x, bool val)
+{
+ set(y, x, val ? Trit::T : Trit::F);
+}
+
+string TritMatrix::to_ascii() const
+{
+ string res;
+
+ for (unsigned i = 0; i < c.size(); i++) {
+ for (unsigned j = 0; j < c.at(0).size(); j++)
+ switch (c[i][j])
+ {
+ case Trit::T:
+ res.push_back('#');
+ break;
+ case Trit::F:
+ res.push_back(' ');
+ break;
+ case Trit::EMPTY:
+ res.push_back('E');
+ break;
+ }
+ if (i != c.size() - 1)
+ res.push_back('\n');
+ }
+
+ return res;
+}
+
+string TritMatrix::to_string() const
+{
+ string res;
+
+ for (unsigned i = 0; i < c.size(); i++) {
+ for (unsigned j = 0; j < c.at(0).size(); j++)
+ switch (c[i][j])
+ {
+ case Trit::T:
+ res.push_back('1');
+ break;
+ case Trit::F:
+ res.push_back('0');
+ break;
+ case Trit::EMPTY:
+ res.push_back('E');
+ break;
+ }
+ if (i != c.size() - 1)
+ res.push_back('\n');
+ }
+
+ return res;
+}
diff --git a/QRCodeLibrary/TritMatrix.hpp b/QRCodeLibrary/TritMatrix.hpp
new file mode 100644
index 0000000..4dac810
--- /dev/null
+++ b/QRCodeLibrary/TritMatrix.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include
+#include
+
+using namespace std;
+
+enum Trit {
+ EMPTY = -1,
+ F,
+ T,
+};
+
+class TritMatrix
+{
+public:
+ TritMatrix(unsigned width, unsigned height) : c{ height, vector(width, Trit::EMPTY) } {};
+
+ Trit get(unsigned y, unsigned x) const;
+
+ void set(unsigned y, unsigned x, Trit val);
+ void set(unsigned y, unsigned x, bool val);
+ void set(unsigned y, unsigned x, int32_t val, unsigned char size);
+
+ string to_ascii() const;
+ string to_string() const;
+
+private:
+ vector> c;
+};
+
diff --git a/tests/TritMatrix_test.cpp b/tests/TritMatrix_test.cpp
new file mode 100644
index 0000000..0faacdc
--- /dev/null
+++ b/tests/TritMatrix_test.cpp
@@ -0,0 +1,87 @@
+#include "pch.h"
+
+#define protected public
+#define private public
+
+#include "../QRCodeLibrary/TritMatrix.hpp"
+
+TEST(TritMatrixTests, CreatesVectorOfVectors) {
+ TritMatrix m(5, 4);
+
+ ASSERT_EQ(m.c.size(), 4);
+
+ for (int i = 0; i < 4; i++)
+ EXPECT_EQ(m.c[i].size(), 5);
+}
+
+TEST(TritMatrixTests, GetsByCoordinates) {
+ TritMatrix m(5, 4);
+
+ m.c[1][4] = Trit::F;
+
+ EXPECT_EQ(m.get(1, 4), Trit::F);
+ EXPECT_EQ(m.get(1, 3), Trit::EMPTY);
+}
+
+TEST(TritMatrixTests, SetsIndividualCell) {
+ TritMatrix m(5, 4);
+
+ m.set(1, 3, Trit::T);
+
+ EXPECT_EQ(m.get(1, 3), Trit::T);
+ EXPECT_EQ(m.get(1, 4), Trit::EMPTY);
+
+ m.set(1, 4, Trit::F);
+
+ EXPECT_EQ(m.get(1, 3), Trit::T);
+ EXPECT_EQ(m.get(1, 4), Trit::F);
+}
+
+TEST(TritMatrixTests, SetsIndividualCellWithBool) {
+ TritMatrix m(5, 4);
+
+ m.set(1, 3, 1);
+
+ EXPECT_EQ(m.get(1, 3), Trit::T);
+ EXPECT_EQ(m.get(1, 4), Trit::EMPTY);
+
+ m.set(1, 4, 0);
+
+ EXPECT_EQ(m.get(1, 3), Trit::T);
+ EXPECT_EQ(m.get(1, 4), Trit::F);
+}
+
+TEST(TritMatrixTests, ConvertsToString) {
+ TritMatrix m(2, 2);
+
+ m.set(0, 0, 1);
+ m.set(1, 0, 0);
+ m.set(1, 1, 1);
+
+ EXPECT_EQ(m.to_string(), "1E\n01");
+}
+
+TEST(TritMatrixTests, SetsMultipleCells) {
+ TritMatrix m(5, 4);
+
+ m.set(1, 1, 0b101, 3);
+
+ ASSERT_EQ(m.to_string(), "EEEEE\nE101E\nEEEEE\nEEEEE");
+
+ m.set(2, 0, 0b11111, 5);
+
+ ASSERT_EQ(m.to_string(), "EEEEE\nE101E\n11111\nEEEEE");
+
+ m.set(2, 1, 0b010, 3);
+
+ EXPECT_EQ(m.to_string(), "EEEEE\nE101E\n10101\nEEEEE");
+}
+
+TEST(TritMatrixTests, ConvertsToASCII) {
+ TritMatrix m(2, 2);
+
+ m.set(0, 0, 0b10, 2);
+ m.set(1, 0, 0b01, 2);
+
+ EXPECT_EQ(m.to_ascii(), "# \n #");
+}
diff --git a/tests/tests.vcxproj b/tests/tests.vcxproj
index fa4c3f8..5617c86 100644
--- a/tests/tests.vcxproj
+++ b/tests/tests.vcxproj
@@ -47,6 +47,7 @@
Create
Create
+