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 (
"fmt"
"testing"
"strconv"
"testing"
)
func TestNewCoil(t *testing.T) {
data := readCsvLines("../coils.csv")
addr := data[1][0]
symbol := data[1][0]
description := data[1][0]
symbol := data[1][1]
description := data[1][2]
coil := newCoil(addr, symbol, description)
typ := fmt.Sprintf("%T", coil)
@ -29,7 +29,7 @@ func TestNewCoil(t *testing.T) {
}
// Assert Symbol is string and matches CSV
symboltype := fmt.Sprintf("%T", coil.Symbol)
if symboltype!= "string" {
if symboltype != "string" {
t.Errorf("coil.Symbol is of type %s, expecting string", symboltype)
}
if coil.Symbol != symbol {
@ -37,7 +37,7 @@ func TestNewCoil(t *testing.T) {
}
// Assert Description is string and matches CSV
descriptiontype := fmt.Sprintf("%T", coil.Description)
if descriptiontype!= "string" {
if descriptiontype != "string" {
t.Errorf("coil.Description is of type %s, expecting string", descriptiontype)
}
if coil.Description != description {
@ -45,10 +45,35 @@ func TestNewCoil(t *testing.T) {
}
// Assert Value is boolean and false
valuetype := fmt.Sprintf("%T", coil.Value)
if valuetype!= "bool" {
if valuetype != "bool" {
t.Errorf("coil.Value is of type %s, expecting bool", valuetype)
}
if coil.Value != false {
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)
}
}