diff --git a/yr/yr.go b/yr/yr.go index ef8f74c..292749b 100644 --- a/yr/yr.go +++ b/yr/yr.go @@ -41,21 +41,23 @@ func (w *wind) DirectionToString() string { // Retruns unicode block arrow based on wind-direction func windDirection(d float64) string { switch { - case d == 0 || d == 360: + case d == 360: return direction.SOUTH - case d <= 45 && d < 90: + case d >= 0 && d < 45: + return direction.SOUTH + case d >= 45 && d < 90: return direction.SOUTH_WEST - case d <= 90 && d < 135: + case d >= 90 && d < 135: return direction.WEST - case d <= 135 && d < 180: + case d >= 135 && d < 180: return direction.NORTH_WEST - case d <= 180 && d < 225: + case d >= 180 && d < 225: return direction.NORTH - case d <= 225 && d < 270: + case d >= 225 && d < 270: return direction.NORTH_EAST - case d <= 270 && d < 315: + case d >= 270 && d < 315: return direction.EAST - case d <= 315 && d < 360: + case d >= 315: return direction.SOUTH_EAST default: return "↔" diff --git a/yr/yr_test.go b/yr/yr_test.go index bb14257..3f0d40e 100644 --- a/yr/yr_test.go +++ b/yr/yr_test.go @@ -11,26 +11,50 @@ func TestWindDirection(t *testing.T) { assert := assert.New(t) south := windDirection(0) - assert.Equal(direction.SOUTH, south, "south") + assert.Equal(direction.SOUTH, south, "south 0") + + south = windDirection(20) + assert.Equal(direction.SOUTH, south, "south 20") southwest := windDirection(45) - assert.Equal(direction.SOUTH_WEST, southwest, "southwest") + assert.Equal(direction.SOUTH_WEST, southwest, "southwest 45") + + southwest = windDirection(60) + assert.Equal(direction.SOUTH_WEST, southwest, "southwest 60") west := windDirection(90) - assert.Equal(direction.WEST, west, "west") + assert.Equal(direction.WEST, west, "west 90") + + west = windDirection(100) + assert.Equal(direction.WEST, west, "west 100") northwest := windDirection(135) - assert.Equal(direction.NORTH_WEST, northwest, "northwest") + assert.Equal(direction.NORTH_WEST, northwest, "northwest 135") + + northwest = windDirection(150) + assert.Equal(direction.NORTH_WEST, northwest, "northwest 150") north := windDirection(180) - assert.Equal(direction.NORTH, north, "north") + assert.Equal(direction.NORTH, north, "north 180") + + north = windDirection(200) + assert.Equal(direction.NORTH, north, "north 200") northeast := windDirection(225) - assert.Equal(direction.NORTH_EAST, northeast, "northeast") + assert.Equal(direction.NORTH_EAST, northeast, "northeast 225") + + northeast = windDirection(250) + assert.Equal(direction.NORTH_EAST, northeast, "northeast 250") east := windDirection(270) - assert.Equal(direction.EAST, east, "east") + assert.Equal(direction.EAST, east, "east 270") + + east = windDirection(280) + assert.Equal(direction.EAST, east, "east 280") southeast := windDirection(315) - assert.Equal(direction.SOUTH_EAST, southeast, "southeast") + assert.Equal(direction.SOUTH_EAST, southeast, "southeast 315") + + southeast = windDirection(347.3) + assert.Equal(direction.SOUTH_EAST, southeast, "southeast 347.3") }