public void GetEndYearAndWeekTest() { Parallel.For(0, CultureTestData.Default.Count(), i => { var currentCulture = CultureTestData.Default[i]; Enumerable.Range(2000, 100) .RunEach(year => { var yearWeek = WeekTool.GetEndYearAndWeek(year, currentCulture); Assert.AreEqual(year, yearWeek.Year); Assert.IsTrue(yearWeek.Week >= 52); }); }); Parallel.For(1980, 2200, year => { var yearWeek = WeekTool.GetEndYearAndWeek(year, null, WeekOfYearRuleKind.Iso8601); Assert.AreEqual(year, yearWeek.Year); Assert.IsTrue(yearWeek.Week >= 52); }); }
public void AddWeekOfYearsTest() { const int maxAddWeeks = 40; Action <CultureInfo> @AddWeekOfYearsAction = (culture) => { var currentCulture = culture; Enumerable .Range(2000, 20) .RunEach(year => { const int step = 10; YearAndWeek prevResult = new YearAndWeek(); var maxWeek = WeekTool.GetEndYearAndWeek(year, currentCulture); for (var week = 1; week < maxWeek.Week; week += step) { for (var addWeeks = -maxAddWeeks; addWeeks <= maxAddWeeks; addWeeks += step) { var current = new YearAndWeek(year, week); var result = WeekTool.AddWeekOfYears(current, addWeeks, currentCulture); if (addWeeks != 0 && prevResult.Week.HasValue) { if (result.Year == prevResult.Year) { Assert.AreEqual(prevResult.Week + step, result.Week, @"Prev=[{0}], Result=[{1}], addWeeks=[{2}]", prevResult, result, addWeeks); } } result.Week.Should().Have.Value(); result.Week.Value.Should().Be.GreaterThan(0); result.Week.Value.Should().Be.LessThanOrEqualTo(TimeSpec.MaxWeeksPerYear); prevResult = result; if (IsDebugEnabled) { log.Debug("Current=[{0}], Added=[{1}], AddWeeks=[{2}]", current, result, addWeeks); } } } }); }; Parallel.For(0, CultureTestData.Default.Count(), i => @AddWeekOfYearsAction(CultureTestData.Default[i])); var rule = WeekOfYearRuleKind.Iso8601; ParallelTool.ForWithStep(2000, 2020, 2, year => { const int step = 10; var prevResult = new YearAndWeek(); var maxWeek = WeekTool.GetEndYearAndWeek(year, null, rule); for (var week = 1; week < maxWeek.Week; week += step) { for (var addWeeks = -maxAddWeeks; addWeeks <= maxAddWeeks; addWeeks += step) { var current = new YearAndWeek(year, week); var result = WeekTool.AddWeekOfYears(current, addWeeks, null, rule); if (addWeeks != 0 && prevResult.Week.HasValue) { if (result.Year == prevResult.Year) { Assert.AreEqual(prevResult.Week + step, result.Week, @"Prev={0}, Result={1}, addWeeks={2}", prevResult, result, addWeeks); } } result.Week.Should().Have.Value(); result.Week.Value.Should().Be.GreaterThan(0); result.Week.Value.Should().Be.LessThanOrEqualTo(TimeSpec.MaxWeeksPerYear); prevResult = result; if (IsDebugEnabled) { log.Debug("Current=[{0}], Added=[{1}], AddWeeks=[{2}]", current, result, addWeeks); } } } }); }