KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_increment.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
22#include <increment.h>
23
24
28BOOST_AUTO_TEST_SUITE( StringIncrement )
29
30
32{
33 wxString input;
34 int delta;
35 size_t part;
36 wxString expected;
37};
38
39
44{
45 const std::vector<INCREMENT_TEST_CASE> cases{
46 // Null
47 { "", 1, 0, "nullopt" },
48 { "", 1, 1, "nullopt" },
49 { "", -1, 1, "nullopt" },
50 // Up
51 { "1", 1, 0, "2" },
52 { "1", 9, 0, "10" },
53 // Down
54 { "2", -1, 0, "1" },
55 { "10", -1, 0, "9" },
56 // Down from 0
57 { "0", -1, 0, "nullopt" },
58 // Ran out of a parts
59 { "1", 1, 1, "nullopt" },
60 // Leading zeros preserved
61 { "01", 1, 0, "02" },
62 // Alpha
63 { "A", 1, 0, "B" },
64 { "E", -1, 0, "D" },
65 // Skip I
66 { "H", 1, 0, "J" },
67 { "J", -1, 0, "H" },
68 // But I works if it's there
69 { "I", 1, 0, "J" },
70 { "I", -1, 0, "H" },
71 // Alpha wrap
72 { "Z", 1, 0, "AA" },
73 // Reject huge alphabetic value
74 { "ABB", 1, 0, "nullopt" },
75 // Dashes skipped
76 { "A-1", 1, 0, "A-2" },
77 { "A-1", 1, 1, "B-1" },
78 // Mixed alphabetic+numeric string behavior
79 { "A12", 1, 0, "A13" },
80 { "A12", -1, 0, "A11" },
81 { "A12", 1, 1, "B12" },
82 { "A12", -1, 1, "nullopt" },
83 };
84
85 STRING_INCREMENTER incrementer;
86 incrementer.SetSkipIOSQXZ( true );
87
88 for( const auto& c : cases )
89 {
90 BOOST_TEST_INFO( "Input: " << c.input << " Delta: " << c.delta << " Part: " << c.part );
91 wxString result = incrementer.Increment( c.input, c.delta, c.part ).value_or( "nullopt" );
92 BOOST_CHECK_EQUAL( result, c.expected );
93 }
94}
95
96
98{
99 wxString input;
100 const wxString& alphabet;
102};
103
104
105BOOST_AUTO_TEST_CASE( AlphabeticIndexes )
106{
107 const wxString alphabet = "ABCDEFGHJKLMNPRTUVWY";
108
109 const std::vector<ALPHABETIC_TEST_CASE> cases{ {
110 { "A", alphabet, 0 },
111 { "B", alphabet, 1 },
112 { "Y", alphabet, 19 },
113 { "AA", alphabet, 20 },
114 { "AY", alphabet, 39 },
115 } };
116
117 for( const auto& c : cases )
118 {
119 BOOST_TEST_INFO( "Input: " << c.input << " <-> " << c.expected );
120
121 const int fromString = IndexFromAlphabetic( c.input, c.alphabet );
122 BOOST_CHECK_EQUAL( fromString, c.expected );
123
124 const wxString fromIndex = AlphabeticFromIndex( c.expected, c.alphabet, true );
125 BOOST_CHECK_EQUAL( fromIndex, c.input );
126 }
127}
128
129
Heuristically increment a string's n'th part from the right.
Definition increment.h:44
void SetSkipIOSQXZ(bool aSkip)
If a alphabetic part is found, skip the letters I, O, S, Q, X, Z.
Definition increment.h:50
std::optional< wxString > Increment(const wxString &aStr, int aDelta, size_t aRightIndex) const
Increment the n-th part from the right of the given string.
Definition increment.cpp:82
KICOMMON_API int IndexFromAlphabetic(const wxString &aStr, const wxString &aAlphabet)
Attempt to convert a string to an integer, assuming it is an alphabetic string like "A",...
wxString KICOMMON_API AlphabeticFromIndex(size_t aN, const wxString &aAlphabet, bool aZeroBasedNonUnitCols)
Get an alphabetic string like A, B, ... Z, AA, AB, ... ZZ, AAA, ...
const wxString & alphabet
Declares a struct as the Boost test fixture.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(BasicCase)
Check formatting the point.
BOOST_TEST_INFO("Two-port Series .op current = "<< iDevice)
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")