diff options
| author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-04-15 19:20:53 -0400 | 
|---|---|---|
| committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-04-15 19:20:53 -0400 | 
| commit | 3a247fa75c56f315d82ea55143e89d28d61c064c (patch) | |
| tree | 910ee84a435238ddf42fca43927217ec6ce96987 /src/SMAPI.Tests/Utilities/SDateTests.cs | |
| parent | 01b970c84a565ff264f0482a3c544c609886912e (diff) | |
| download | SMAPI-3a247fa75c56f315d82ea55143e89d28d61c064c.tar.gz SMAPI-3a247fa75c56f315d82ea55143e89d28d61c064c.tar.bz2 SMAPI-3a247fa75c56f315d82ea55143e89d28d61c064c.zip | |
tweak new code, update release notes
Diffstat (limited to 'src/SMAPI.Tests/Utilities/SDateTests.cs')
| -rw-r--r-- | src/SMAPI.Tests/Utilities/SDateTests.cs | 117 | 
1 files changed, 53 insertions, 64 deletions
| diff --git a/src/SMAPI.Tests/Utilities/SDateTests.cs b/src/SMAPI.Tests/Utilities/SDateTests.cs index 3fca9b29..0461952e 100644 --- a/src/SMAPI.Tests/Utilities/SDateTests.cs +++ b/src/SMAPI.Tests/Utilities/SDateTests.cs @@ -6,7 +6,6 @@ using System.Text.RegularExpressions;  using NUnit.Framework;  using StardewModdingAPI.Utilities;  using StardewValley; -using LC = StardewValley.LocalizedContentManager.LanguageCode;  namespace SMAPI.Tests.Utilities  { @@ -84,6 +83,46 @@ namespace SMAPI.Tests.Utilities          }          /**** +        ** FromDaysSinceStart +        ****/ +        [Test(Description = "Assert that FromDaysSinceStart returns the expected date.")] +        [TestCase(1, ExpectedResult = "01 spring Y1")] +        [TestCase(2, ExpectedResult = "02 spring Y1")] +        [TestCase(28, ExpectedResult = "28 spring Y1")] +        [TestCase(29, ExpectedResult = "01 summer Y1")] +        [TestCase(141, ExpectedResult = "01 summer Y2")] +        public string FromDaysSinceStart(int daysSinceStart) +        { +            // act +            return SDate.FromDaysSinceStart(daysSinceStart).ToString(); +        } + +        [Test(Description = "Assert that FromDaysSinceStart throws an exception if the number of days is invalid.")] +        [TestCase(-1)] // day < 0 +        [TestCase(0)] // day == 0 +        [SuppressMessage("ReSharper", "AssignmentIsFullyDiscarded", Justification = "Deliberate for unit test.")] +        public void FromDaysSinceStart_RejectsInvalidValues(int daysSinceStart) +        { +            // act & assert +            Assert.Throws<ArgumentException>(() => _ = SDate.FromDaysSinceStart(daysSinceStart), "Passing the invalid number of days didn't throw the expected exception."); +        } + +        /**** +        ** From +        ****/ +        [Test(Description = "Assert that SDate.From constructs the correct instance for a given date.")] +        [TestCase(0, ExpectedResult = "01 spring Y1")] +        [TestCase(1, ExpectedResult = "02 spring Y1")] +        [TestCase(27, ExpectedResult = "28 spring Y1")] +        [TestCase(28, ExpectedResult = "01 summer Y1")] +        [TestCase(140, ExpectedResult = "01 summer Y2")] +        public string From_WorldDate(int totalDays) +        { +            return SDate.From(new WorldDate { TotalDays = totalDays }).ToString(); +        } + + +        /****          ** SeasonIndex          ****/          [Test(Description = "Assert the numeric index of the season.")] @@ -98,6 +137,7 @@ namespace SMAPI.Tests.Utilities              return this.GetDate(dateStr).SeasonIndex;          } +          /****          ** DayOfWeek          ****/ @@ -136,6 +176,7 @@ namespace SMAPI.Tests.Utilities              return this.GetDate(dateStr).DayOfWeek;          } +          /****          ** DaysSinceStart          ****/ @@ -151,6 +192,7 @@ namespace SMAPI.Tests.Utilities              return this.GetDate(dateStr).DaysSinceStart;          } +          /****          ** ToString          ****/ @@ -164,57 +206,6 @@ namespace SMAPI.Tests.Utilities              return this.GetDate(dateStr).ToString();          } -        /**** -        ** ToLocaleString -        ****/ -        // TODO: Provide an appropriate XNA/MonoGame context to run this in, or else remove the test. -        // [Test(Description = "Assert that ToLocaleString returns the expected string in various locales.")] -        // [TestCase("14 spring Y1", LC.en, ExpectedResult = "Day 14 of Spring, Year 1")] -        // [TestCase("01 summer Y16", LC.en, ExpectedResult = "Day 1 of Summer, Year 16")] -        // [TestCase("28 fall Y10", LC.en, ExpectedResult = "Day 28 of Fall, Year 10")] -        // [TestCase("01 winter Y1", LC.en, ExpectedResult = "Day 1 of Winter, Year 1")] -        // [TestCase("14 spring Y1", LC.es, ExpectedResult = "Día 14 de primavera, año 1")] -        // [TestCase("01 summer Y16", LC.es, ExpectedResult = "Día 1 de verano, año 16")] -        // [TestCase("28 fall Y10", LC.es, ExpectedResult = "Día 28 de otoño, año 10")] -        // [TestCase("01 winter Y1", LC.es, ExpectedResult = "Día 1 de invierno, año 1")] -        // public string ToLocaleString(string dateStr, LC langCode) -        // { -        //     LC oldCode = LocalizedContentManager.CurrentLanguageCode; -        //     try -        //     { -        //         LocalizedContentManager.CurrentLanguageCode = langCode; -        //         return this.GetDate(dateStr).ToLocaleString(); -        //     } -        //     finally -        //     { -        //         LocalizedContentManager.CurrentLanguageCode = oldCode; -        //     } -        // } - -        /**** -        ** FromDaysSinceStart -        ****/ -        [Test(Description = "Assert that FromDaysSinceStart returns the expected date.")] -        [TestCase(1, ExpectedResult = "01 spring Y1")] -        [TestCase(2, ExpectedResult = "02 spring Y1")] -        [TestCase(28, ExpectedResult = "28 spring Y1")] -        [TestCase(29, ExpectedResult = "01 summer Y1")] -        [TestCase(141, ExpectedResult = "01 summer Y2")] -        public string FromDaysSinceStart(int daysSinceStart) -        { -            // act -            return SDate.FromDaysSinceStart(daysSinceStart).ToString(); -        } - -        [Test(Description = "Assert that FromDaysSinceStart throws an exception if the number of days is invalid.")] -        [TestCase(-1)] // day < 0 -        [TestCase(0)] // day == 0 -        [SuppressMessage("ReSharper", "AssignmentIsFullyDiscarded", Justification = "Deliberate for unit test.")] -        public void FromDaysSinceStart_RejectsInvalidValues(int daysSinceStart) -        { -            // act & assert -            Assert.Throws<ArgumentException>(() => _ = SDate.FromDaysSinceStart(daysSinceStart), "Passing the invalid number of days didn't throw the expected exception."); -        }          /****          ** AddDays @@ -246,6 +237,7 @@ namespace SMAPI.Tests.Utilities              Assert.Throws<ArithmeticException>(() => _ = this.GetDate(dateStr).AddDays(addDays), "Passing the invalid number of days didn't throw the expected exception.");          } +          /****          ** GetHashCode          ****/ @@ -274,28 +266,25 @@ namespace SMAPI.Tests.Utilities              }          } -        [Test(Description = "Assert that the SDate operator for WorldDates returns the corresponding SDate.")] -        [TestCase(0, ExpectedResult = "01 spring Y1")] -        [TestCase(1, ExpectedResult = "02 spring Y1")] -        [TestCase(27, ExpectedResult = "28 spring Y1")] -        [TestCase(28, ExpectedResult = "01 summer Y1")] -        [TestCase(140, ExpectedResult = "01 summer Y2")] -        public string Operators_SDate_WorldDate(int totalDays) -        { -            return ((SDate)new WorldDate { TotalDays = totalDays }).ToString(); -        } +        /**** +        ** ToWorldDate +        ****/          [Test(Description = "Assert that the WorldDate operator returns the corresponding WorldDate.")]          [TestCase("01 spring Y1", ExpectedResult = 0)]          [TestCase("02 spring Y1", ExpectedResult = 1)]          [TestCase("28 spring Y1", ExpectedResult = 27)]          [TestCase("01 summer Y1", ExpectedResult = 28)]          [TestCase("01 summer Y2", ExpectedResult = 140)] -        public int Operators_WorldDate(string dateStr) +        public int ToWorldDate(string dateStr)          { -            return ((WorldDate)this.GetDate(dateStr)).TotalDays; +            return this.GetDate(dateStr).ToWorldDate().TotalDays;          } + +        /**** +        ** Operators +        ****/          [Test(Description = "Assert that the == operator returns the expected values. We only need a few test cases, since it's based on GetHashCode which is tested more thoroughly.")]          [TestCase(Dates.Now, null, ExpectedResult = false)]          [TestCase(Dates.Now, Dates.PrevDay, ExpectedResult = false)] | 
