gh-14 Tests for newRegister
This commit is contained in:
parent
b8929f6211
commit
a4fcbdc2ed
|
@ -16,8 +16,9 @@ func TestNewCoil(t *testing.T) {
|
||||||
typ := fmt.Sprintf("%T", coil)
|
typ := fmt.Sprintf("%T", coil)
|
||||||
// Assert newCoil returns pingvinKL.pingvinCoil
|
// Assert newCoil returns pingvinKL.pingvinCoil
|
||||||
if typ != "pingvinKL.pingvinCoil" {
|
if typ != "pingvinKL.pingvinCoil" {
|
||||||
t.Errorf("newCoil returned %s, expecting pingvinCoil", typ)
|
t.Errorf("newCoil returned %s, expecting pingvinKL.pingvinCoil", typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert Address is int and matches CSV
|
// Assert Address is int and matches CSV
|
||||||
addrtype := fmt.Sprintf("%T", coil.Address)
|
addrtype := fmt.Sprintf("%T", coil.Address)
|
||||||
if addrtype != "int" {
|
if addrtype != "int" {
|
||||||
|
@ -27,6 +28,7 @@ func TestNewCoil(t *testing.T) {
|
||||||
if coil.Address != iaddr {
|
if coil.Address != iaddr {
|
||||||
t.Errorf("coil.Address is %d, expecting %d", coil.Address, iaddr)
|
t.Errorf("coil.Address is %d, expecting %d", coil.Address, iaddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert Symbol is string and matches CSV
|
// Assert Symbol is string and matches CSV
|
||||||
symboltype := fmt.Sprintf("%T", coil.Symbol)
|
symboltype := fmt.Sprintf("%T", coil.Symbol)
|
||||||
if symboltype != "string" {
|
if symboltype != "string" {
|
||||||
|
@ -35,6 +37,7 @@ func TestNewCoil(t *testing.T) {
|
||||||
if coil.Symbol != symbol {
|
if coil.Symbol != symbol {
|
||||||
t.Errorf("coil.Symbol is %s, expecting %s", coil.Symbol, symbol)
|
t.Errorf("coil.Symbol is %s, expecting %s", coil.Symbol, symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert Description is string and matches CSV
|
// Assert Description is string and matches CSV
|
||||||
descriptiontype := fmt.Sprintf("%T", coil.Description)
|
descriptiontype := fmt.Sprintf("%T", coil.Description)
|
||||||
if descriptiontype != "string" {
|
if descriptiontype != "string" {
|
||||||
|
@ -43,6 +46,7 @@ func TestNewCoil(t *testing.T) {
|
||||||
if coil.Description != description {
|
if coil.Description != description {
|
||||||
t.Errorf("coil.Description is %s, expecting %s", coil.Description, description)
|
t.Errorf("coil.Description is %s, expecting %s", coil.Description, description)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert Value is boolean and false
|
// Assert Value is boolean and false
|
||||||
valuetype := fmt.Sprintf("%T", coil.Value)
|
valuetype := fmt.Sprintf("%T", coil.Value)
|
||||||
if valuetype != "bool" {
|
if valuetype != "bool" {
|
||||||
|
@ -51,10 +55,11 @@ func TestNewCoil(t *testing.T) {
|
||||||
if coil.Value != false {
|
if coil.Value != false {
|
||||||
t.Errorf("coil.Value is %t, expecting false", coil.Value)
|
t.Errorf("coil.Value is %t, expecting false", coil.Value)
|
||||||
}
|
}
|
||||||
// Assert Reserved is bool and true
|
|
||||||
|
// Assert Reserved is bool and false
|
||||||
reservedtype := fmt.Sprintf("%T", coil.Reserved)
|
reservedtype := fmt.Sprintf("%T", coil.Reserved)
|
||||||
if reservedtype != "bool" {
|
if reservedtype != "bool" {
|
||||||
t.Errorf("coil.Reserved is of type %s, expecting bool", typ)
|
t.Errorf("coil.Reserved is of type %s, expecting bool", reservedtype)
|
||||||
}
|
}
|
||||||
if coil.Reserved != false {
|
if coil.Reserved != false {
|
||||||
t.Errorf("coil.Reserved is %t, expecting false", coil.Reserved)
|
t.Errorf("coil.Reserved is %t, expecting false", coil.Reserved)
|
||||||
|
@ -77,3 +82,74 @@ func TestNewReservedCoil(t *testing.T) {
|
||||||
t.Errorf("coil.Reserved is %t, expecting true", coil.Reserved)
|
t.Errorf("coil.Reserved is %t, expecting true", coil.Reserved)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewRegister(t *testing.T) {
|
||||||
|
data := readCsvLines("../registers.csv")
|
||||||
|
addr := data[4][0]
|
||||||
|
symbol := data[4][1]
|
||||||
|
regtype := data[4][2]
|
||||||
|
description := data[4][6]
|
||||||
|
|
||||||
|
hreg := newRegister(addr, symbol, regtype, description)
|
||||||
|
|
||||||
|
// Assert newRegister returns pingvinKL.pingvinRegister
|
||||||
|
typ := fmt.Sprintf("%T", hreg)
|
||||||
|
if typ != "pingvinKL.pingvinRegister" {
|
||||||
|
t.Errorf("newRegister returned %s, expecting pingvinKL.pingvinRegister", typ)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert Address is int and matches CSV
|
||||||
|
addrtype := fmt.Sprintf("%T", hreg.Address)
|
||||||
|
if addrtype != "int" {
|
||||||
|
t.Errorf("hreg.Address is of type %s, expecting int", addrtype)
|
||||||
|
}
|
||||||
|
iaddr, _ := strconv.Atoi(addr)
|
||||||
|
if hreg.Address != iaddr {
|
||||||
|
t.Errorf("hreg.Address is %d, expecting %d", hreg.Address, iaddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert Symbol is string and matches CSV
|
||||||
|
symboltype := fmt.Sprintf("%T", hreg.Symbol)
|
||||||
|
if symboltype != "string" {
|
||||||
|
t.Errorf("hreg.Symbol is of type %s, expecting string", symboltype)
|
||||||
|
}
|
||||||
|
if hreg.Symbol != symbol {
|
||||||
|
t.Errorf("hreg.Symbol is %s, expecting %s", hreg.Symbol, symbol)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert Description is string and matches CSV
|
||||||
|
descriptiontype := fmt.Sprintf("%T", hreg.Description)
|
||||||
|
if descriptiontype != "string" {
|
||||||
|
t.Errorf("hreg.Description is of type %s, expecting string", descriptiontype)
|
||||||
|
}
|
||||||
|
if hreg.Description != description {
|
||||||
|
t.Errorf("hreg.Description is %s, expecting %s", hreg.Description, description)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert Value is int and 0
|
||||||
|
valuetype := fmt.Sprintf("%T", hreg.Value)
|
||||||
|
if valuetype != "int" {
|
||||||
|
t.Errorf("hreg.Value is of type %s, expecting int", valuetype)
|
||||||
|
}
|
||||||
|
if hreg.Value != 0 {
|
||||||
|
t.Errorf("hreg.Value is %d, expecting false", hreg.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert Reserved is bool and false
|
||||||
|
reservedtype := fmt.Sprintf("%T", hreg.Reserved)
|
||||||
|
if reservedtype != "bool" {
|
||||||
|
t.Errorf("hreg.Reserved is of type %s, expecting bool", reservedtype)
|
||||||
|
}
|
||||||
|
if hreg.Reserved != false {
|
||||||
|
t.Errorf("hreg.Reserved is %t, expecting false", hreg.Reserved)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert Type is string and matches CSV
|
||||||
|
hregtype := fmt.Sprintf("%T", hreg.Type)
|
||||||
|
if hregtype != "string" {
|
||||||
|
t.Errorf("hreg.Type is of type %s, expecting string", hregtype)
|
||||||
|
}
|
||||||
|
if hreg.Type != regtype {
|
||||||
|
t.Errorf("hreg.Type is %s, expecting %s", hreg.Type, regtype)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue