|
| 1 | +# These tests are auto-generated with test data from: |
| 2 | +# https://github.com/exercism/problem-specifications/tree/main/exercises/swift-scheduling/canonical-data.json |
| 3 | +# File last updated on 2026-04-20 |
| 4 | + |
| 5 | +source("./swift-scheduling.R") |
| 6 | +library(testthat) |
| 7 | + |
| 8 | +test_that("NOW translates to two hours later", { |
| 9 | + start <- "2012-02-13T09:00:00" |
| 10 | + description <- "NOW" |
| 11 | + expected <- "2012-02-13T11:00:00" |
| 12 | + expect_equal(delivery_date(start, description), expected) |
| 13 | +}) |
| 14 | + |
| 15 | +test_that("ASAP before one in the afternoon translates to today at five in the afternoon", { |
| 16 | + start <- "1999-06-03T09:45:00" |
| 17 | + description <- "ASAP" |
| 18 | + expected <- "1999-06-03T17:00:00" |
| 19 | + expect_equal(delivery_date(start, description), expected) |
| 20 | +}) |
| 21 | + |
| 22 | +test_that("ASAP at one in the afternoon translates to tomorrow at one in the afternoon", { |
| 23 | + start <- "2008-12-21T13:00:00" |
| 24 | + description <- "ASAP" |
| 25 | + expected <- "2008-12-22T13:00:00" |
| 26 | + expect_equal(delivery_date(start, description), expected) |
| 27 | +}) |
| 28 | + |
| 29 | +test_that("ASAP after one in the afternoon translates to tomorrow at one in the afternoon", { |
| 30 | + start <- "2008-12-21T14:50:00" |
| 31 | + description <- "ASAP" |
| 32 | + expected <- "2008-12-22T13:00:00" |
| 33 | + expect_equal(delivery_date(start, description), expected) |
| 34 | +}) |
| 35 | + |
| 36 | +test_that("EOW on Monday translates to Friday at five in the afternoon", { |
| 37 | + start <- "2025-02-03T16:00:00" |
| 38 | + description <- "EOW" |
| 39 | + expected <- "2025-02-07T17:00:00" |
| 40 | + expect_equal(delivery_date(start, description), expected) |
| 41 | +}) |
| 42 | + |
| 43 | +test_that("EOW on Tuesday translates to Friday at five in the afternoon", { |
| 44 | + start <- "1997-04-29T10:50:00" |
| 45 | + description <- "EOW" |
| 46 | + expected <- "1997-05-02T17:00:00" |
| 47 | + expect_equal(delivery_date(start, description), expected) |
| 48 | +}) |
| 49 | + |
| 50 | +test_that("EOW on Wednesday translates to Friday at five in the afternoon", { |
| 51 | + start <- "2005-09-14T11:00:00" |
| 52 | + description <- "EOW" |
| 53 | + expected <- "2005-09-16T17:00:00" |
| 54 | + expect_equal(delivery_date(start, description), expected) |
| 55 | +}) |
| 56 | + |
| 57 | +test_that("EOW on Thursday translates to Sunday at eight in the evening", { |
| 58 | + start <- "2011-05-19T08:30:00" |
| 59 | + description <- "EOW" |
| 60 | + expected <- "2011-05-22T20:00:00" |
| 61 | + expect_equal(delivery_date(start, description), expected) |
| 62 | +}) |
| 63 | + |
| 64 | +test_that("EOW on Friday translates to Sunday at eight in the evening", { |
| 65 | + start <- "2022-08-05T14:00:00" |
| 66 | + description <- "EOW" |
| 67 | + expected <- "2022-08-07T20:00:00" |
| 68 | + expect_equal(delivery_date(start, description), expected) |
| 69 | +}) |
| 70 | + |
| 71 | +test_that("EOW translates to leap day", { |
| 72 | + start <- "2008-02-25T10:30:00" |
| 73 | + description <- "EOW" |
| 74 | + expected <- "2008-02-29T17:00:00" |
| 75 | + expect_equal(delivery_date(start, description), expected) |
| 76 | +}) |
| 77 | + |
| 78 | +test_that("2M before the second month of this year translates to the first workday of the second month of this year", { |
| 79 | + start <- "2007-01-02T14:15:00" |
| 80 | + description <- "2M" |
| 81 | + expected <- "2007-02-01T08:00:00" |
| 82 | + expect_equal(delivery_date(start, description), expected) |
| 83 | +}) |
| 84 | + |
| 85 | +test_that("11M in the eleventh month translates to the first workday of the eleventh month of next year", { |
| 86 | + start <- "2013-11-21T15:30:00" |
| 87 | + description <- "11M" |
| 88 | + expected <- "2014-11-03T08:00:00" |
| 89 | + expect_equal(delivery_date(start, description), expected) |
| 90 | +}) |
| 91 | + |
| 92 | +test_that("4M in the ninth month translates to the first workday of the fourth month of next year", { |
| 93 | + start <- "2019-11-18T15:15:00" |
| 94 | + description <- "4M" |
| 95 | + expected <- "2020-04-01T08:00:00" |
| 96 | + expect_equal(delivery_date(start, description), expected) |
| 97 | +}) |
| 98 | + |
| 99 | +test_that("Q1 in the first quarter translates to the last workday of the first quarter of this year", { |
| 100 | + start <- "2003-01-01T10:45:00" |
| 101 | + description <- "Q1" |
| 102 | + expected <- "2003-03-31T08:00:00" |
| 103 | + expect_equal(delivery_date(start, description), expected) |
| 104 | +}) |
| 105 | + |
| 106 | +test_that("Q4 in the second quarter translates to the last workday of the fourth quarter of this year", { |
| 107 | + start <- "2001-04-09T09:00:00" |
| 108 | + description <- "Q4" |
| 109 | + expected <- "2001-12-31T08:00:00" |
| 110 | + expect_equal(delivery_date(start, description), expected) |
| 111 | +}) |
| 112 | + |
| 113 | +test_that("Q3 in the fourth quarter translates to the last workday of the third quarter of next year", { |
| 114 | + start <- "2022-10-06T11:00:00" |
| 115 | + description <- "Q3" |
| 116 | + expected <- "2023-09-29T08:00:00" |
| 117 | + expect_equal(delivery_date(start, description), expected) |
| 118 | +}) |
0 commit comments