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

Some tests can fail in date module #163

Closed
Globostofo opened this issue Sep 30, 2023 · 5 comments
Closed

Some tests can fail in date module #163

Globostofo opened this issue Sep 30, 2023 · 5 comments

Comments

@Globostofo
Copy link
Contributor

Since the data in the tests is chosen randomly, it's possible for a test not to work every time, and for a bug to remain undiscovered if the tests are only run a few times.

The following test failed while I was coding other tests for issue #153:

[ RUN      ] DateTest.shouldGenerateBirthDateByRangeYear
/path/faker-cxx/src/modules/date/DateTest.cpp:150: Failure
Expected: (birthdate.tm_year + 1900) >= (1990), actual: 1989 vs 1990

In theory it's not my code that's causing it to fail, but I'm still investigating to be sure.

@Globostofo
Copy link
Contributor Author

Globostofo commented Oct 1, 2023

By spamming make test command, I've managed to find another test from the date module that sometimes fails:

[ RUN      ] DateTest.shouldGenerateBirthDateByExactYear
/home/plouc/faker-cxx/src/modules/date/DateTest.cpp:141: Failure
Expected equality of these values:
  birthdate.tm_year + 1900
    Which is: 1995
  1996

I'm continuing to investigate the source of the problem.

@Globostofo Globostofo changed the title Test fails in date module Some tests can fail in date module Oct 1, 2023
@cieslarmichal
Copy link
Owner

Ok thanks for investigating that, I will take a look.

@Globostofo
Copy link
Contributor Author

Globostofo commented Oct 1, 2023

I found the problem!

In this function, the tm_mday attribute is set to 0 for the lower bound (line 87). However, a month starts on the 1st, so the lower bound is set to midnight on 31 December when it should be on 1 January at midnight.

When I print the lower bound I got this:

1995-12-31 00:00:00.000000000

But we want to have this:

1996-01-01 00:00:00.000000000

Setting the variable to 1 instead of 0 definitely solves the problem. I'll do the PR.

@cieslarmichal
Copy link
Owner

Good job, I was also looking at the problem right now, and there was a problem with parsing ISO date in tests in parseISOFormattedStringToTm() and parseISOFormattedStringToTimePoint() functions, I fixed it: #168. It took local time instead of UTC and shifted hours but we dont want that,

So we managed to find two bugs in there, nice 😄

@cieslarmichal
Copy link
Owner

Marking as resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants