KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sim_model_inference.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 (C) 2022-2023 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 <sim/sim_model.h>
26#include <lib_pin.h>
27
29{
30public:
32 {}
33};
34
35
36BOOST_FIXTURE_TEST_SUITE( SimModelInference, TEST_SIM_MODEL_INFERENCE )
37
38
39BOOST_AUTO_TEST_CASE( InferPassiveValues )
40{
41 struct PASSIVE_VALUE_TEST_CASE
42 {
43 wxString reference;
44 wxString value;
45 wxString result;
46 };
47
48 const std::vector<PASSIVE_VALUE_TEST_CASE> testCases =
49 {
50 { wxString( "C1" ), wxString( "33M" ), wxString( "c=\"33Meg\"" ) },
51 { wxString( "C2" ), wxString( "33m" ), wxString( "c=\"33m\"" ) },
52 { wxString( "C3" ), wxString( "33Meg" ), wxString( "c=\"33Meg\"" ) },
53
54 { wxString( "C4" ), wxString( "33,000uF" ), wxString( "c=\"33000u\"" ) },
55 { wxString( "C5" ), wxString( "3,300uF" ), wxString( "c=\"3300u\"" ) },
56 { wxString( "C6" ), wxString( "33000uF" ), wxString( "c=\"33000u\"" ) },
57 { wxString( "C7" ), wxString( "3300uF" ), wxString( "c=\"3300u\"" ) },
58 { wxString( "C8" ), wxString( "3.3uF" ), wxString( "c=\"3.3u\"" ) },
59 { wxString( "C9" ), wxString( "3,3uF" ), wxString( "c=\"3.3u\"" ) },
60 { wxString( "C10" ), wxString( "3,32uF" ), wxString( "c=\"3.32u\"" ) },
61
62 { wxString( "C11" ), wxString( "3u3" ), wxString( "c=\"3.3u\"" ) },
63 { wxString( "C12" ), wxString( "3p3" ), wxString( "c=\"3.3p\"" ) },
64 { wxString( "C13" ), wxString( "3u32" ), wxString( "c=\"3.32u\"" ) },
65
66 { wxString( "R1" ), wxString( "3R3" ), wxString( "r=\"3.3\"" ) },
67 { wxString( "R2" ), wxString( "3K3" ), wxString( "r=\"3.3K\"" ) },
68 { wxString( "R3" ), wxString( "3K32" ), wxString( "r=\"3.32K\"" ) },
69
70 { wxString( "R4" ), wxString( "3,000.5" ), wxString( "r=\"3000.5\"" ) },
71 { wxString( "R5" ), wxString( "3.000,5" ), wxString( "r=\"3000.5\"" ) },
72 { wxString( "R6" ), wxString( "3000.5" ), wxString( "r=\"3000.5\"" ) },
73 { wxString( "R7" ), wxString( "3,000K" ), wxString( "r=\"3000K\"" ) },
74 { wxString( "R8" ), wxString( "3.000K" ), wxString( "r=\"3.000K\"" ) },
75 { wxString( "R9" ), wxString( "3.0,000,000" ), wxString( "" ) },
76
77 { wxString( "X1" ), wxString( "3.3K" ), wxString( "" ) },
78
79 { wxString( "C14" ), wxString( "33,000,000uF" ), wxString( "c=\"33000000u\"" ) },
80 { wxString( "C15" ), wxString( "33 000 000uF" ), wxString( "c=\"33000000u\"" ) },
81 { wxString( "C16" ), wxString( "33.000,000uF" ), wxString( "c=\"33000.000u\"" )},
82 };
83
84 std::unique_ptr<LIB_SYMBOL> symbol = std::make_unique<LIB_SYMBOL>( "symbol", nullptr );
85 symbol->AddDrawItem( new LIB_PIN( symbol.get() ) );
86 symbol->AddDrawItem( new LIB_PIN( symbol.get() ) );
87
88 wxString deviceType;
89 wxString modelType;
90 wxString modelParams;
91 wxString pinMap;
92 wxString msg;
93
94 for( const auto& testCase : testCases )
95 {
96 symbol->GetReferenceField().SetText( testCase.reference );
97 symbol->GetValueField().SetText( testCase.value );
98
99 std::vector<LIB_FIELD> fields;
100 fields.emplace_back( symbol->GetReferenceField() );
101 fields.emplace_back( symbol->GetValueField() );
102
104 &deviceType, &modelType, &modelParams, &pinMap );
105
106 msg.Printf( "Passive model inference %s %s failed [%s != %s]",
107 testCase.reference,
108 testCase.value,
109 modelParams,
110 testCase.result );
111 BOOST_CHECK_MESSAGE( modelParams == testCase.result, msg.ToStdString() );
112 }
113}
114
115
116BOOST_AUTO_TEST_SUITE_END()
static bool InferSimModel(T_symbol &aSymbol, std::vector< T_field > *aFields, bool aResolve, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
Definition: sim_model.cpp:1140
BOOST_AUTO_TEST_CASE(InferPassiveValues)