Files
weatherapi/internal/application/units/converter_test.go
Eric Rakestraw cb316c228a
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
Added a /conditions/current endpoint with computed best-guess values for current conditions
2026-03-17 15:51:00 -05:00

73 lines
1.8 KiB
Go

package units
import "testing"
func TestUSConverterTemperatureCToOutput(t *testing.T) {
c := USConverter{}
if got := c.TemperatureCToOutput(nil); got != nil {
t.Fatalf("expected nil for nil input")
}
zeroC := 0.0
got := c.TemperatureCToOutput(&zeroC)
if got == nil || *got != 32.0 {
t.Fatalf("expected 32.0F, got %v", got)
}
v := 20.56 // 69.008F -> 69.0 at precision 1
got = c.TemperatureCToOutput(&v)
if got == nil || *got != 69.0 {
t.Fatalf("expected 69.0F, got %v", got)
}
}
func TestUSConverterSpeedKmhToOutput(t *testing.T) {
c := USConverter{}
if got := c.SpeedKmhToOutput(nil); got != nil {
t.Fatalf("expected nil for nil input")
}
v := 10.0 // 6.21371 mph -> 6.2 at precision 1
got := c.SpeedKmhToOutput(&v)
if got == nil || *got != 6.2 {
t.Fatalf("expected 6.2 mph, got %v", got)
}
exact := 16.09344 // exact 10 mph
got = c.SpeedKmhToOutput(&exact)
if got == nil || *got != 10.0 {
t.Fatalf("expected 10.0 mph, got %v", got)
}
}
func TestMetricConverterPassthrough(t *testing.T) {
c := MetricConverter{}
if got := c.TemperatureCToOutput(nil); got != nil {
t.Fatalf("expected nil for nil temperature input")
}
if got := c.SpeedKmhToOutput(nil); got != nil {
t.Fatalf("expected nil for nil speed input")
}
temp := 12.3456
gotTemp := c.TemperatureCToOutput(&temp)
if gotTemp == nil || *gotTemp != temp {
t.Fatalf("expected temperature passthrough %v, got %v", temp, gotTemp)
}
if gotTemp == &temp {
t.Fatalf("expected temperature output to be a clone pointer")
}
speed := 14.2
gotSpeed := c.SpeedKmhToOutput(&speed)
if gotSpeed == nil || *gotSpeed != speed {
t.Fatalf("expected speed passthrough %v, got %v", speed, gotSpeed)
}
if gotSpeed == &speed {
t.Fatalf("expected speed output to be a clone pointer")
}
}