# Path: wordinserter/operations.py
# class Table(Operation):
#     allowed_children = {"TableRow", "TableHead", "TableBody"}
#     optional = {"border"}
# 
#     @property
#     def dimensions(self):
#         """
#         Returns row, column counts
#         """
#         if not self.has_children:
#             return 0, 0
# 
#         rows = len(self.children)
#         columns = max(sum(child.colspan or 1 for child in row.children) for row in self.children)
# 
#         return rows, columns
#     
#     @property
#     def is_uniform(self):
#         if not self.has_children:
#             return False
# 
#         if len(self.children) == 1:
#             return True
# 
#         first_row = len(self.children[0].children)
#         return all(len(child.children) == first_row for child in self.children[1:])
#     
#     @property
#     def width(self):
#         return get_value_and_unit(self.format.width)
# 
#     def update_child_widths(self):
#         if not self.is_uniform:
#             return
# 
#         row_widths = [None] * self.dimensions[1]
# 
#         for idx, _ in enumerate(row_widths):
#             for row in self.children:
#                 child = row.children[idx]
#                 child_width, unit = child.width
#                 if child_width is not None:
#                     row_widths[idx] = child.format.width
#                     break
# 
#         for row in self.children:
#             for idx, cell in enumerate(row.children):
#                 cell.format.width = row_widths[idx]
# 
# class TableCell(Operation):
#     optional = {"colspan", "rowspan", "orientation"}
# 
#     @property
#     def width(self):
#         return get_value_and_unit(self.format.width)
# 
# class TableRow(Operation):
#     allowed_children = {"TableCell"}
# 
# Path: wordinserter/parsers/fixes/table_colspans.py
# def normalize_table_colspans(tokens):
# def normalize_table(table: Table):


import pytest
from wordinserter.operations import Table, TableCell, TableRow
from wordinserter.parsers.fixes import table_colspans



class TestNormalizeTable:
    # Lists of (table_length, given, expected) table colspans
    TABLES = [
        (8, (5, 1, 3), (5, 1, 2)),  # Reduce last column by 1
        (8, (3, 1, 4, 4), (3, 1, 3, 1)),  # Reduce 3rd column by one, last column to 1
        (8, (3, 2, 4, 4), (3, 2, 2, 1)),  # Reduce 2nd column, third and fourth
        (8, (3, 1, 3), (3, 1, 4)),  # Expand fourth column,
    ]
    TABLES.extend((i, (8,), (i,)) for i in range(1, 7))  # Reduce single column colspans to single values

    @pytest.mark.parametrize('table_length, given_spans,expected_spans', TABLES)
    def test_normalize_rowspans(self, table_length, given_spans, expected_spans):

# Path: wordinserter/operations.py
# class Table(Operation):
#     allowed_children = {"TableRow", "TableHead", "TableBody"}
#     optional = {"border"}
# 
#     @property
#     def dimensions(self):
#         """
#         Returns row, column counts
#         """
#         if not self.has_children:
#             return 0, 0
# 
#         rows = len(self.children)
#         columns = max(sum(child.colspan or 1 for child in row.children) for row in self.children)
# 
#         return rows, columns
#     
#     @property
#     def is_uniform(self):
#         if not self.has_children:
#             return False
# 
#         if len(self.children) == 1:
#             return True
# 
#         first_row = len(self.children[0].children)
#         return all(len(child.children) == first_row for child in self.children[1:])
#     
#     @property
#     def width(self):
#         return get_value_and_unit(self.format.width)
# 
#     def update_child_widths(self):
#         if not self.is_uniform:
#             return
# 
#         row_widths = [None] * self.dimensions[1]
# 
#         for idx, _ in enumerate(row_widths):
#             for row in self.children:
#                 child = row.children[idx]
#                 child_width, unit = child.width
#                 if child_width is not None:
#                     row_widths[idx] = child.format.width
#                     break
# 
#         for row in self.children:
#             for idx, cell in enumerate(row.children):
#                 cell.format.width = row_widths[idx]
# 
# class TableCell(Operation):
#     optional = {"colspan", "rowspan", "orientation"}
# 
#     @property
#     def width(self):
#         return get_value_and_unit(self.format.width)
# 
# class TableRow(Operation):
#     allowed_children = {"TableCell"}
# 
# Path: wordinserter/parsers/fixes/table_colspans.py
# def normalize_table_colspans(tokens):
# def normalize_table(table: Table):


# Path: tests/test_normalize.py
import pytest
from wordinserter.operations import Table, TableCell, TableRow
from wordinserter.parsers.fixes import table_colspans




class TestNormalizeTable:
    # Lists of (table_length, given, expected) table colspans
    TABLES = [
        (8, (5, 1, 3), (5, 1, 2)),  # Reduce last column by 1
        (8, (3, 1, 4, 4), (3, 1, 3, 1)),  # Reduce 3rd column by one, last column to 1
        (8, (3, 2, 4, 4), (3, 2, 2, 1)),  # Reduce 2nd column, third and fourth
        (8, (3, 1, 3), (3, 1, 4)),  # Expand fourth column,
    ]
    TABLES.extend((i, (8,), (i,)) for i in range(1, 7))  # Reduce single column colspans to single values

    @pytest.mark.parametrize('table_length, given_spans,expected_spans', TABLES)
    def test_normalize_rowspans(self, table_length, given_spans, expected_spans):

        given_row = TableRow(