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 c3a61e9a2510f095442c979b2bc4f00f4f6eb0d6
parent 7c3b495ecf8aa9001424dffbdc6b95a566efed3e
Author: Jaron Swab <jrswab@gmail.com>
Date:   Sun,  8 Mar 2020 13:04:51 -0400

Added pressure and humidity

Diffstat:
Mtests/veterejo_test.go | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mveterejo.go | 10++++++++++
2 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/tests/veterejo_test.go b/tests/veterejo_test.go @@ -62,6 +62,90 @@ func TestGetMinTemp(t *testing.T) { } } +func TestGetFeelsLike(t *testing.T) { + tests := []struct { + name string + data *v.WeatherData + want float32 + }{ + // TODO: Add test cases. + { + name: "Returns a temperature float on a correct call to the api (imperial)", + data: RunTestServer("imperial"), + want: 24.13, + }, + { + name: "Returns a temperature float on a correct call to the api (metric)", + data: RunTestServer("metric"), + want: -4.73, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.data.GetFeelsLike() + if got != tt.want { + t.Errorf("GetMinTemp() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetPressure(t *testing.T) { + tests := []struct { + name string + data *v.WeatherData + want int + }{ + // TODO: Add test cases. + { + name: "GetPressure returns integer on a correct call to the api (imperial)", + data: RunTestServer("imperial"), + want: 1031, + }, + { + name: "GetPressure returns integer on a correct call to the api (metric)", + data: RunTestServer("metric"), + want: 1031, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.data.GetPressure() + if got != tt.want { + t.Errorf("GetMaxTemp() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestGetHumidity(t *testing.T) { + tests := []struct { + name string + data *v.WeatherData + want int + }{ + // TODO: Add test cases. + { + name: "GetHumidity returns integer on a correct call to the api (imperial)", + data: RunTestServer("imperial"), + want: 68, + }, + { + name: "GetHumidity returns integer on a correct call to the api (metric)", + data: RunTestServer("metric"), + want: 55, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.data.GetHumidity() + if got != tt.want { + t.Errorf("GetMaxTemp() = %v, want %v", got, tt.want) + } + }) + } +} + func TestGetCoords(t *testing.T) { tests := []struct { name string diff --git a/veterejo.go b/veterejo.go @@ -82,6 +82,16 @@ func (w *WeatherData) GetFeelsLike() float32 { return w.Main.FeelsLike } +// GetPressure returns the current pressure that GetData gets in the call. +func (w *WeatherData) GetPressure() int { + return w.Main.Pressure +} + +// GetHumidity returns the current humidity (as a percentage) that GetData gets in the call. +func (w *WeatherData) GetHumidity() int { + return w.Main.Humidity +} + // GetCoords returns a string of "lat, long" func (w *WeatherData) GetCoords() string { return fmt.Sprintf("%.2f, %.2f", w.Coord.Lat, w.Coord.Lon)