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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <sch_table.h>
26#include <sch_tablecell.h>
27
28
29BOOST_AUTO_TEST_SUITE( SchTable )
30
31
32static SCH_TABLE* createTable( int aColCount, int aCellCount, int aX, int aY )
33{
34 SCH_TABLE* table = new SCH_TABLE( schIUScale.mmToIU( 0.1 ) );
35 table->SetColCount( aColCount );
36
37 for( int i = 0; i < aCellCount; ++i )
38 {
39 SCH_TABLECELL* cell = new SCH_TABLECELL();
40
41 if( i == 0 )
42 cell->SetPosition( VECTOR2I( aX, aY ) );
43
44 table->AddCell( cell );
45 }
46
47 return table;
48}
49
50
51BOOST_AUTO_TEST_CASE( TableCompareByPosition )
52{
53 // Issue 22559: Tables with different positions were not compared correctly because
54 // operator< had bugs comparing positions (comparing self to self instead of other).
55
56 std::unique_ptr<SCH_TABLE> table1( createTable( 2, 4, 100, 200 ) );
57 std::unique_ptr<SCH_TABLE> table2( createTable( 2, 4, 300, 200 ) );
58 std::unique_ptr<SCH_TABLE> table3( createTable( 2, 4, 100, 400 ) );
59
60 // Table1 should be < Table2 (different X positions)
61 BOOST_CHECK( *table1 < *table2 );
62 BOOST_CHECK( !( *table2 < *table1 ) );
63
64 // Table1 should be < Table3 (same X, different Y positions)
65 BOOST_CHECK( *table1 < *table3 );
66 BOOST_CHECK( !( *table3 < *table1 ) );
67
68 // Table2 should be > Table3 (X comparison takes precedence: 300 > 100)
69 BOOST_CHECK( *table3 < *table2 );
70 BOOST_CHECK( !( *table2 < *table3 ) );
71
72 // Test reflexivity: table should not be less than itself
73 BOOST_CHECK( !( *table1 < *table1 ) );
74 BOOST_CHECK( !( *table2 < *table2 ) );
75 BOOST_CHECK( !( *table3 < *table3 ) );
76}
77
78
79BOOST_AUTO_TEST_CASE( TableCompareOrdering )
80{
81 // Test that table comparison produces consistent ordering for sorting.
82
83 std::unique_ptr<SCH_TABLE> tableA( createTable( 2, 4, 100, 100 ) );
84 std::unique_ptr<SCH_TABLE> tableB( createTable( 2, 4, 200, 100 ) );
85 std::unique_ptr<SCH_TABLE> tableC( createTable( 2, 4, 100, 200 ) );
86 std::unique_ptr<SCH_TABLE> tableD( createTable( 2, 4, 200, 200 ) );
87
88 // Verify strict weak ordering for all pairs
89 // Each table should compare consistently against all others
90
91 // A < B (X: 100 < 200)
92 BOOST_CHECK( *tableA < *tableB );
93 BOOST_CHECK( !( *tableB < *tableA ) );
94
95 // A < C (same X, Y: 100 < 200)
96 BOOST_CHECK( *tableA < *tableC );
97 BOOST_CHECK( !( *tableC < *tableA ) );
98
99 // A < D (X: 100 < 200)
100 BOOST_CHECK( *tableA < *tableD );
101 BOOST_CHECK( !( *tableD < *tableA ) );
102
103 // B > C (X: 200 > 100)
104 BOOST_CHECK( *tableC < *tableB );
105 BOOST_CHECK( !( *tableB < *tableC ) );
106
107 // B < D (same X: 200, Y: 100 < 200)
108 BOOST_CHECK( *tableB < *tableD );
109 BOOST_CHECK( !( *tableD < *tableB ) );
110
111 // C < D (X: 100 < 200)
112 BOOST_CHECK( *tableC < *tableD );
113 BOOST_CHECK( !( *tableD < *tableC ) );
114}
115
116
117BOOST_AUTO_TEST_CASE( TableCompareByCellCount )
118{
119 // Tables with different cell counts should compare by cell count first
120
121 std::unique_ptr<SCH_TABLE> smallTable( createTable( 2, 4, 100, 100 ) );
122 std::unique_ptr<SCH_TABLE> largeTable( createTable( 3, 9, 100, 100 ) );
123
124 // Smaller table should be < larger table
125 BOOST_CHECK( *smallTable < *largeTable );
126 BOOST_CHECK( !( *largeTable < *smallTable ) );
127}
128
129
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
void SetPosition(const VECTOR2I &aPos) override
Definition sch_shape.h:86
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
static SCH_TABLE * createTable(int aColCount, int aCellCount, int aX, int aY)
BOOST_AUTO_TEST_CASE(TableCompareByPosition)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695