Files
cheesy-arena-lite/plc/plc_test.go

66 lines
2.1 KiB
Go
Raw Normal View History

// Copyright 2017 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
2018-09-03 19:12:22 -07:00
package plc
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestByteToBool(t *testing.T) {
bytes := []byte{7, 254, 3}
bools := byteToBool(bytes, 17)
if assert.Equal(t, 17, len(bools)) {
expectedBools := []bool{true, true, true, false, false, false, false, false, false, true, true, true, true,
true, true, true, true}
assert.Equal(t, expectedBools, bools)
}
}
func TestByteToUint(t *testing.T) {
bytes := []byte{1, 77, 2, 253, 21, 179}
uints := byteToUint(bytes, 3)
if assert.Equal(t, 3, len(uints)) {
assert.Equal(t, []uint16{333, 765, 5555}, uints)
}
}
func TestBoolToByte(t *testing.T) {
bools := []bool{true, true, false, false, true, false, false, false, false, true}
bytes := boolToByte(bools)
if assert.Equal(t, 2, len(bytes)) {
assert.Equal(t, []byte{19, 2}, bytes)
assert.Equal(t, bools, byteToBool(bytes, len(bools)))
}
}
func TestGetArmorBlockStatuses(t *testing.T) {
var plc Plc
plc.registers[fieldIoConnection] = 0
2020-04-14 19:38:14 -05:00
assert.Equal(t, map[string]bool{"RedDs": false, "BlueDs": false},
plc.GetArmorBlockStatuses())
plc.registers[fieldIoConnection] = 1
2020-04-14 19:38:14 -05:00
assert.Equal(t, map[string]bool{"RedDs": true, "BlueDs": false},
plc.GetArmorBlockStatuses())
plc.registers[fieldIoConnection] = 2
2020-04-14 19:38:14 -05:00
assert.Equal(t, map[string]bool{"RedDs": false, "BlueDs": true},
plc.GetArmorBlockStatuses())
plc.registers[fieldIoConnection] = 4
2020-04-14 19:38:14 -05:00
assert.Equal(t, map[string]bool{"RedDs": false, "BlueDs": false},
plc.GetArmorBlockStatuses())
plc.registers[fieldIoConnection] = 8
2020-04-14 19:38:14 -05:00
assert.Equal(t, map[string]bool{"RedDs": false, "BlueDs": false},
plc.GetArmorBlockStatuses())
plc.registers[fieldIoConnection] = 5
2020-04-14 19:38:14 -05:00
assert.Equal(t, map[string]bool{"RedDs": true, "BlueDs": false},
plc.GetArmorBlockStatuses())
plc.registers[fieldIoConnection] = 10
2020-04-14 19:38:14 -05:00
assert.Equal(t, map[string]bool{"RedDs": false, "BlueDs": true},
plc.GetArmorBlockStatuses())
plc.registers[fieldIoConnection] = 15
2020-04-14 19:38:14 -05:00
assert.Equal(t, map[string]bool{"RedDs": true, "BlueDs": true},
plc.GetArmorBlockStatuses())
}