mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 16:03:11 +02:00
feat: add test_tabular_required_parameters
This commit is contained in:
parent
5988bbb2bb
commit
8deebc9312
Binary file not shown.
@ -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}
|
||||
|
||||
@ -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):
|
||||
|
||||
29
program/tests/test_code/test_only_pipes_and_space.py
Normal file
29
program/tests/test_code/test_only_pipes_and_space.py
Normal file
@ -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()
|
||||
@ -47,7 +47,7 @@ def given_single_left_then_correct():
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
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: <!DOCTYPE html><html>
|
||||
"""
|
||||
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: <!DOCTYPE html><html>
|
||||
"""
|
||||
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: <!DOCTYPE html><html>
|
||||
"""
|
||||
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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user