Skip to content

Commit

Permalink
test corrections + fix bug, remove line return
Browse files Browse the repository at this point in the history
  • Loading branch information
arng40 committed Dec 17, 2024
1 parent 6b024b4 commit e40b0df
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 46 deletions.
16 changes: 12 additions & 4 deletions src/coreComponents/common/format/table/TableFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,26 @@ void TableTextFormatter::populateHeaderCellsLayout( TableLayout & tableLayout,
}
currentCell.m_cellWidth = it->m_header.m_cellWidth;

if( it->hasParent() && it->getParent()->getNumberCellMerge() == 0 )
if( it->hasParent() )
{
it->getParent()->incrementMergeHeaderCount();
if( it->getNumberCellMerge() == 0 )
{
it->getParent()->incrementMergeHeaderCount( 1 );
}
else
{
it->getParent()->incrementMergeHeaderCount( it->getNumberCellMerge() );
}
}

if( it->getNumberCellMerge() > 1 )
{
it->getParent()->decrementMergeHeaderCount();
it->decrementMergeHeaderCount();
}

sublineHeaderCounts[currentLayer] = std::max( sublineHeaderCounts[currentLayer],
currentCell.m_lines.size() );

for( size_t idxColumn = 0; idxColumn < it->getNumberCellMerge(); idxColumn++ )
{
TableLayout::CellLayout mergingCell{ CellType::MergeNext, "", TableLayout::Alignment::center };
Expand Down Expand Up @@ -643,7 +651,7 @@ void TableTextFormatter::outputLines( TableLayout & tableLayout,

if( sectionType == CellType::Value && !cellsLayout.empty())
{
tableOutput << GEOS_FMT( "{}\n", separatorLine );
tableOutput << separatorLine;
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/coreComponents/common/format/table/TableLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ TableLayout::Column & TableLayout::Column::setValuesAlignment( Alignment valueAl
size_t TableLayout::Column::getNumberCellMerge()
{ return m_headerMergeCount; }

void TableLayout::Column::incrementMergeHeaderCount()
{ m_headerMergeCount++;}
void TableLayout::Column::incrementMergeHeaderCount( size_t value )
{ m_headerMergeCount+= value;}

void TableLayout::Column::decrementMergeHeaderCount()
{ m_headerMergeCount--; }
Expand Down
8 changes: 5 additions & 3 deletions src/coreComponents/common/format/table/TableLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class TableLayout

/**
* @brief Set the column visibility.
* @param CellType Cell type to apply to hide the colmun
* @param celltype Cell type to apply to hide the colmun
* @return The current column .
*/
Column & setVisibility( CellType celltype );
Expand Down Expand Up @@ -193,7 +193,7 @@ class TableLayout

/**
* @brief Sets the values alignment for the column.
* @param headerAlignment The alignment to set for the column values (left, right, or center).
* @param valueAlignment The alignment to set for the column values (left, right, or center).
* @return The current column object
*/
TableLayout::Column & setValuesAlignment( Alignment valueAlignment );
Expand All @@ -205,8 +205,9 @@ class TableLayout

/**
* @brief Increment number of times we will divide the current cell
* @param value number of division to add
*/
void incrementMergeHeaderCount();
void incrementMergeHeaderCount( size_t value );

/**
* @brief Decremente number of times we will divide the current cell
Expand Down Expand Up @@ -241,6 +242,7 @@ class TableLayout
class LeafIterator
{
public:
///alias for column
using ColumnType = Column;

/**
Expand Down
81 changes: 44 additions & 37 deletions src/coreComponents/common/format/table/unitTests/testTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ TEST( testTable, tableEmptyRow )
"| value1 | [30.21543] | 3.0 | 54 | 0 |\n"
"| | | | | |\n"
"| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n"
"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n"
"-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
);
}

Expand Down Expand Up @@ -83,7 +83,7 @@ TEST( testTable, tableClassic )
"| value1 | [30.21543] | 3.0 | 54 | 0 |\n"
"| | | | | |\n"
"| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n"
"-----------------------------------------------------------------------------------------------------------------------------------------------------------\n\n"
"-----------------------------------------------------------------------------------------------------------------------------------------------------------\n"
);
}

Expand Down Expand Up @@ -111,13 +111,13 @@ TEST( testTable, tableColumnParamClassic )
std::cout << tableText.toString( tableData )<< std::endl;
EXPECT_EQ( tableText.toString( tableData ),
"\n-------------------------------------------------------------------------------------------\n"
"| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n"
"| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n"
"| | | | | element | element |\n"
"-------------------------------------------------------------------------------------------\n"
"| value1 | gaz | 3.0 | 3.0129877 | 2 | 1 |\n"
"| | water | 42.0 | 0.0123456 | 3 | 4 |\n"
"| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n"
"-------------------------------------------------------------------------------------------\n\n"
"-------------------------------------------------------------------------------------------\n"
);
}

Expand Down Expand Up @@ -165,7 +165,7 @@ TEST( testTable, tableHiddenColumn )
"---------------------------------------------------------------------------------------------------------------\n"
"| value1 | 3.0 | 3.0129877 |\n"
"| val1 | [3.045,42.02,89.25] | 3 |\n"
"---------------------------------------------------------------------------------------------------------------\n\n" );
"---------------------------------------------------------------------------------------------------------------\n" );
}

TEST( testTable, tableUniqueColumn )
Expand All @@ -186,7 +186,7 @@ TEST( testTable, tableUniqueColumn )
"---------------------------------------------------------------------------------------------------------------\n"
"| value1 |\n"
"| val1 |\n"
"---------------------------------------------------------------------------------------------------------------\n\n" );
"---------------------------------------------------------------------------------------------------------------\n" );
}

TEST( testTable, tableEmptyTitle )
Expand Down Expand Up @@ -221,7 +221,7 @@ TEST( testTable, tableEmptyTitle )
"-------------------------------------------------------------------------------------------\n"
"| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n"
"| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n"
"-------------------------------------------------------------------------------------------\n\n"
"-------------------------------------------------------------------------------------------\n"
);
}

Expand Down Expand Up @@ -258,7 +258,7 @@ TEST( testTable, table2DTable )
"| Temperature = 300 | 0.03 | 0.02 |\n"
"| Temperature = 350 | 0.035 | 0.023333333333333334 |\n"
"| Temperature = 400 | 0.04 | 0.02666666666666667 |\n"
"---------------------------------------------------------------------\n\n"
"---------------------------------------------------------------------\n"
);
}

Expand Down Expand Up @@ -311,7 +311,6 @@ TEST( testTable, subColumns )
tableData.addRow( "6193", "7481", "1305", "9037", "4306.1", "6157", "1849", "2753", "910", "2369", "9992", "6", "7" );
tableData.addRow( "8012", "5729.2112", "6975", "3201.213", "9448", "1820", "4125", "182.12", "7453", "5069", "3912", "6", "7" );
tableData.addRow( "4381", "6728", "5204", "8663", "2035", "7804", "6310", "9621", "4158", "789", "2537", "6", "7" );

TableTextFormatter tableText( tableLayout );
EXPECT_EQ( tableText.toString(
tableData ),
Expand All @@ -328,7 +327,7 @@ TEST( testTable, subColumns )
"| 6193 | 7481 | 1305 | 9037 | 4306.1 | 6157 | 1849 | 2753 | 910 | 2369 | 9992 | 6 | 7 |\n"
"| 8012 | 5729.2112 | 6975 | 3201.213 | 9448 | 1820 | 4125 | 182.12 | 7453 | 5069 | 3912 | 6 | 7 |\n"
"| 4381 | 6728 | 5204 | 8663 | 2035 | 7804 | 6310 | 9621 | 4158 | 789 | 2537 | 6 | 7 |\n"
"------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n"
"------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
);
}
}
Expand Down Expand Up @@ -359,13 +358,13 @@ TEST( testTable, variadicTest )
"\n--------------------------------------------------------------------------------------------------------------------------------------\n"
"| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis nascetur ridiculus mus |\n"
"--------------------------------------------------------------------------------------------------------------------------------------\n"
"| Rank | Nodes | Edge | Faces | Elems |\n"
"| Rank | Nodes | Edge | Faces | Elems |\n"
"--------------------------------------------------------------------------------------------------------------------------------------\n"
"| | Locales | Ghost | | Locales | Ghost | Locales | Ghost |\n"
"| | Locales | Ghost | | Locales | Ghost | Locales | Ghost |\n"
"--------------------------------------------------------------------------------------------------------------------------------------\n"
"| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n"
"| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n"
"--------------------------------------------------------------------------------------------------------------------------------------\n"
"| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n"
"| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n"
"--------------------------------------------------------------------------------------------------------------------------------------\n\n"
);
}
}
Expand All @@ -390,7 +389,7 @@ TEST( testTable, testLineBreak )
"---------------------------------------------------\n"
"| 1| 2|3.0|3.0129877| 2| 1|\n"
"| 1| 2|3.0|3.0129877| 2| 1|\n"
"---------------------------------------------------\n"
"---------------------------------------------------"
);
}

Expand Down Expand Up @@ -433,28 +432,36 @@ TEST( testTable, testCellMerging )
tableData.addRow( "Alpha", 1001, 8, "Beta\nwater", "2002\n1.0", CellType::MergeNext );

TableTextFormatter const tableText( tableLayout );
std::cout <<tableText.toString( tableData ) << std::endl;
EXPECT_EQ( tableText.toString( tableData ),
"\n----------------------------------------------------------------------------\n"
"| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n"
"| | | | | element | element |\n"
"----------------------------------------------------------------------------\n"
"| ProductA | 1234 | 40 | ProductName | 5678 | 60 |\n"
"----------------------------------------------------------------------------\n"
"| P1 | 2002 | 1212121245452145454545 | 4004 | |\n"
"| P2 | 2003 | | | |\n"
"| P3 | 2004 | | | |\n"
"| 3.14 | 2.718 | 1.618 | 0.577 | |\n"
"----------------------------------------------------------------------------\n"
"| Item2 |\n"
"----------------------------------------------------------------------------\n"
"| 1500 | 2500 | |\n"
"----------------------------------------------------------------------------\n"
"| 1.23 | 4.56 | 7.89 | 0.12 | 40 |\n"
"----------------------------------------------------------------------------\n"
"| Alpha | 1001 | 8 | Beta | 2002 | |\n"
"| | | | water | 1.0 | |\n"
"----------------------------------------------------------------------------\n\n"
"\n-------------------------------------------------------------------------------------------------------------------\n"
"| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n"
"| | | | | element | element |\n"
"-------------------------------------------------------------------------------------------------------------------\n"
"| ProductA | 1234 | 40 | ProductName | 5678 | 60 |\n"
"| ProductA | 54 | 4564575 | long size value | 5454554512 | 60 |\n"
"-------------------------------------------------------------------------------------------------------------------\n"
"| ProductA | 54 | 4564575 | long size value | 5454554512 | 60 |\n"
"| 3.14 | 2.718 | 1.618 | 0.577 | |\n"
"| P1 | 2002 | 1212121245452145454545 | 4004 | |\n"
"| P2 | 2003 | | | |\n"
"| P3 | 2004 | | | |\n"
"| Long product size | 54 | 4564575 | long size value | 5454554512 | 60 |\n"
"| ProductAfdggfd | 5445 | 4565 | PrName | 5454512 | 64650 |\n"
"| 3.14 | 2.718 | 1.618 | 0.577 | |\n"
"-------------------------------------------------------------------------------------------------------------------\n"
"| Item2 |\n"
"-------------------------------------------------------------------------------------------------------------------\n"
"| 1500 | 2500 | |\n"
"-------------------------------------------------------------------------------------------------------------------\n"
"| 1.23 | 4.56 | 7.89 | 0.12 | 40 |\n"
"| Long product size | 54 | 4564575 | long size value | 5454554512 | 60 |\n"
"| ProductA | 54 | 4564575 | long size value | 5454554512 | 60 |\n"
"-------------------------------------------------------------------------------------------------------------------\n"
"| P1 | 2002 | 1212121245452145454545 |\n"
"-------------------------------------------------------------------------------------------------------------------\n"
"| Alpha | 1001 | 8 | Beta | 2002 | |\n"
"| | | | water | 1.0 | |\n"
"-------------------------------------------------------------------------------------------------------------------\n"
);
}

Expand Down

0 comments on commit e40b0df

Please sign in to comment.