Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Holy Days Issue Bugfix #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BadiNodaTime/BadiYearInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public List<SpecialDay> GetSpecialDays(SpecialDayType typesWanted, HolyDayCode h
return final
.Where(sd =>
holyDaysWanted == HolyDayCode._NoCode_
|| !sd.DayType.HasFlag(SpecialDayType.HolyDay_WorkSuspended | SpecialDayType.HolyDay_Other)
|| ((sd.DayType != SpecialDayType.HolyDay_WorkSuspended) && (sd.DayType != SpecialDayType.HolyDay_Other))
|| sd.DayCode.HasFlag(holyDaysWanted))
.OrderBy(sd => sd.Date.LocalDate.DayOfYear)
.ToList();
Expand Down
12 changes: 11 additions & 1 deletion src/BadiNodaTimeTest/ResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ public void HolyDayNames(HolyDayCode code, string name, string time)
_resolver.GetString("HolyDay_" + code).ShouldEqual(name);

var yi = new BadiYearInfo(174);
var holyDay = yi.GetSpecialDays(SpecialDayType.HolyDay_Other, code).First();
SpecialDayType specialDayType = new SpecialDayType();
if (code == HolyDayCode.BirthBab)
{
specialDayType = SpecialDayType.HolyDay_WorkSuspended;
}
else if (code == HolyDayCode.AscAbdul)
{
specialDayType = SpecialDayType.HolyDay_Other;
}

var holyDay = yi.GetSpecialDays(specialDayType, code).First();

if (holyDay.TimeCode != SpecialTimeCode._NoCode_)
{
Expand Down
12 changes: 12 additions & 0 deletions src/BadiNodaTimeTest/YearInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,17 @@ public void HolyDays_Other()
hd2.TimeCode.ShouldEqual(SpecialTimeCode.H01);
hd2.DayCode.ShouldEqual(HolyDayCode.AscAbdul);
}

[Fact]
public void GetSpecialDays_HolyDaysWanted()
{
var yearInfo = new BadiYearInfo(174);

var specialDaysList = yearInfo.GetSpecialDays(SpecialDayType.HolyDay_WorkSuspended, HolyDayCode.NawRuz);
specialDaysList.Count().ShouldEqual(1);

specialDaysList = yearInfo.GetSpecialDays(SpecialDayType.HolyDay_WorkSuspended, HolyDayCode.Ridvan1);
specialDaysList.Count().ShouldEqual(1);
}
Comment on lines +107 to +117
Copy link
Collaborator

@benrobot benrobot Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to asserting the count the test should also assert the correct day and day code are returned.

Copy link
Collaborator

@benrobot benrobot Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also change this test from a Fact to a Theory and exhaustively test every possible HolyDayCode

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In just reading the code change proposed, I can't be confident that it is working fully. I'd need to run the code and do a number of other tests to be sure.

So it would be good if you could add more tests and made them more comprehensive. For instance, it would be good to also test calls that will give no result, like .GetSpecialDays(SpecialDayType.HolyDay_Other, HolyDayCode.Ridvan1).

}
}