forked from AlienDwarf/open-meteo-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the WeatherCode method to its own class
- Loading branch information
Showing
4 changed files
with
70 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace OpenMeteo; | ||
public static class WeatherCodeHelper | ||
{ | ||
/// <summary> | ||
/// Converts a given weathercode to it's string representation | ||
/// </summary> | ||
/// <param name="weathercode"></param> | ||
/// <returns><see cref="string"/> Weathercode string representation</returns> | ||
public static string WeathercodeToString(int weathercode) | ||
{ | ||
return weathercode switch | ||
{ | ||
0 => "Clear sky", | ||
1 => "Mainly clear", | ||
2 => "Partly cloudy", | ||
3 => "Overcast", | ||
45 => "Fog", | ||
48 => "Depositing rime Fog", | ||
51 => "Light drizzle", | ||
53 => "Moderate drizzle", | ||
55 => "Dense drizzle", | ||
56 => "Light freezing drizzle", | ||
57 => "Dense freezing drizzle", | ||
61 => "Slight rain", | ||
63 => "Moderate rain", | ||
65 => "Heavy rain", | ||
66 => "Light freezing rain", | ||
67 => "Heavy freezing rain", | ||
71 => "Slight snow fall", | ||
73 => "Moderate snow fall", | ||
75 => "Heavy snow fall", | ||
77 => "Snow grains", | ||
80 => "Slight rain showers", | ||
81 => "Moderate rain showers", | ||
82 => "Violent rain showers", | ||
85 => "Slight snow showers", | ||
86 => "Heavy snow showers", | ||
95 => "Thunderstorm", | ||
96 => "Thunderstorm with light hail", | ||
99 => "Thunderstorm with heavy hail", | ||
_ => "Invalid weathercode", | ||
}; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OpenMeteo; | ||
|
||
namespace OpenMeteoTests | ||
{ | ||
[TestClass] | ||
public class WeatherCodeHelperTests | ||
{ | ||
[DataTestMethod] | ||
[DataRow(0, "Clear sky")] | ||
[DataRow(1, "Mainly clear")] | ||
[DataRow(2, "Partly cloudy")] | ||
[DataRow(3, "Overcast")] | ||
[DataRow(51, "Light drizzle")] | ||
[DataRow(53, "Moderate drizzle")] | ||
[DataRow(96, "Thunderstorm with light hail")] | ||
[DataRow(99, "Thunderstorm with heavy hail")] | ||
[DataRow(100, "Invalid weathercode")] | ||
public void Weather_Codes_To_String_Tests(int weatherCode, string expectedString) | ||
{ | ||
string weatherCodeString = WeatherCodeHelper.WeathercodeToString(weatherCode); | ||
Assert.IsInstanceOfType(weatherCodeString, typeof(string)); | ||
Assert.AreEqual(expectedString, weatherCodeString); | ||
} | ||
} | ||
} |