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