<commit_before>import unittest
from src.dims import *
from src import printer

class TestsPrinter(unittest.TestCase):
	x = "x"
	r = "r"
	c = "c"
	data = [{r: 0, c: 0, x: 1},
	        {r: 0, c: 0, x: 2},
	        {r: 0, c: 0, x: 3},
	        {r: 0, c: 1, x: 4},
	        {r: 0, c: 1, x: 5},
	        {r: 0, c: 1, x: 6},
	        {r: 0, c: 2, x: 7},
	        {r: 0, c: 2, x: 8},
	        {r: 0, c: 2, x: 9},
	        {r: 1, c: 0, x: 11},
	        {r: 1, c: 0, x: 12},
	        {r: 1, c: 0, x: 13},
	        {r: 1, c: 1, x: 14},
	        {r: 1, c: 1, x: 15},
	        {r: 1, c: 1, x: 16},
	        {r: 1, c: 2, x: 17},
	        {r: 1, c: 2, x: 18},
	        {r: 1, c: 2, x: 19}]
	dim_rows = Dim([Config("r0", lambda d: d["r"] == 0),
	                Config("r1", lambda d: d["r"] == 1)])
	dim_cols = Dim([Config("c0", lambda d: d["c"] == 0),
	                Config("c1", lambda d: d["c"] == 1),
	                Config("c2", lambda d: d["c"] == 2)])
	dim_z = Dim([Config("z0", lambda d: d["x"] < 5 ),
	             Config("z1", lambda d: d["x"] >= 5)])

	def test_text_table_multichar_seps(self):
		text = printer.text_table(self.data, self.dim_rows, self.dim_cols, lambda ds: sum([d["x"] for d in ds]), d_cols=" && ", d_rows=";\n")
		self.assertEquals(" && c0 && c1 && c2;\n" + "r0 && 6 && 15 && 24;\n" + "r1 && 36 && 45 && 54;\n", text)


	def test_text_table(self):
		text = printer.text_table(self.data, self.dim_rows, self.dim_cols, lambda ds: sum([d["x"] for d in ds]))
		self.assertEquals("\tc0\tc1\tc2\n" + "r0\t6\t15\t24\n"  + "r1\t36\t45\t54\n", text)

		text = printer.text_table(self.data, self.dim_cols, self.dim_rows, lambda ds: sum([d["x"] for d in ds]))
		self.assertEquals("\tr0\tr1\n" + "c0\t6\t36\n" + "c1\t15\t45\n" + "c2\t24\t54\n", text)


	def test_latex_table(self):
		text = printer.latex_table(self.data, self.dim_rows, self.dim_cols, lambda ds: sum([d["x"] for d in ds]))
		self.assertEquals(r"\begin{tabular}{cccc}" + "\n" + r" & c0 & c1 & c2\\" + "\n" +
		                  r"r0 & 6 & 15 & 24\\"+"\n" + r"r1 & 36 & 45 & 54\\" + "\n" +
		                  r"\end{tabular}" + "\n", text)


	def test_latex_table_header_multilayered_1(self):
		text = printer.latex_table_header_multilayered(self.dim_cols)
		self.assertEquals(r" & c0 & c1 & c2\\" + "\n", text)


	def test_latex_table_header_multilayered_2(self):
		dim = self.dim_rows * self.dim_cols
		text = printer.latex_table_header_multilayered(dim)
		print("TEXT2:\n" + text)
		self.assertEquals(r" & \multicolumn{3}{c}{r0} & \multicolumn{3}{c}{r1}\\" + "\n" +
		                  r" & c0 & c1 & c2 & c0 & c1 & c2\\" + "\n", text)

		dim = self.dim_rows * self.dim_cols
		dim = Dim(dim.configs[:-1])
		text = printer.latex_table_header_multilayered(dim)
		self.assertEquals(r" & \multicolumn{3}{c}{r0} & \multicolumn{2}{c}{r1}\\" + "\n" +
		                  r" & c0 & c1 & c2 & c0 & c1\\" + "\n", text)


	def test_latex_table_header_multilayered_3(self):
		dim = self.dim_z * self.dim_rows * self.dim_cols
		text = printer.latex_table_header_multilayered(dim)
		print("TEXT3:\n" + text)
		self.assertEquals(r" & \multicolumn{6}{c}{z0} & \multicolumn{6}{c}{z1}\\" + "\n" +
		                  r" & \multicolumn{3}{c}{r0} & \multicolumn{3}{c}{r1} & \multicolumn{3}{c}{r0} & \multicolumn{3}{c}{r1}\\" + "\n" +
		                  r" & c0 & c1 & c2 & c0 & c1 & c2 & c0 & c1 & c2 & c0 & c1 & c2\\" + "\n", text)

<commit_msg>Added unit test for an assymetrical case of layered table header.<commit_after>import unittest
from src.dims import *
from src import printer

