KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_board_statistics.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 <board_statistics.h>
26#include <algorithm>
27#include <vector>
28
29
30BOOST_AUTO_TEST_SUITE( BoardStatistics )
31
32
33
37BOOST_AUTO_TEST_CASE( DrillCompareStrictWeakOrderingPlated )
38{
39 // Create test items with different plated values
40 DRILL_LINE_ITEM platedItem( 100, 100, PAD_DRILL_SHAPE::CIRCLE, true, true, F_Cu, B_Cu );
41 DRILL_LINE_ITEM unplatedItem( 100, 100, PAD_DRILL_SHAPE::CIRCLE, false, true, F_Cu, B_Cu );
42
43 platedItem.m_Qty = 1;
44 unplatedItem.m_Qty = 1;
45
46 // Test ascending comparator
48
49 // Strict weak ordering requirement 1: irreflexivity - compare(a, a) must be false
50 BOOST_CHECK( !cmpAsc( platedItem, platedItem ) );
51 BOOST_CHECK( !cmpAsc( unplatedItem, unplatedItem ) );
52
53 // Strict weak ordering requirement 2: asymmetry - if compare(a, b) then !compare(b, a)
54 bool aLessB = cmpAsc( unplatedItem, platedItem ); // false < true
55 bool bLessA = cmpAsc( platedItem, unplatedItem ); // true < false
56
57 BOOST_CHECK( aLessB != bLessA || (!aLessB && !bLessA) );
58
59 // Test that sorting works without crashing (this would cause undefined behavior with broken comparator)
60 std::vector<DRILL_LINE_ITEM> items;
61 items.push_back( platedItem );
62 items.push_back( unplatedItem );
63 items.push_back( platedItem );
64 items.push_back( unplatedItem );
65
66 BOOST_CHECK_NO_THROW( std::sort( items.begin(), items.end(), cmpAsc ) );
67
68 // Verify the sort order is correct: false (0) values should come before true (1) values
69 BOOST_CHECK( !items[0].isPlated );
70 BOOST_CHECK( !items[1].isPlated );
71 BOOST_CHECK( items[2].isPlated );
72 BOOST_CHECK( items[3].isPlated );
73
74 // Test descending order
76
77 BOOST_CHECK( !cmpDesc( platedItem, platedItem ) );
78 BOOST_CHECK( !cmpDesc( unplatedItem, unplatedItem ) );
79
80 BOOST_CHECK_NO_THROW( std::sort( items.begin(), items.end(), cmpDesc ) );
81
82 // Verify descending order: true (1) values should come before false (0) values
83 BOOST_CHECK( items[0].isPlated );
84 BOOST_CHECK( items[1].isPlated );
85 BOOST_CHECK( !items[2].isPlated );
86 BOOST_CHECK( !items[3].isPlated );
87}
88
89
94BOOST_AUTO_TEST_CASE( DrillCompareStrictWeakOrderingViaPad )
95{
96 // Create test items with different isPad values
97 DRILL_LINE_ITEM padItem( 100, 100, PAD_DRILL_SHAPE::CIRCLE, true, true, F_Cu, B_Cu );
98 DRILL_LINE_ITEM viaItem( 100, 100, PAD_DRILL_SHAPE::CIRCLE, true, false, F_Cu, B_Cu );
99
100 padItem.m_Qty = 1;
101 viaItem.m_Qty = 1;
102
103 // Test ascending comparator
105
106 // Strict weak ordering requirement 1: irreflexivity - compare(a, a) must be false
107 BOOST_CHECK( !cmpAsc( padItem, padItem ) );
108 BOOST_CHECK( !cmpAsc( viaItem, viaItem ) );
109
110 // Strict weak ordering requirement 2: asymmetry - if compare(a, b) then !compare(b, a)
111 bool aLessB = cmpAsc( viaItem, padItem ); // false < true
112 bool bLessA = cmpAsc( padItem, viaItem ); // true < false
113
114 BOOST_CHECK( aLessB != bLessA || (!aLessB && !bLessA) );
115
116 // Test that sorting works without crashing
117 std::vector<DRILL_LINE_ITEM> items;
118 items.push_back( padItem );
119 items.push_back( viaItem );
120 items.push_back( padItem );
121 items.push_back( viaItem );
122
123 BOOST_CHECK_NO_THROW( std::sort( items.begin(), items.end(), cmpAsc ) );
124
125 // Verify the sort order is correct: false (via) values should come before true (pad) values
126 BOOST_CHECK( !items[0].isPad );
127 BOOST_CHECK( !items[1].isPad );
128 BOOST_CHECK( items[2].isPad );
129 BOOST_CHECK( items[3].isPad );
130
131 // Test descending order
133
134 BOOST_CHECK( !cmpDesc( padItem, padItem ) );
135 BOOST_CHECK( !cmpDesc( viaItem, viaItem ) );
136
137 BOOST_CHECK_NO_THROW( std::sort( items.begin(), items.end(), cmpDesc ) );
138
139 // Verify descending order: true (pad) values should come before false (via) values
140 BOOST_CHECK( items[0].isPad );
141 BOOST_CHECK( items[1].isPad );
142 BOOST_CHECK( !items[2].isPad );
143 BOOST_CHECK( !items[3].isPad );
144}
145
146
@ B_Cu
Definition layer_ids.h:65
@ F_Cu
Definition layer_ids.h:64
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(DrillCompareStrictWeakOrderingPlated)
Test that DRILL_LINE_ITEM::COMPARE satisfies strict weak ordering for COL_PLATED.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()