Skip to content

Commit

Permalink
establish testing pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
cdzombak committed Sep 2, 2023
1 parent 95dd184 commit 69bd3bf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
16 changes: 1 addition & 15 deletions libwx_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
package libwx

import (
"testing"
)

func Test_RelHumidity_type(t *testing.T) {
var sut interface{} = RelHumidity(50)
switch sut.(type) {
case int:
// ok
case string:
t.Fatal("RelHumidity should not be a string")
default:
t.Fatalf("RelHumidity is %T", sut)
}
}
// TODO(cdzombak): testing for calculations in libwx.go
39 changes: 39 additions & 0 deletions temperature_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package libwx

import "testing"

func TestTempF_C(t *testing.T) {
pairs := []struct {
input TempF
expected TempC
}{
{TempF(32), TempC(0)},
{TempF(212), TempC(100)},
{TempF(98.6), TempC(37)},
{TempF(-40), TempC(-40)},
}

for _, pair := range pairs {
if Float64Compare(float64(pair.expected), float64(pair.input.C()), Tolerance001) != 0 {
t.Errorf("for input %v: expected %v, got %v", pair.input, pair.expected, pair.input.C())
}
}
}

func TestTempC_F(t *testing.T) {
pairs := []struct {
input TempC
expected TempF
}{
{TempC(0), TempF(32)},
{TempC(100), TempF(212)},
{TempC(37), TempF(98.6)},
{TempC(-40), TempF(-40)},
}

for _, pair := range pairs {
if Float64Compare(float64(pair.expected), float64(pair.input.F()), Tolerance001) != 0 {
t.Errorf("for input %v: expected %v, got %v", pair.input, pair.expected, pair.input.F())
}
}
}

0 comments on commit 69bd3bf

Please sign in to comment.