-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis_test.go
More file actions
139 lines (112 loc) · 3.23 KB
/
Copy pathanalysis_test.go
File metadata and controls
139 lines (112 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package resistor
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestAnalyzeResistor_NonPositiveResistance(t *testing.T) {
_, err := AnalyzeResistor(AnalysisInput{Spec: ResistorSpec{ResistanceOhms: 0}})
require.Error(t, err)
}
func TestAnalyzeResistor_VoltageDriven(t *testing.T) {
input := AnalysisInput{
Spec: ResistorSpec{
ResistanceOhms: 100,
PowerWatts: 0.5,
TolerancePct: 5,
},
AppliedVoltage: 10,
}
report, err := AnalyzeResistor(input)
require.NoError(t, err)
require.InDelta(t, 0.1, report.Current, 1e-9)
require.InDelta(t, 1.0, report.PowerDissipation, 1e-9)
require.NotNil(t, report.WorstCaseResistanceMin)
require.Equal(t, 95.0, *report.WorstCaseResistanceMin)
require.NotNil(t, report.WorstCaseResistanceMax)
require.Equal(t, 105.0, *report.WorstCaseResistanceMax)
require.NotEmpty(t, report.Warnings)
}
func TestAnalyzeResistor_CurrentDriven(t *testing.T) {
input := AnalysisInput{
Spec: ResistorSpec{
ResistanceOhms: 50,
},
AppliedCurrent: 0.2,
}
report, err := AnalyzeResistor(input)
require.NoError(t, err)
require.InDelta(t, 10.0, report.VoltageDrop, 1e-9)
require.InDelta(t, 2.0, report.PowerDissipation, 1e-9)
}
func TestAnalyzeResistor_DeratingWarnings(t *testing.T) {
input := AnalysisInput{
Spec: ResistorSpec{
ResistanceOhms: 100,
PowerWatts: 0.25,
},
AppliedVoltage: 10,
}
report, err := AnalyzeResistor(input)
require.NoError(t, err)
require.NotEmpty(t, report.Warnings)
}
func TestAnalyzeResistor_OhmsLawConsistency(t *testing.T) {
// V and I that disagree by more than 1%: V=10, I=0.001, R=100 → expected V=0.1
inconsistent := AnalysisInput{
Spec: ResistorSpec{ResistanceOhms: 100},
AppliedVoltage: 10,
AppliedCurrent: 0.001,
}
report, err := AnalyzeResistor(inconsistent)
require.NoError(t, err)
var found bool
for _, w := range report.Warnings {
if w.Level == WarningCaution {
found = true
break
}
}
require.True(t, found, "expected a WarningCaution for inconsistent V/I")
// V and I that agree within 1%: V=10, I=0.1, R=100 → exactly consistent
consistent := AnalysisInput{
Spec: ResistorSpec{ResistanceOhms: 100},
AppliedVoltage: 10,
AppliedCurrent: 0.1,
}
report2, err := AnalyzeResistor(consistent)
require.NoError(t, err)
for _, w := range report2.Warnings {
require.NotEqual(t, WarningCaution, w.Level, "consistent V/I should not produce a WarningCaution from Ohm's Law check")
}
}
func TestAnalyzeResistor_DeratingCaution(t *testing.T) {
// Pdiss (1W) > DeratedSafePower (0.75W) but < PowerWatts (1.5W) → caution
input := AnalysisInput{
Spec: ResistorSpec{
ResistanceOhms: 100,
PowerWatts: 1.5,
},
AppliedVoltage: 10,
}
report, err := AnalyzeResistor(input)
require.NoError(t, err)
var found bool
for _, w := range report.Warnings {
if w.Level == WarningCaution {
found = true
break
}
}
require.True(t, found, "expected WarningCaution for dissipation exceeding 50%% derate")
}
func TestAnalyzeResistor_NoInputs(t *testing.T) {
input := AnalysisInput{
Spec: ResistorSpec{
ResistanceOhms: 100,
},
}
report, err := AnalyzeResistor(input)
require.NoError(t, err)
require.Equal(t, 0.0, report.PowerDissipation)
require.NotEmpty(t, report.Warnings)
}