KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_tuning_bridging_clamp.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
20
#include <boost/test/unit_test.hpp>
21
22
#include <limits>
23
24
#include <
base_units.h
>
25
#include <
core/minoptmax.h
>
26
#include <
net_chain_bridging.h
>
27
28
29
static
void
applyBridging
(
MINOPTMAX<int>
& aTarget,
long
long
aBridgingIU )
30
{
31
if
( aTarget.
HasMin
() )
32
aTarget.
SetMin
(
SubtractBridgingClamped
( aTarget.
Min
(), aBridgingIU ) );
33
34
if
( aTarget.
HasOpt
() )
35
aTarget.
SetOpt
(
SubtractBridgingClamped
( aTarget.
Opt
(), aBridgingIU ) );
36
37
if
( aTarget.
HasMax
() )
38
aTarget.
SetMax
(
SubtractBridgingClamped
( aTarget.
Max
(), aBridgingIU ) );
39
}
40
41
42
BOOST_AUTO_TEST_SUITE
( TuningBridgingClamp )
43
44
45
BOOST_AUTO_TEST_CASE
( TimeDomainAttosecondsClampsToZero )
46
{
47
constexpr
long
long
bridging = 3'000LL *
static_cast<
long
long
>
(
pcbIUScale
.IU_PER_PS );
48
49
BOOST_CHECK_GT( bridging,
static_cast<
long
long
>
( std::numeric_limits<int>::max() ) );
50
51
MINOPTMAX<int>
target;
52
target.
SetMin
( 1'000'000'000 );
53
target.
SetMax
( 1'200'000'000 );
54
55
applyBridging
( target, bridging );
56
57
BOOST_CHECK_EQUAL
( target.
Min
(), 0 );
58
BOOST_CHECK_EQUAL
( target.
Max
(), 0 );
59
}
60
61
62
BOOST_AUTO_TEST_CASE
( LengthModeUnaffectedWithinIntRange )
63
{
64
MINOPTMAX<int>
target;
65
target.
SetMin
( 100'000'000 );
66
target.
SetMax
( 120'000'000 );
67
68
applyBridging
( target, 5'000'000 );
69
70
BOOST_CHECK_EQUAL
( target.
Min
(), 95'000'000 );
71
BOOST_CHECK_EQUAL
( target.
Max
(), 115'000'000 );
72
}
73
74
75
BOOST_AUTO_TEST_CASE
( BridgingExceedsTargetFloorsAtZero )
76
{
77
MINOPTMAX<int>
target;
78
target.
SetMin
( 100 );
79
target.
SetMax
( 200 );
80
81
applyBridging
( target, 1'000'000'000LL );
82
83
BOOST_CHECK_EQUAL
( target.
Min
(), 0 );
84
BOOST_CHECK_EQUAL
( target.
Max
(), 0 );
85
}
86
87
88
// Pre-fix code truncated bridgingDelayIU to int, wrapping the value before subtraction;
89
// verify the long long path keeps the magnitude intact.
90
BOOST_AUTO_TEST_CASE
( WideArithmeticPreservesMagnitude )
91
{
92
constexpr
long
long
bridging = 500'000'000'000'000LL;
93
94
long
long
truncated =
static_cast<
long
long
>
(
static_cast<
int
>
( bridging ) );
95
96
BOOST_CHECK_NE( truncated, bridging );
97
98
MINOPTMAX<int>
target;
99
target.
SetMin
( 2'000'000'000 );
100
101
applyBridging
( target, bridging );
102
103
BOOST_CHECK_EQUAL
( target.
Min
(), 0 );
104
}
105
106
107
BOOST_AUTO_TEST_CASE
( OptStaysWithinMinMaxAfterBridging )
108
{
109
MINOPTMAX<int>
target;
110
target.
SetMin
( 100'000'000 );
111
target.
SetOpt
( 110'000'000 );
112
target.
SetMax
( 120'000'000 );
113
114
applyBridging
( target, 5'000'000 );
115
116
BOOST_CHECK_EQUAL
( target.
Min
(), 95'000'000 );
117
BOOST_CHECK_EQUAL
( target.
Opt
(), 105'000'000 );
118
BOOST_CHECK_EQUAL
( target.
Max
(), 115'000'000 );
119
120
BOOST_CHECK_LE( target.
Min
(), target.
Opt
() );
121
BOOST_CHECK_LE( target.
Opt
(), target.
Max
() );
122
}
123
124
125
BOOST_AUTO_TEST_CASE
( OptClampsToZeroWhenBridgingExceedsTarget )
126
{
127
MINOPTMAX<int>
target;
128
target.
SetMin
( 1'000'000'000 );
129
target.
SetOpt
( 1'100'000'000 );
130
target.
SetMax
( 1'200'000'000 );
131
132
constexpr
long
long
bridging = 3'000LL *
static_cast<
long
long
>
(
pcbIUScale
.IU_PER_PS );
133
134
applyBridging
( target, bridging );
135
136
BOOST_CHECK_EQUAL
( target.
Min
(), 0 );
137
BOOST_CHECK_EQUAL
( target.
Opt
(), 0 );
138
BOOST_CHECK_EQUAL
( target.
Max
(), 0 );
139
}
140
141
142
BOOST_AUTO_TEST_SUITE_END
()
base_units.h
pcbIUScale
constexpr EDA_IU_SCALE pcbIUScale
Definition
base_units.h:121
MINOPTMAX
Definition
minoptmax.h:27
MINOPTMAX::Min
T Min() const
Definition
minoptmax.h:29
MINOPTMAX::SetMin
void SetMin(T v)
Definition
minoptmax.h:37
MINOPTMAX::HasMax
bool HasMax() const
Definition
minoptmax.h:34
MINOPTMAX::SetOpt
void SetOpt(T v)
Definition
minoptmax.h:39
MINOPTMAX::HasMin
bool HasMin() const
Definition
minoptmax.h:33
MINOPTMAX::SetMax
void SetMax(T v)
Definition
minoptmax.h:38
MINOPTMAX::Max
T Max() const
Definition
minoptmax.h:30
MINOPTMAX::Opt
T Opt() const
Definition
minoptmax.h:31
MINOPTMAX::HasOpt
bool HasOpt() const
Definition
minoptmax.h:35
minoptmax.h
net_chain_bridging.h
SubtractBridgingClamped
int SubtractBridgingClamped(int aValue, long long aDelta)
Saturating subtract for bridge-adjusting MINOPTMAX<int> bounds without overflow when the delta is in ...
Definition
net_chain_bridging.h:90
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
applyBridging
static void applyBridging(MINOPTMAX< int > &aTarget, long long aBridgingIU)
Definition
test_tuning_bridging_clamp.cpp:29
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(TimeDomainAttosecondsClampsToZero)
Definition
test_tuning_bridging_clamp.cpp:45
src
qa
tests
pcbnew
net_chains
test_tuning_bridging_clamp.cpp
Generated on Fri Jun 26 2026 00:05:45 for KiCad PCB EDA Suite by
1.13.2