class TestsPrinter(unittest.TestCase):
	x = "x"
	r = "r"
	c = "c"
	data = [{r: 0, c: 0, x: 1},
	        {r: 0, c: 0, x: 2},
	        {r: 0, c: 0, x: 3},
	        {r: 0, c: 1, x: 4},
	        {r: 0, c: 1, x: 5},
	        {r: 0, c: 1, x: 6},
	        {r: 0, c: 2, x: 7},
	        {r: 0, c: 2, x: 8},
	        {r: 0, c: 2, x: 9},
	        {r: 1, c: 0, x: 11},
	        {r: 1, c: 0, x: 12},
	        {r: 1, c: 0, x: 13},
	        {r: 1, c: 1, x: 14},
	        {r: 1, c: 1, x: 15},
	        {r: 1, c: 1, x: 16},
	        {r: 1, c: 2, x: 17},
	        {r: 1, c: 2, x: 18},
	        {r: 1, c: 2, x: 19}]
	dim_rows = Dim([Config("r0", lambda d: d["r"] == 0),
	                Config("r1", lambda d: d["r"] == 1)])
	dim_cols = Dim([Config("c0", lambda d: d["c"] == 0),
	                Config("c1", lambda d: d["c"] == 1),
	                Config("c2", lambda d: d["c"] == 2)])
	dim_z = Dim([Config("z0", lambda d: d["x"] < 5 ),
	             Config("z1", lambda d: d["x"] >= 5)])

	def test_text_table_multichar_seps(self):
		text = printer.text_table(self.data, self.dim_rows, self.dim_cols, lambda ds: sum([d["x"] for d in ds]), d_cols=" && ", d_rows=";\n")
		self.assertEquals(" && c0 && c1 && c2;\n" + "r0 && 6 && 15 && 24;\n" + "r1 && 36 && 45 && 54;\n", text)


	def test_text_table(self):
		text = printer.text_table(self.data, self.dim_rows, self.dim_cols, lambda ds: sum([d["x"] for d in ds]))
		self.assertEquals("\tc0\tc1\tc2\n" + "r0\t6\t15\t24\n"  + "r1\t36\t45\t54\n", text)

		text = printer.text_table(self.data, self.dim_cols, self.dim_rows, lambda ds: sum([d["x"] for d in ds]))
		self.assertEquals("\tr0\tr1\n" + "c0\t6\t36\n" + "c1\t15\t45\n" + "c2\t24\t54\n", text)


	def test_latex_table(self):
		text = printer.latex_table(self.data, self.dim_rows, self.dim_cols, lambda ds: sum([d["x"] for d in ds]))
		self.assertEquals(r"\begin{tabular}{cccc}" + "\n" + r" & c0 & c1 & c2\\" + "\n" +
		                  r"r0 & 6 & 15 & 24\\"+"\n" + r"r1 & 36 & 45 & 54\\" + "\n" +
		                  r"\end{tabular}" + "\n", text)


	def test_latex_table_header_multilayered_1(self):
		text = printer.latex_table_header_multilayered(self.dim_cols)
		self.assertEquals(r" & c0 & c1 & c2\\" + "\n", text)


	def test_latex_table_header_multilayered_2(self):
		dim = self.dim_rows * self.dim_cols
		text = printer.latex_table_header_multilayered(dim)
		self.assertEquals(r" & \multicolumn{3}{c}{r0} & \multicolumn{3}{c}{r1}\\" + "\n" +
		                  r" & c0 & c1 & c2 & c0 & c1 & c2\\" + "\n", text)

		dim = self.dim_rows * self.dim_cols
		dim = Dim(dim.configs[:-1])
		text = printer.latex_table_header_multilayered(dim)
		self.assertEquals(r" & \multicolumn{3}{c}{r0} & \multicolumn{2}{c}{r1}\\" + "\n" +
		                  r" & c0 & c1 & c2 & c0 & c1\\" + "\n", text)


	def test_latex_table_header_multilayered_3(self):
		dim = self.dim_z * self.dim_rows * self.dim_cols
		text = printer.latex_table_header_multilayered(dim)
		self.assertEquals(r" & \multicolumn{6}{c}{z0} & \multicolumn{6}{c}{z1}\\" + "\n" +
		                  r" & \multicolumn{3}{c}{r0} & \multicolumn{3}{c}{r1} & \multicolumn{3}{c}{r0} & \multicolumn{3}{c}{r1}\\" + "\n" +
		                  r" & c0 & c1 & c2 & c0 & c1 & c2 & c0 & c1 & c2 & c0 & c1 & c2\\" + "\n", text)

		dim = self.dim_z * self.dim_rows * self.dim_cols
		dim = Dim(dim.configs[:-1])
		text = printer.latex_table_header_multilayered(dim)
		self.assertEquals(r" & \multicolumn{6}{c}{z0} & \multicolumn{5}{c}{z1}\\" + "\n" +
		                  r" & \multicolumn{3}{c}{r0} & \multicolumn{3}{c}{r1} & \multicolumn{3}{c}{r0} & \multicolumn{2}{c}{r1}\\" + "\n" +
		                  r" & c0 & c1 & c2 & c0 & c1 & c2 & c0 & c1 & c2 & c0 & c1\\" + "\n", text)


{'fraction_non_alphanumeric': 0.22329427980702962, 'fraction_numerical': 0.05623707787732598, 'mean_word_length': 2.4453941120607787, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '198256', 'n_tokens_mistral': 3454, 'n_tokens_neox': 3142, 'n_words': 724}