gh-14 Test coil.Reserved assignment

This commit is contained in:
Jarno Rankinen 2023-02-12 22:37:23 +02:00
parent 480279e2f5
commit b8929f6211
1 changed files with 34 additions and 9 deletions

View File

@ -2,15 +2,15 @@ package pingvinKL
import ( import (
"fmt" "fmt"
"testing"
"strconv" "strconv"
"testing"
) )
func TestNewCoil(t *testing.T) { func TestNewCoil(t *testing.T) {
data := readCsvLines("../coils.csv") data := readCsvLines("../coils.csv")
addr := data[1][0] addr := data[1][0]
symbol := data[1][0] symbol := data[1][1]
description := data[1][0] description := data[1][2]
coil := newCoil(addr, symbol, description) coil := newCoil(addr, symbol, description)
typ := fmt.Sprintf("%T", coil) typ := fmt.Sprintf("%T", coil)
@ -29,26 +29,51 @@ func TestNewCoil(t *testing.T) {
} }
// 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" {
t.Errorf("coil.Symbol is of type %s, expecting string", symboltype) t.Errorf("coil.Symbol is of type %s, expecting string", symboltype)
} }
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" {
t.Errorf("coil.Description is of type %s, expecting string", descriptiontype) t.Errorf("coil.Description is of type %s, expecting string", descriptiontype)
} }
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" {
t.Errorf("coil.Value is of type %s, expecting bool", valuetype) t.Errorf("coil.Value is of type %s, expecting bool", valuetype)
} }
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
reservedtype := fmt.Sprintf("%T", coil.Reserved)
if reservedtype != "bool" {
t.Errorf("coil.Reserved is of type %s, expecting bool", typ)
}
if coil.Reserved != false {
t.Errorf("coil.Reserved is %t, expecting false", coil.Reserved)
}
}
func TestNewReservedCoil(t *testing.T) {
data := readCsvLines("../coils.csv")
addr := data[3][0]
symbol := data[3][1]
description := data[3][2]
coil := newCoil(addr, symbol, description)
// Assert Reserved is bool and true
typ := fmt.Sprintf("%T", coil.Reserved)
if typ != "bool" {
t.Errorf("coil.Reserved is of type %s, expecting bool", typ)
}
if coil.Reserved != true {
t.Errorf("coil.Reserved is %t, expecting true", coil.Reserved)
}
} }