89 lines
3.3 KiB
Go
89 lines
3.3 KiB
Go
package circuit_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/rtsssimulation/component"
|
|
"math/rand"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
func Test_mkxBtnDriveRelay(t *testing.T) {
|
|
for i := 0; i < 100; i++ {
|
|
mkx, pmc, psdCircuit := generateTestCase()
|
|
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
|
mkxBtnDriveRelay(mkx, pmc, psdCircuit)
|
|
if component.BitStateType.Get(mkx.PCB).Val && !component.BitStateType.Get(mkx.PCBPL).Val != component.RelayDriveType.Get(pmc.PCBJ).Td {
|
|
panic("PCB对应的继电器状态不对")
|
|
}
|
|
if component.BitStateType.Get(mkx.POB).Val && !component.BitStateType.Get(mkx.POBPL).Val != component.RelayDriveType.Get(pmc.POBJ).Td {
|
|
panic("POB对应的继电器状态不对")
|
|
}
|
|
if component.BitStateType.Get(mkx.PAB).Val && !component.BitStateType.Get(mkx.PABPL).Val != component.RelayDriveType.Get(pmc.PABJ).Td {
|
|
panic("PAB对应的继电器状态不对")
|
|
}
|
|
if component.BitStateType.Get(mkx.WRZF).Val && !component.BitStateType.Get(mkx.WRZFPL).Val != component.RelayDriveType.Get(pmc.WRZFJ).Td {
|
|
panic("WRZF对应的继电器状态不对")
|
|
}
|
|
if component.BitStateType.Get(mkx.QKQR).Val && !component.BitStateType.Get(mkx.QKQRPL).Val != component.RelayDriveType.Get(pmc.QKQRJ).Td {
|
|
panic("QKQR对应的继电器状态不对")
|
|
}
|
|
})
|
|
i++
|
|
}
|
|
}
|
|
|
|
func generateTestCase() (*component.Mkx, *component.PlatformMkxCircuit, *component.PsdCircuit) {
|
|
world := ecs.NewWorld(100)
|
|
mkx := &component.Mkx{
|
|
PCB: newButtonEntity(world, "PCB", rand.Int()%2 == 0),
|
|
PCBPL: newButtonEntity(world, "PCBPL", rand.Int()%2 == 0),
|
|
POB: newButtonEntity(world, "POB", rand.Int()%2 == 0),
|
|
POBPL: newButtonEntity(world, "POBPL", rand.Int()%2 == 0),
|
|
PAB: newButtonEntity(world, "PAB", rand.Int()%2 == 0),
|
|
PABPL: newButtonEntity(world, "PABPL", rand.Int()%2 == 0),
|
|
WRZF: newButtonEntity(world, "WRZF", rand.Int()%2 == 0),
|
|
WRZFPL: newButtonEntity(world, "WRZFPL", rand.Int()%2 == 0),
|
|
QKQR: newButtonEntity(world, "QKQR", rand.Int()%2 == 0),
|
|
QKQRPL: newButtonEntity(world, "QKQRPL", rand.Int()%2 == 0),
|
|
MPL: newButtonEntity(world, "MPL", rand.Int()%2 == 0),
|
|
JXTCPL: newButtonEntity(world, "JXTCPL", rand.Int()%2 == 0),
|
|
}
|
|
rand.Int()
|
|
pmc := &component.PlatformMkxCircuit{
|
|
MkxList: nil,
|
|
PCBJ: newRelayEntry(world, "PCBJ"),
|
|
POBJ: newRelayEntry(world, "POBJ"),
|
|
PABJ: newRelayEntry(world, "PABJ"),
|
|
WRZFJ: newRelayEntry(world, "WRZFJ"),
|
|
QKQRJ: newRelayEntry(world, "QKQRJ"),
|
|
}
|
|
psdCircuit := &component.PsdCircuit{
|
|
GMJ: nil,
|
|
KMJMap: nil,
|
|
MGJ: nil,
|
|
MPLJ: newRelayEntry(world, "MPLJ"),
|
|
QDTCJ: nil,
|
|
TZTCJ: nil,
|
|
ZAWJ: nil,
|
|
JXTCPLJ: newRelayEntry(world, "JXTCPLJ"),
|
|
UnusedJ: nil,
|
|
}
|
|
return mkx, pmc, psdCircuit
|
|
}
|
|
|
|
func newRelayEntry(w ecs.World, uid string) *ecs.Entry {
|
|
entry := w.Entry(w.Create(component.RelayTag, component.UidType, component.RelayDriveType, component.BitStateType))
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
|
entry.AddComponent(component.YjRelayTag)
|
|
return entry
|
|
}
|
|
|
|
func newButtonEntity(w ecs.World, uid string, val bool) *ecs.Entry {
|
|
btnType := component.NoResetPressBtn
|
|
entry := w.Entry(w.Create(component.ButtonTag, btnType, component.UidType, component.BitStateType))
|
|
component.UidType.SetValue(entry, component.Uid{Id: uid})
|
|
component.BitStateType.SetValue(entry, component.BitState{Val: val})
|
|
return entry
|
|
}
|