veterejo

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.swab.dev/veterejo.git
Log | Files | Refs | README | LICENSE

commit 58582a8fd4b53b55d9a6f6afc1266971e04e673b
parent b462330fce66833ac6466af7cb20ab904a4889f1
Author: Jaron Swab <jrswab@gmail.com>
Date:   Sun,  8 Mar 2020 12:30:34 -0400

Added method to return coords as a string

Diffstat:
Mtests/helpers.go | 4++--
Mtests/veterejo_test.go | 28++++++++++++++++++++++++++++
Mveterejo.go | 12+++++++++++-
3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/tests/helpers.go b/tests/helpers.go @@ -40,7 +40,7 @@ func getImperialTestData() string { return `{ "coord": { "lon": -79.96, - "lat": 40.56 + "lat": 50.56 }, "weather": [ { @@ -86,7 +86,7 @@ func getMetricTestData() string { return `{ "coord": { "lon": -79.96, - "lat": 40.56 + "lat": 50.56 }, "weather": [ { diff --git a/tests/veterejo_test.go b/tests/veterejo_test.go @@ -61,3 +61,31 @@ func TestGetMinTemp(t *testing.T) { }) } } + +func TestGetCoords(t *testing.T) { + tests := []struct { + name string + data *v.WeatherData + want string + }{ + // TODO: Add test cases. + { + name: "Return coords as string on a correct call to the api (imperial)", + data: RunTestServer("imperial"), + want: "50.56, -79.96", + }, + { + name: "Return coords as string on a correct call to the api (metric)", + data: RunTestServer("metric"), + want: "50.56, -79.96", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.data.GetCoords() + if got != tt.want { + t.Errorf("GetCoords() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/veterejo.go b/veterejo.go @@ -6,7 +6,7 @@ import ( "net/http" ) -// weatherData holds the information passed back from the OpenWeather API +// WeatherData holds the information passed back from the OpenWeather API type WeatherData struct { Coord struct { Lon float32 `json:"lon"` @@ -76,3 +76,13 @@ func (w *WeatherData) GetMaxTemp() int { func (w *WeatherData) GetMinTemp() float32 { return w.Main.TempMin } + +// GetFeelsLike returns the current "feels like" temperature that GetData gets in the call. +func (w *WeatherData) GetFeelsLike() float32 { + return w.Main.FeelsLike +} + +// GetCoords returns a string of "lat, long" +func (w *WeatherData) GetCoords() string { + return fmt.Sprintf("%.2f, %.2f", w.Coord.Lat, w.Coord.Lon) +}