From 8deebc93127617ddc642da7d5657b48f6f220652 Mon Sep 17 00:00:00 2001 From: Krzysztof Rudnicki Date: Tue, 30 May 2023 22:43:42 +0200 Subject: [PATCH] feat: add test_tabular_required_parameters --- examples/complicated/table1.pdf | Bin 4532 -> 4512 bytes examples/complicated/table1.tex | 2 +- program/code/main.py | 37 +++++++++++++++++- .../test_code/test_only_pipes_and_space.py | 29 ++++++++++++++ .../test_tabular_required_parameters.py | 30 ++++++++++++-- 5 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 program/tests/test_code/test_only_pipes_and_space.py diff --git a/examples/complicated/table1.pdf b/examples/complicated/table1.pdf index 7c7c02011ab45c63f30abd53d32b7c58730c82bc..68484692fe77c1e664bd42e3cd69a32814ed7f95 100644 GIT binary patch delta 1553 zcmV+s2JZQ^BcLOYHGefZK0XR_baG{3Z3=kWeN($`!!Qio`xX2Fvl6K%5O^ri7U&k# zThS#+lcgCl_4i9!lI=8gU3>i~~{aF&PvQF?cz~hUBj5$z% z;V2M{mY@rSF?bjb9~)!%OBNXujK;oWX309uOeec z&dI~i{FFlz;S7{Krj%OZ8{T324_qRV6a1o{Laz85L5WZj*PD zF{MCgS0L`tQ>vnh1wCcIDPE`ptiWRf-Kv~aO}v*nXX1+rn=!aBRyg8iMa`^PlM>pP z7uM7_?^}}``hUz-w|Av^Do>-zYkR#DsnTW=WTZL*xn*1Py;bZy7{%~rmOIGW^_|_! z4#zd~niZ3>r8#$`5qS)9eJxI&82c2dL~olIZMV`^qG2Rhh{}AgcXTH8r^k2t!`B5h zv!;SAT4tFPHZs2Lck~mf?ZYpu($r}RWo~41baG{3ZIhc236s+SCx16SJ_>Vma%Ev{ z3V7OG(pzhTFcb&ycRxiQH%9SV?LdUi%P6e7)b<0|cyvOIA?icF{WSm3hY1S5Q zK8~lMuY~JtPSnn~N`GxG=fVwHO%0;YcS+1MK4j&6oTxvDW?*q_F=j7m-8iW`d)n8- zm7dqJFIAK3M9ZEoX{krbS;`yrBqruqNutZS_&q+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4$-&gQ$35rD2&9;gnKrRa!Y~6|^T?@E=aAVaqkXV836v^L@veRw_ zHeh}*Me>lMc*qbCBm@!+a3Mhek3!%ekxmk%6re$c0dNk1Mo<IhFg_aj1eRk0_k z{Pg+O&F(=&$nO1UwnO)!+TVCKt~WkYgaPwbe;#n7*ouE@`U!!d{_n4Ck-v19@oRox zWX%g`W!h8|KR*K{5eC8_aK&jUxCj%rAl{12xXiZ}kj=MgUPC~6Pg~paT)Ns`;oGP2 z!#6s=?0dSi|L&eg%!{p+w2|EwP&+M+x%$ha-zoY}ZU%2HA6&C9<;G=11N+0)wJS@h z1m_n|cS{hpc6Vh#XbT+ARr~^jpF4t+eGn`{V_`WsVqr04IXGltWMMHeV=y%~V=*){ zGh;GiI59J3K0IS#IXGfrF=RP7WMO1sF)?E>H8x{0G&3_}GGjO~GiH+P`(MTbANJe@%#(Q$9tkx$3MC~) GPeuxksOmKU diff --git a/examples/complicated/table1.tex b/examples/complicated/table1.tex index f83c1933..ad6681ff 100644 --- a/examples/complicated/table1.tex +++ b/examples/complicated/table1.tex @@ -3,7 +3,7 @@ Here is a table: -\begin{tabular}{|l|c|r|} +\begin{tabular}{|lp{1.3pt}c|r|} \hline left & center & right \\ \cline{2-3} diff --git a/program/code/main.py b/program/code/main.py index 626b4e8e..ffa5507f 100644 --- a/program/code/main.py +++ b/program/code/main.py @@ -90,6 +90,38 @@ def tabular_parameters(latex_string): return "Error!" +def only_pipes_and_space(latex_string): + """Checks if latex string only contains | or " ", if yes returns True, if no returns false""" + return all(char == '|' or char == ' ' or char == '{' or char == '}' for char in latex_string) + + +def main_tabular_parameters_loop(latex_string, simple_parameters_dictionary): + return_array = [] + i = 0 + latex_string_length = len(latex_string) + while i < latex_string_length: + character = latex_string[i] + if character in ['l', 'c', 'r', '|']: + print("entered") + return_array.append( + simple_parameters_dictionary.get(latex_string[i])) + i += 1 + continue + if character in ['p', 'm', 'b']: + closing_bracket = latex_string.find('}', i + 1) + columns_string = latex_string[i:closing_bracket + 1] + print(columns_string) + result = tabular_columns_parameters(columns_string) + if result == "Error!": + return result + return_array.append(result) + i = closing_bracket + continue + i += 1 + print(return_array) + return return_array + + def tabular_required_parameters(latex_string): if generic_checks(latex_string) == "Error!": return "Error!" @@ -102,7 +134,10 @@ def tabular_required_parameters(latex_string): "r": "align='right'", "|": "style=\"border-left: 1px solid black" } - return latex_string + if only_pipes_and_space(latex_string): + print("tabular_required_parameters, required table parameters are only pipes and spaces!:", latex_string) + return "Error!" + return main_tabular_parameters_loop(latex_string, simple_parameters_dictionary) def length_conversions(latex_length): diff --git a/program/tests/test_code/test_only_pipes_and_space.py b/program/tests/test_code/test_only_pipes_and_space.py new file mode 100644 index 00000000..c330c426 --- /dev/null +++ b/program/tests/test_code/test_only_pipes_and_space.py @@ -0,0 +1,29 @@ +from code.main import only_pipes_and_space + + +def given_empty_then_true(): + assert only_pipes_and_space("") == True + + +def given_only_pipes_then_true(): + assert only_pipes_and_space("|||||") == True + + +def given_only_space_then_true(): + assert only_pipes_and_space(" ") == True + + +def given_space_and_pipes_then_true(): + assert only_pipes_and_space("| | ||| |") == True + + +def given_not_space_nor_pipes_then_false(): + assert only_pipes_and_space(" || || a") == False + + +def test_only_pipes_and_space(): + given_empty_then_true() + given_only_pipes_then_true() + given_only_space_then_true() + given_space_and_pipes_then_true() + given_not_space_nor_pipes_then_false() diff --git a/program/tests/test_code/test_tabular_required_parameters.py b/program/tests/test_code/test_tabular_required_parameters.py index cc0cea48..2141e18f 100644 --- a/program/tests/test_code/test_tabular_required_parameters.py +++ b/program/tests/test_code/test_tabular_required_parameters.py @@ -47,7 +47,7 @@ def given_single_left_then_correct(): When: N/A Then: """ - assert tabular_required_parameters("{l}") == ['l'] + assert tabular_required_parameters("{l}") == ["align='left'"] def given_single_center_then_correct(): @@ -56,7 +56,7 @@ def given_single_center_then_correct(): When: N/A Then: """ - assert tabular_required_parameters("{c}") == ['c'] + assert tabular_required_parameters("{c}") == ["align='center'"] def given_single_right_then_correct(): @@ -65,7 +65,7 @@ def given_single_right_then_correct(): When: N/A Then: """ - assert tabular_required_parameters("{r}") == ['r'] + assert tabular_required_parameters("{r}") == ["align='right'"] def given_empty_wrap_p_then_error(): @@ -122,6 +122,28 @@ def given_empty_wrap_b_brackets_then_error(): assert tabular_required_parameters("{b{}}") == "Error!" +def given_filled_p_brackets_then_correct(): + """ + Given: {r} + When: N/A + Then: + """ + assert tabular_required_parameters("{p{1.3pt}}") == [ + "style=\"vertical-align: top; width: 1.69px;\""] + + +def given_complicated_then_correct(): + assert tabular_required_parameters("{|lp{1.3pt}c|r|}") == [ + "style=\"border-left: 1px solid black", + "align='left'", + "style=\"vertical-align: top; width: 1.69px;\"", + "align='center'", + "style=\"border-left: 1px solid black", + "align='right'", + "style=\"border-left: 1px solid black" + ] + + def test_tabular_required_parameters(): given_empty_then_error() given_empty_brackets_then_error() @@ -136,3 +158,5 @@ def test_tabular_required_parameters(): given_empty_wrap_p_brackets_then_error() given_empty_wrap_m_brackets_then_error() given_empty_wrap_b_brackets_then_error() + given_filled_p_brackets_then_correct() + given_complicated_then_correct()