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