-
-
Notifications
You must be signed in to change notification settings - Fork 670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom charger: add typical meter measurements #14546
Conversation
Wow, der PR hat 27000 Zeilen generierten Code geändert. Langsam mache ich mir Sorgen! UPDATE binary geht von 103MB auf 117MB auf dem Mac. Das ist leider ein No-Go! @GrimmiMeloni dazu fällt dir auch nichts ein, oder? |
28200a1
to
806d851
Compare
Zwei (hässliche) Optimierungsideen fallen mir ein:
|
@GrimmiMeloni I've prototyped the idea above. This does work: func TestMeterDecoration(t *testing.T) {
ctrl := gomock.NewController(t)
type chargerStruct = struct {
api.Charger
api.PhaseSwitcher
}
charger := chargerStruct{
api.NewMockCharger(ctrl),
api.NewMockPhaseSwitcher(ctrl),
}
assert.Implements(t, (*api.Charger)(nil), charger)
assert.Implements(t, (*api.PhaseSwitcher)(nil), charger)
meter := api.NewMockMeter(ctrl)
combined := struct {
chargerStruct
api.Meter
}{
charger,
meter,
}
assert.Implements(t, (*api.Charger)(nil), combined)
assert.Implements(t, (*api.PhaseSwitcher)(nil), combined)
assert.Implements(t, (*api.Meter)(nil), combined)
} while this doesn't: func TestMeterDecoration(t *testing.T) {
ctrl := gomock.NewController(t)
charger := struct {
api.Charger
api.PhaseSwitcher
}{
api.NewMockCharger(ctrl),
api.NewMockPhaseSwitcher(ctrl),
}
assert.Implements(t, (*api.Charger)(nil), charger)
assert.Implements(t, (*api.PhaseSwitcher)(nil), charger)
meter := api.NewMockMeter(ctrl)
combined := struct {
api.Charger
api.Meter
}{
charger,
meter,
}
assert.Implements(t, (*api.Charger)(nil), combined)
assert.Implements(t, (*api.PhaseSwitcher)(nil), combined)
assert.Implements(t, (*api.Meter)(nil), combined)
} This makes me think that it might work to partition the combinations and build a combined type of specific charger and meter sub types. |
Testcase nochmal aktualisiert: package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
type If1 interface {
F1()
}
type If1Impl struct{}
func (i *If1Impl) F1() {
}
type If2 interface {
F2()
}
type If2Impl struct{}
func (i *If2Impl) F2() {
}
type If3 interface {
F3()
}
type If3Impl struct{}
func (i *If3Impl) F3() {
}
type If12 interface {
If1
If2
}
func TestEmbedding(t *testing.T) {
type if12T struct {
If1
If2
}
if12 := if12T{
new(If1Impl),
new(If2Impl),
}
meter := new(If3Impl)
check := func(i any, msg string) {
assert.Implements(t, (*If1)(nil), i, msg)
assert.Implements(t, (*If2)(nil), i, msg)
assert.Implements(t, (*If3)(nil), i, msg)
}
structs := struct {
*if12T
If3
}{
&if12,
meter,
}
check(structs, "structs")
interfaces := struct {
If12
If3
}{
if12,
meter,
}
check(interfaces, "interfaces")
interfaces2 := struct {
If1
If3
}{
if12,
meter,
}
check(interfaces2, "implicit interfaces")
} ergibt:
|
Fix #14508