From b8929f6211d000193168b341740528f03db06392 Mon Sep 17 00:00:00 2001 From: Jarno Rankinen Date: Sun, 12 Feb 2023 22:37:23 +0200 Subject: [PATCH] gh-14 Test coil.Reserved assignment --- enervent-ctrl-go/pingvinKL/pingvinKL_test.go | 43 ++++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/enervent-ctrl-go/pingvinKL/pingvinKL_test.go b/enervent-ctrl-go/pingvinKL/pingvinKL_test.go index 66c1f1f..252d86c 100644 --- a/enervent-ctrl-go/pingvinKL/pingvinKL_test.go +++ b/enervent-ctrl-go/pingvinKL/pingvinKL_test.go @@ -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,26 +29,51 @@ 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 { t.Errorf("coil.Symbol is %s, expecting %s", coil.Symbol, symbol) } // 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 { t.Errorf("coil.Description is %s, expecting %s", coil.Description, description) } // 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) + } }