KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sch_table.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <sch_table.h>
22#include <sch_tablecell.h>
23
24
25BOOST_AUTO_TEST_SUITE( SchTable )
26
27
28static SCH_TABLE* createTable( int aColCount, int aCellCount, int aX, int aY )
29{
30 SCH_TABLE* table = new SCH_TABLE( schIUScale.mmToIU( 0.1 ) );
31 table->SetColCount( aColCount );
32
33 for( int i = 0; i < aCellCount; ++i )
34 {
35 SCH_TABLECELL* cell = new SCH_TABLECELL();
36
37 if( i == 0 )
38 cell->SetPosition( VECTOR2I( aX, aY ) );
39
40 table->AddCell( cell );
41 }
42
43 return table;
44}
45
46
47BOOST_AUTO_TEST_CASE( TableCompareByPosition )
48{
49 // Issue 22559: Tables with different positions were not compared correctly because
50 // operator< had bugs comparing positions (comparing self to self instead of other).
51
52 std::unique_ptr<SCH_TABLE> table1( createTable( 2, 4, 100, 200 ) );
53 std::unique_ptr<SCH_TABLE> table2( createTable( 2, 4, 300, 200 ) );
54 std::unique_ptr<SCH_TABLE> table3( createTable( 2, 4, 100, 400 ) );
55
56 // Table1 should be < Table2 (different X positions)
57 BOOST_CHECK( *table1 < *table2 );
58 BOOST_CHECK( !( *table2 < *table1 ) );
59
60 // Table1 should be < Table3 (same X, different Y positions)
61 BOOST_CHECK( *table1 < *table3 );
62 BOOST_CHECK( !( *table3 < *table1 ) );
63
64 // Table2 should be > Table3 (X comparison takes precedence: 300 > 100)
65 BOOST_CHECK( *table3 < *table2 );
66 BOOST_CHECK( !( *table2 < *table3 ) );
67
68 // Test reflexivity: table should not be less than itself
69 BOOST_CHECK( !( *table1 < *table1 ) );
70 BOOST_CHECK( !( *table2 < *table2 ) );
71 BOOST_CHECK( !( *table3 < *table3 ) );
72}
73
74
75BOOST_AUTO_TEST_CASE( TableCompareOrdering )
76{
77 // Test that table comparison produces consistent ordering for sorting.
78
79 std::unique_ptr<SCH_TABLE> tableA( createTable( 2, 4, 100, 100 ) );
80 std::unique_ptr<SCH_TABLE> tableB( createTable( 2, 4, 200, 100 ) );
81 std::unique_ptr<SCH_TABLE> tableC( createTable( 2, 4, 100, 200 ) );
82 std::unique_ptr<SCH_TABLE> tableD( createTable( 2, 4, 200, 200 ) );
83
84 // Verify strict weak ordering for all pairs
85 // Each table should compare consistently against all others
86
87 // A < B (X: 100 < 200)
88 BOOST_CHECK( *tableA < *tableB );
89 BOOST_CHECK( !( *tableB < *tableA ) );
90
91 // A < C (same X, Y: 100 < 200)
92 BOOST_CHECK( *tableA < *tableC );
93 BOOST_CHECK( !( *tableC < *tableA ) );
94
95 // A < D (X: 100 < 200)
96 BOOST_CHECK( *tableA < *tableD );
97 BOOST_CHECK( !( *tableD < *tableA ) );
98
99 // B > C (X: 200 > 100)
100 BOOST_CHECK( *tableC < *tableB );
101 BOOST_CHECK( !( *tableB < *tableC ) );
102
103 // B < D (same X: 200, Y: 100 < 200)
104 BOOST_CHECK( *tableB < *tableD );
105 BOOST_CHECK( !( *tableD < *tableB ) );
106
107 // C < D (X: 100 < 200)
108 BOOST_CHECK( *tableC < *tableD );
109 BOOST_CHECK( !( *tableD < *tableC ) );
110}
111
112
113BOOST_AUTO_TEST_CASE( TableCompareByCellCount )
114{
115 // Tables with different cell counts should compare by cell count first
116
117 std::unique_ptr<SCH_TABLE> smallTable( createTable( 2, 4, 100, 100 ) );
118 std::unique_ptr<SCH_TABLE> largeTable( createTable( 3, 9, 100, 100 ) );
119
120 // Smaller table should be < larger table
121 BOOST_CHECK( *smallTable < *largeTable );
122 BOOST_CHECK( !( *largeTable < *smallTable ) );
123}
124
125
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
void SetPosition(const VECTOR2I &aPos) override
Definition sch_shape.h:85
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
std::vector< std::vector< std::string > > table
static SCH_TABLE * createTable(int aColCount, int aCellCount, int aX, int aY)
BOOST_AUTO_TEST_CASE(TableCompareByPosition)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683