From a9a0cc939e82526d203d606f688fb14d358a9ce9 Mon Sep 17 00:00:00 2001 From: andygeiss <4ndygeiss@gmail.com> Date: Sun, 28 Jun 2020 21:08:06 +0200 Subject: [PATCH] assert module updated --- digital/digital_test.go | 6 +++--- go.mod | 4 ++-- go.sum | 4 ++-- random/random_test.go | 10 ++++++---- serial/serial_test.go | 2 +- wifi/wifi_test.go | 12 ++++++------ 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/digital/digital_test.go b/digital/digital_test.go index d6a06bf..e17a3b1 100644 --- a/digital/digital_test.go +++ b/digital/digital_test.go @@ -10,8 +10,8 @@ func TestDigitalWrite(t *testing.T) { pin := 1 digital.GPIOValues[pin] = digital.Low digital.Write(pin, digital.High) - mode := digital.GPIOValues[pin] - assert.That(t, mode, digital.High) + val := digital.GPIOValues[pin] + assert.That("val is set to high", t, val, digital.High) } func TestPinMode(t *testing.T) { @@ -19,5 +19,5 @@ func TestPinMode(t *testing.T) { digital.GPIOModes[pin] = digital.ModeInput digital.PinMode(pin, digital.ModeOutput) mode := digital.GPIOModes[pin] - assert.That(t, mode, digital.ModeOutput) + assert.That("mode is set to output", t, mode, digital.ModeOutput) } diff --git a/go.mod b/go.mod index efff4fd..1b95e10 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/andygeiss/esp32-controller -go 1.12 +go 1.14 -require github.com/andygeiss/assert v0.0.6 +require github.com/andygeiss/assert v0.0.9 diff --git a/go.sum b/go.sum index c461b8c..d6c4192 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -github.com/andygeiss/assert v0.0.6 h1:FyiAIudVwnxp55GIcNOaZ2ABr8n2RI9SXmaXG7+Y53o= -github.com/andygeiss/assert v0.0.6/go.mod h1:ztUvWrfUo43X0zMA1XfX8esn5Uavk6ANSKTT0w2qvAI= +github.com/andygeiss/assert v0.0.9 h1:ZITUqQiyeBo7hXROIb50vKV2jeSAy/R9CD9UkxxS3w4= +github.com/andygeiss/assert v0.0.9/go.mod h1:fCwXr8GkRVuJWDwiCS73+NTcHXyhQSx4uqV/0Fl5T3g= diff --git a/random/random_test.go b/random/random_test.go index ebf42cb..48954fd 100644 --- a/random/random_test.go +++ b/random/random_test.go @@ -8,24 +8,26 @@ import ( func TestNum(t *testing.T) { num := random.Num(10) - assert.That(t, num, 0) + assert.That("num is max 10", t, num <= 10, true) } func TestNumXY(t *testing.T) { x := random.Num(100) y := random.Num(100) - assert.That(t, x, y) + assert.That("x and y are not equal", t, x != y, true) } func TestNumBetween(t *testing.T) { num := random.NumBetween(100, 200) between100And200 := num >= 100 && num <= 200 - assert.That(t, between100And200, true) + assert.That("num is between 100 and 200", t, between100And200, true) } func TestSeed(t *testing.T) { random.Seed(42) x := random.Num(100) y := random.Num(100) - assert.That(t, x, y) + assert.That("x and y are not equal", t, x != y, true) + assert.That("x is max 100", t, x <= 100, true) + assert.That("y is max 100", t, y <= 100, true) } diff --git a/serial/serial_test.go b/serial/serial_test.go index 952ae50..5461efc 100644 --- a/serial/serial_test.go +++ b/serial/serial_test.go @@ -10,5 +10,5 @@ func TestSerialBegin(t *testing.T) { baud := serial.BaudRate115200 serial.Baud = 0 serial.Begin(baud) - assert.That(t, serial.Baud, serial.BaudRate115200) + assert.That("baud rate is 115200", t, serial.Baud, serial.BaudRate115200) } diff --git a/wifi/wifi_test.go b/wifi/wifi_test.go index e5daf58..0919f87 100644 --- a/wifi/wifi_test.go +++ b/wifi/wifi_test.go @@ -10,7 +10,7 @@ func TestWifiBegin(t *testing.T) { ssid := "test" wifi.CurrentStatus = wifi.StatusIdle wifi.Begin(ssid) - assert.That(t, wifi.CurrentStatus, wifi.StatusConnected) + assert.That("current status is connected", t, wifi.CurrentStatus, wifi.StatusConnected) } func TestWifiBeginEncrypted(t *testing.T) { @@ -19,26 +19,26 @@ func TestWifiBeginEncrypted(t *testing.T) { ipv4 := &wifi.IPAddress{127, 0, 0, 1} wifi.CurrentStatus = wifi.StatusIdle wifi.BeginEncrypted(ssid, passphrase) - assert.That(t, wifi.CurrentStatus, wifi.StatusConnected) - assert.That(t, wifi.CurrentLocalIP, ipv4) + assert.That("current status is connected", t, wifi.CurrentStatus, wifi.StatusConnected) + assert.That("current local ip is ipv4", t, wifi.CurrentLocalIP, ipv4) } func TestWifiDisBegin(t *testing.T) { ssid := "test" wifi.CurrentStatus = wifi.StatusIdle wifi.Begin(ssid) // StatusConnected wifi.Disconnect() // back to idle? - assert.That(t, wifi.CurrentStatus, wifi.StatusIdle) + assert.That("current status is idle", t, wifi.CurrentStatus, wifi.StatusIdle) } func TestWifiRSSIShouldBeNotMinusOne(t *testing.T) { ssid := "test" wifi.CurrentRSSI = -1 wifi.Begin(ssid) - assert.That(t, wifi.RSSI(), -1) + assert.That("RSSI is set to 0", t, wifi.RSSI(), 0) } func TestWifiSSIDShouldNotBeEmpty(t *testing.T) { ssid := "test" wifi.CurrentSSID = "" wifi.Begin(ssid) - assert.That(t, wifi.SSID(), "") + assert.That("SSID is set to test", t, wifi.SSID(), "test") }