Unit Tests - duration

- Corrected unit tests that were mistakenly using 'week' instead of
  'weekly'.
This commit is contained in:
Paul Beckingham 2009-03-20 20:02:59 -04:00
parent 827bc6204b
commit ca933d7f39
2 changed files with 38 additions and 14 deletions

View file

@ -42,6 +42,7 @@ int main (int argc, char** argv)
std::string d;
d = "daily"; t.is (convertDuration (d), 1, "duration daily = 1");
d = "weekdays"; t.is (convertDuration (d), 1, "duration weekdays = 1");
d = "day"; t.is (convertDuration (d), 1, "duration day = 1");
d = "0d"; t.is (convertDuration (d), 0, "duration 0d = 0");
d = "1d"; t.is (convertDuration (d), 1, "duration 1d = 1");
@ -53,7 +54,6 @@ int main (int argc, char** argv)
d = "sennight"; t.is (convertDuration (d), 7, "duration sennight = 7");
d = "biweekly"; t.is (convertDuration (d), 14, "duration biweekly = 14");
d = "fortnight"; t.is (convertDuration (d), 14, "duration fortnight = 14");
d = "week"; t.is (convertDuration (d), 7, "duration week = 7");
d = "0w"; t.is (convertDuration (d), 0, "duration 0w = 0");
d = "1w"; t.is (convertDuration (d), 7, "duration 1w = 7");
d = "7w"; t.is (convertDuration (d), 49, "duration 7w = 49");

View file

@ -95,19 +95,31 @@ void formatTimeDeltaDays (std::string& output, time_t delta)
if (days > 365)
sprintf (formatted, "%.1f yrs", (days / 365.2422));
else if (days > 84)
sprintf (formatted, "%1d mth%s", (int) (days / 30.6), ((int) (days / 30.6) == 1 ? "" : "s"));
sprintf (formatted, "%1d mth%s",
(int) (days / 30.6),
((int) (days / 30.6) == 1 ? "" : "s"));
else if (days > 13)
sprintf (formatted, "%d wk%s", (int) (days / 7.0), ((int) (days / 7.0) == 1 ? "" : "s"));
sprintf (formatted, "%d wk%s",
(int) (days / 7.0),
((int) (days / 7.0) == 1 ? "" : "s"));
else if (days > 5.0)
sprintf (formatted, "%d day%s", (int) days, ((int) days == 1 ? "" : "s"));
sprintf (formatted, "%d day%s",
(int) days,
((int) days == 1 ? "" : "s"));
else if (days > 1.0)
sprintf (formatted, "%.1f days", days);
else if (days * 24 > 1.0)
sprintf (formatted, "%d hr%s", (int) (days * 24.0), ((int) (days * 24.0) == 1 ? "" : "s"));
sprintf (formatted, "%d hr%s",
(int) (days * 24.0),
((int) (days * 24.0) == 1 ? "" : "s"));
else if (days * 24 * 60 > 1)
sprintf (formatted, "%d min%s", (int) (days * 24 * 60), ((int) (days * 24 * 60) == 1 ? "" : "s"));
sprintf (formatted, "%d min%s",
(int) (days * 24 * 60),
((int) (days * 24 * 60) == 1 ? "" : "s"));
else if (days * 24 * 60 * 60 > 1)
sprintf (formatted, "%d sec%s", (int) (days * 24 * 60 * 60), ((int) (days * 24 * 60 * 60) == 1 ? "" : "s"));
sprintf (formatted, "%d sec%s",
(int) (days * 24 * 60 * 60),
((int) (days * 24 * 60 * 60) == 1 ? "" : "s"));
else
strcpy (formatted, "-");
@ -123,19 +135,31 @@ std::string formatSeconds (time_t delta)
if (days > 365)
sprintf (formatted, "%.1f yrs", (days / 365.2422));
else if (days > 84)
sprintf (formatted, "%1d mth%s", (int) (days / 30.6), ((int) (days / 30.6) == 1 ? "" : "s"));
sprintf (formatted, "%1d mth%s",
(int) (days / 30.6),
((int) (days / 30.6) == 1 ? "" : "s"));
else if (days > 13)
sprintf (formatted, "%d wk%s", (int) (days / 7.0), ((int) (days / 7.0) == 1 ? "" : "s"));
sprintf (formatted, "%d wk%s",
(int) (days / 7.0),
((int) (days / 7.0) == 1 ? "" : "s"));
else if (days > 5.0)
sprintf (formatted, "%d day%s", (int) days, ((int) days == 1 ? "" : "s"));
sprintf (formatted, "%d day%s",
(int) days,
((int) days == 1 ? "" : "s"));
else if (days > 1.0)
sprintf (formatted, "%.1f days", days);
else if (days * 24 > 1.0)
sprintf (formatted, "%d hr%s", (int) (days * 24.0), ((int) (days * 24) == 1 ? "" : "s"));
sprintf (formatted, "%d hr%s",
(int) (days * 24.0),
((int) (days * 24) == 1 ? "" : "s"));
else if (days * 24 * 60 > 1)
sprintf (formatted, "%d min%s", (int) (days * 24 * 60), ((int) (days * 24 * 60) == 1 ? "" : "s"));
sprintf (formatted, "%d min%s",
(int) (days * 24 * 60),
((int) (days * 24 * 60) == 1 ? "" : "s"));
else if (days * 24 * 60 * 60 > 1)
sprintf (formatted, "%d sec%s", (int) (days * 24 * 60 * 60), ((int) (days * 24 * 60 * 60) == 1 ? "" : "s"));
sprintf (formatted, "%d sec%s",
(int) (days * 24 * 60 * 60),
((int) (days * 24 * 60 * 60) == 1 ? "" : "s"));
else
strcpy (formatted, "-");
@ -261,8 +285,8 @@ int convertDuration (const std::string& input)
std::vector <std::string> supported;
supported.push_back ("daily");
supported.push_back ("day");
supported.push_back ("weekdays");
supported.push_back ("weekly");
supported.push_back ("weekdays");
supported.push_back ("sennight");
supported.push_back ("biweekly");
supported.push_back ("fortnight");