#1 Updated readme, added test cases for examples.

This commit is contained in:
Per Malmberg 2019-03-15 11:18:10 +01:00
parent 18dc065f00
commit 802d8e724e
3 changed files with 48 additions and 6 deletions

View File

@ -56,9 +56,9 @@ Each part is separated by one or more whitespaces. It is thus important to keep
* 0, 3, 40-50 * * * * ?
`Day of month` and `day of week` are mutually exclusive so one of them must at always be ignored using
the '?'-character unless one field already is something other than '*'.
the '?'-character to ensure that it is not possible to specify a statement which results in an impossible mix of these fields.
# Examples
## Examples
|Expression | Meaning
| --- | --- |
@ -67,7 +67,22 @@ the '?'-character unless one field already is something other than '*'.
| 0 0 12 1/2 * ? | Every 2 days, starting on the 1st at noon
| 0 0 */12 ? * * | Every twelve hours
# Third party libraries
# Randomization
The standard cron format does not allow for randomization, but with the use of `CronRandomization` you can generate random
schedules using the following format: `R(range_start-range_end)`, where `range_start` and `range_end` follow the same rules
as for a regular cron range with the addition that only numbers are allowed. All the rules for a regular cron expression
still applies when using randomization, i.e. mutual exclusiveness and not extra spaces.
## Examples
|Expression | Meaning
| --- | --- |
| 0 0 R(13-20) * * ? | On the hour, on a random hour 13-20, inclusive.
| 0 0 0 ? * R(0-6) | A random weekday, every week, at midnight.
| 0 R(45-15) */12 ? * * | A random minute between 45-15, inclusive, every 12 hours.
# Used Third party libraries
Howard Hinnant's [date libraries](https://github.com/HowardHinnant/date/)

View File

@ -13,7 +13,7 @@ void test(const char* const random_schedule)
libcron::CronRandomization cr;
std::unordered_map<int, std::unordered_map<int, int>> results{};
for (int i = 0; i < 50000; ++i)
for (int i = 0; i < 5000; ++i)
{
auto res = cr.parse(random_schedule);
REQUIRE(std::get<0>(res));
@ -76,3 +76,30 @@ SCENARIO("Randomize all the things with reverse ranges - day of week")
}
}
}
SCENARIO("Test readme examples")
{
GIVEN("0 0 R(13-20) * * ?")
{
THEN("Valid schedule generated")
{
test("0 0 R(13-20) * * ?");
}
}
GIVEN("0 0 0 ? * R(0-6)")
{
THEN("Valid schedule generated")
{
test("0 0 0 ? * R(0-6)");
}
}
GIVEN("0 R(45-15) */12 ? * *")
{
THEN("Valid schedule generated")
{
test("0 R(45-15) */12 ? * *");
}
}
}

Binary file not shown.