-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from GravityWolfNotAmused/sunmoon-tags-time-tags
Fix logic for SunMoon
- Loading branch information
Showing
8 changed files
with
132 additions
and
24 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
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,78 @@ | ||
namespace DiscordPlayerCountBot.Tests | ||
{ | ||
[Collection("Sun & Moon Tag Test Suite")] | ||
public class SunMoonTagTests | ||
{ | ||
[Theory(DisplayName = "Test If Should Be Moon", Timeout = 30)] | ||
[InlineData("05:30")] | ||
[InlineData("21:30")] | ||
[InlineData("23:30")] | ||
public void ShouldBeMoonPhase(string time) | ||
{ | ||
var success = time.TryGetSunMoonPhase(null, null, out var output); | ||
|
||
Assert.True(success, "SunMoon Phase failed to parse"); | ||
Assert.True(!string.IsNullOrEmpty(output)); | ||
Assert.Equal("🌙", output); | ||
} | ||
|
||
[Theory(DisplayName = "Test If Should Be Sun", Timeout = 30)] | ||
[InlineData("06:04")] | ||
[InlineData("15:42")] | ||
[InlineData("19:06")] | ||
public void ShouldBeSunPhase(string time) | ||
{ | ||
var success = time.TryGetSunMoonPhase(null, null, out var output); | ||
|
||
Assert.True(success, "SunMoon Phase failed to parse"); | ||
Assert.True(!string.IsNullOrEmpty(output)); | ||
Assert.Equal("☀️", output); | ||
} | ||
|
||
[Theory(DisplayName = "Test Invalid Values", Timeout = 30)] | ||
[InlineData("abc")] | ||
[InlineData("")] | ||
[InlineData("not a time value")] | ||
[InlineData("24:30")] | ||
public void ShouldNotParse(string time) | ||
{ | ||
var success = time.TryGetSunMoonPhase(null, null, out var output); | ||
|
||
Assert.False(success, "SunMoon Phase successfully parsed when it should have failed"); | ||
Assert.True(string.IsNullOrEmpty(output), "SunMoon output is not null or empty."); | ||
} | ||
|
||
[Theory(DisplayName = "Test custom sunrise and sunset", Timeout = 30)] | ||
[InlineData("05:30")] | ||
[InlineData("21:30")] | ||
[InlineData("23:30")] | ||
[InlineData("06:04")] | ||
[InlineData("15:42")] | ||
[InlineData("19:06")] | ||
public void ShouldOutputCorrectValue(string time) | ||
{ | ||
var information = new BotInformation() | ||
{ | ||
SunriseHour = 1, | ||
SunsetHour = 21 | ||
}; | ||
|
||
var success = time.TryGetSunMoonPhase(information.SunriseHour, information.SunsetHour, out var output); | ||
var manualProcessingSuccess = TimeOnly.TryParse(time, out var timeOutput); | ||
|
||
Assert.True(success, "SunMoon Phase parsing failed"); | ||
Assert.True(manualProcessingSuccess, "Manual Parsing SunMoon Phase failed"); | ||
|
||
var isBetween = timeOutput.Hour >= information.SunriseHour && timeOutput.Hour < information.SunsetHour; | ||
var sunMoonPhase = isBetween ? "☀️" : "🌙"; | ||
|
||
if (isBetween) | ||
Assert.True(sunMoonPhase.Equals("☀️"), "Time was between sunrise and sunset, but was not a Sun."); | ||
|
||
if (!isBetween) | ||
Assert.True(sunMoonPhase.Equals("🌙"), "Time not was between sunrise and sunset, but was not a Moon."); | ||
|
||
Assert.Equal(sunMoonPhase, output); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
global using Xunit; | ||
|
||
global using PlayerCountBot; | ||
global using PlayerCountBot.Configuration; | ||
global using PlayerCountBot.Tests.Environment; | ||
global using DiscordPlayerCountBot.Extensions; | ||
global using PlayerCountBot.Json; |
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,34 @@ | ||
using Microsoft.VisualBasic; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DiscordPlayerCountBot.Extensions | ||
{ | ||
public static class StringExtensions | ||
{ | ||
public static bool TryGetSunMoonPhase(this string timeString, int? sunriseHour, int? sunsetHour, out string output) | ||
{ | ||
if (string.IsNullOrWhiteSpace(timeString)) | ||
{ | ||
output = string.Empty; | ||
return false; | ||
} | ||
|
||
if (!TimeOnly.TryParse(timeString, out var time)) | ||
{ | ||
output = string.Empty; | ||
return false; | ||
} | ||
|
||
var sunrise = sunriseHour ?? 6; | ||
var sunset = sunsetHour ?? 20; | ||
var hour = time.Hour; | ||
|
||
output = hour >= sunrise && hour < sunset ? "☀️" : "🌙"; | ||
return !string.IsNullOrEmpty(output); | ||
} | ||
} | ||
} |
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