diff --git a/config.json b/config.json index bf9df02b3..1356cbf81 100644 --- a/config.json +++ b/config.json @@ -854,6 +854,18 @@ ], "difficulty": 4 }, + { + "slug": "swift-scheduling", + "name": "Swift Scheduling", + "uuid": "7f5388dc-ce0e-40d4-98d1-7a00aeae018d", + "practices": [], + "prerequisites": [ + "if-else-statements", + "datetime", + "strings" + ], + "difficulty": 4 + }, { "slug": "triangle", "name": "Triangle", diff --git a/exercises/practice/swift-scheduling/.docs/instructions.md b/exercises/practice/swift-scheduling/.docs/instructions.md new file mode 100644 index 000000000..6423a1066 --- /dev/null +++ b/exercises/practice/swift-scheduling/.docs/instructions.md @@ -0,0 +1,50 @@ +# Instructions + +Your task is to convert delivery date descriptions to _actual_ delivery dates, based on when the meeting started. + +There are two types of delivery date descriptions: + +1. Fixed: a predefined set of words. +2. Variable: words that have a variable component, but follow a predefined set of patterns. + +## Fixed delivery date descriptions + +There are three fixed delivery date descriptions: + +- `"NOW"` +- `"ASAP"` (As Soon As Possible) +- `"EOW"` (End Of Week) + +The following table shows how to translate them: + +| Description | Meeting start | Delivery date | +| ----------- | ----------------------------- | ----------------------------------- | +| `"NOW"` | - | Two hours after the meeting started | +| `"ASAP"` | Before 13:00 | Today at 17:00 | +| `"ASAP"` | After or at 13:00 | Tomorrow at 13:00 | +| `"EOW"` | Monday, Tuesday, or Wednesday | Friday at 17:00 | +| `"EOW"` | Thursday or Friday | Sunday at 20:00 | + +## Variable delivery date descriptions + +There are two variable delivery date description patterns: + +- `"M"` (N-th month) +- `"Q"` (N-th quarter) + +| Description | Meeting start | Delivery date | +| ----------- | ------------------------- | --------------------------------------------------------- | +| `"M"` | Before N-th month | At 8:00 on the _first_ workday of this year's N-th month | +| `"M"` | After or in N-th month | At 8:00 on the _first_ workday of next year's N-th month | +| `"Q"` | Before or in N-th quarter | At 8:00 on the _last_ workday of this year's N-th quarter | +| `"Q"` | After N-th quarter | At 8:00 on the _last_ workday of next year's N-th quarter | + +~~~~exercism/note +A workday is a Monday, Tuesday, Wednesday, Thursday, or Friday. + +A year has four quarters, each with three months: +1. January/February/March +2. April/May/June +3. July/August/September +4. October/November/December. +~~~~ diff --git a/exercises/practice/swift-scheduling/.docs/introduction.md b/exercises/practice/swift-scheduling/.docs/introduction.md new file mode 100644 index 000000000..2322f813f --- /dev/null +++ b/exercises/practice/swift-scheduling/.docs/introduction.md @@ -0,0 +1,6 @@ +# Introduction + +This week, it is your turn to take notes in the department's planning meeting. +In this meeting, your boss will set delivery dates for all open work items. +Annoyingly, instead of specifying the _actual_ delivery dates, your boss will only _describe them_ in an abbreviated format. +As many of your colleagues won't be familiar with this corporate lingo, you'll need to convert these delivery date descriptions to actual delivery dates. diff --git a/exercises/practice/swift-scheduling/.meta/config.json b/exercises/practice/swift-scheduling/.meta/config.json new file mode 100644 index 000000000..d555a97e2 --- /dev/null +++ b/exercises/practice/swift-scheduling/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "zamora-carlos" + ], + "files": { + "solution": [ + "src/main/java/SwiftScheduling.java" + ], + "test": [ + "src/test/java/SwiftSchedulingTest.java" + ], + "example": [ + ".meta/src/reference/java/SwiftScheduling.java" + ] + }, + "blurb": "Convert delivery date descriptions to actual delivery dates.", + "source": "Erik Schierboom", + "source_url": "https://github.com/exercism/problem-specifications/pull/2536" +} diff --git a/exercises/practice/swift-scheduling/.meta/src/reference/java/SwiftScheduling.java b/exercises/practice/swift-scheduling/.meta/src/reference/java/SwiftScheduling.java new file mode 100644 index 000000000..8bff6e3d3 --- /dev/null +++ b/exercises/practice/swift-scheduling/.meta/src/reference/java/SwiftScheduling.java @@ -0,0 +1,97 @@ +import java.time.DayOfWeek; +import java.time.LocalDateTime; + +import static java.time.DayOfWeek.*; + +public class SwiftScheduling { + public static LocalDateTime convertToDeliveryDate(LocalDateTime meetingStart, String description) { + if ("NOW".equals(description)) { + return meetingStart.plusHours(2); + } + + if ("ASAP".equals(description)) { + LocalDateTime sameDayAt1pm = toStartOfDay(meetingStart).withHour(13); + + if (meetingStart.isBefore(sameDayAt1pm)) { + return toStartOfDay(meetingStart).withHour(17); + } else { + return toStartOfDay(meetingStart).plusDays(1).withHour(13); + } + } + + if ("EOW".equals(description)) { + DayOfWeek day = meetingStart.getDayOfWeek(); + LocalDateTime deliveryDate = toStartOfDay(meetingStart); + + if (day == MONDAY || day == TUESDAY || day == WEDNESDAY) { + deliveryDate = deliveryDate.withHour(17); + while (deliveryDate.getDayOfWeek() != FRIDAY) { + deliveryDate = deliveryDate.plusDays(1); + } + } else if (day == THURSDAY || day == FRIDAY) { + deliveryDate = deliveryDate.withHour(20); + while (deliveryDate.getDayOfWeek() != SUNDAY) { + deliveryDate = deliveryDate.plusDays(1); + } + } else { + throw new IllegalArgumentException("Invalid day of week"); + } + + return deliveryDate; + } + + if (description.matches("\\d+M")) { + int month = Integer.parseInt(description.substring(0, description.length() - 1)); + LocalDateTime targetMonth = toStartOfDay(meetingStart) + .withMonth(month) + .withDayOfMonth(1); + + if (!meetingStart.isBefore(targetMonth)) { + targetMonth = targetMonth.plusYears(1); + } + + LocalDateTime deliveryDate = targetMonth.withHour(8); + while (isWeekend(deliveryDate)) { + deliveryDate = deliveryDate.plusDays(1); + } + + return deliveryDate; + } + + if (description.matches("Q\\d")) { + int quarter = Integer.parseInt(description.substring(1)); + LocalDateTime lastDayOfQuarter = getLastDayOfQuarter(meetingStart, quarter); + + if (!meetingStart.isBefore(lastDayOfQuarter.plusDays(1))) { + lastDayOfQuarter = lastDayOfQuarter.plusYears(1); + } + + LocalDateTime deliveryDate = lastDayOfQuarter.withHour(8); + while (isWeekend(deliveryDate)) { + deliveryDate = deliveryDate.minusDays(1); + } + + return deliveryDate; + } + + throw new IllegalArgumentException("Invalid description"); + } + + private static LocalDateTime toStartOfDay(LocalDateTime dateTime) { + return dateTime.toLocalDate().atStartOfDay(); + } + + private static LocalDateTime getLastDayOfQuarter(LocalDateTime dateTime, int quarter) { + int lastMonthOfQuarter = quarter * 3; + return toStartOfDay(dateTime) + .withMonth(lastMonthOfQuarter) + .withDayOfMonth(1) + .plusMonths(1) + .minusDays(1); + } + + private static boolean isWeekend(LocalDateTime date) { + DayOfWeek dayOfWeek = date.getDayOfWeek(); + return dayOfWeek == SATURDAY || dayOfWeek == SUNDAY; + } +} diff --git a/exercises/practice/swift-scheduling/.meta/tests.toml b/exercises/practice/swift-scheduling/.meta/tests.toml new file mode 100644 index 000000000..7cc3e4158 --- /dev/null +++ b/exercises/practice/swift-scheduling/.meta/tests.toml @@ -0,0 +1,58 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[1d0e6e72-f370-408c-bc64-5dafa9c6da73] +description = "NOW translates to two hours later" + +[93325e7b-677d-4d96-b017-2582af879dc2] +description = "ASAP before one in the afternoon translates to today at five in the afternoon" + +[cb4252a3-c4c1-41f6-8b8c-e7269733cef8] +description = "ASAP at one in the afternoon translates to tomorrow at one in the afternoon" + +[6fddc1ea-2fe9-4c60-81f7-9220d2f45537] +description = "ASAP after one in the afternoon translates to tomorrow at one in the afternoon" + +[25f46bf9-6d2a-4e95-8edd-f62dd6bc8a6e] +description = "EOW on Monday translates to Friday at five in the afternoon" + +[0b375df5-d198-489e-acee-fd538a768616] +description = "EOW on Tuesday translates to Friday at five in the afternoon" + +[4afbb881-0b5c-46be-94e1-992cdc2a8ca4] +description = "EOW on Wednesday translates to Friday at five in the afternoon" + +[e1341c2b-5e1b-4702-a95c-a01e8e96e510] +description = "EOW on Thursday translates to Sunday at eight in the evening" + +[bbffccf7-97f7-4244-888d-bdd64348fa2e] +description = "EOW on Friday translates to Sunday at eight in the evening" + +[d651fcf4-290e-407c-8107-36b9076f39b2] +description = "EOW translates to leap day" + +[439bf09f-3a0e-44e7-bad5-b7b6d0c4505a] +description = "2M before the second month of this year translates to the first workday of the second month of this year" + +[86d82e83-c481-4fb4-9264-625de7521340] +description = "11M in the eleventh month translates to the first workday of the eleventh month of next year" + +[0d0b8f6a-1915-46f5-a630-1ff06af9da08] +description = "4M in the ninth month translates to the first workday of the fourth month of next year" + +[06d401e3-8461-438f-afae-8d26aa0289e0] +description = "Q1 in the first quarter translates to the last workday of the first quarter of this year" + +[eebd5f32-b16d-4ecd-91a0-584b0364b7ed] +description = "Q4 in the second quarter translates to the last workday of the fourth quarter of this year" + +[c920886c-44ad-4d34-a156-dc4176186581] +description = "Q3 in the fourth quarter translates to the last workday of the third quarter of next year" diff --git a/exercises/practice/swift-scheduling/build.gradle b/exercises/practice/swift-scheduling/build.gradle new file mode 100644 index 000000000..dd3862eb9 --- /dev/null +++ b/exercises/practice/swift-scheduling/build.gradle @@ -0,0 +1,25 @@ +plugins { + id "java" +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform("org.junit:junit-bom:5.10.0") + testImplementation "org.junit.jupiter:junit-jupiter" + testImplementation "org.assertj:assertj-core:3.25.1" + + testRuntimeOnly "org.junit.platform:junit-platform-launcher" +} + +test { + useJUnitPlatform() + + testLogging { + exceptionFormat = "full" + showStandardStreams = true + events = ["passed", "failed", "skipped"] + } +} diff --git a/exercises/practice/swift-scheduling/gradle/wrapper/gradle-wrapper.jar b/exercises/practice/swift-scheduling/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..e6441136f Binary files /dev/null and b/exercises/practice/swift-scheduling/gradle/wrapper/gradle-wrapper.jar differ diff --git a/exercises/practice/swift-scheduling/gradle/wrapper/gradle-wrapper.properties b/exercises/practice/swift-scheduling/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..2deab89d5 --- /dev/null +++ b/exercises/practice/swift-scheduling/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/exercises/practice/swift-scheduling/gradlew b/exercises/practice/swift-scheduling/gradlew new file mode 100755 index 000000000..1aa94a426 --- /dev/null +++ b/exercises/practice/swift-scheduling/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/exercises/practice/swift-scheduling/gradlew.bat b/exercises/practice/swift-scheduling/gradlew.bat new file mode 100644 index 000000000..93e3f59f1 --- /dev/null +++ b/exercises/practice/swift-scheduling/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/exercises/practice/swift-scheduling/src/main/java/SwiftScheduling.java b/exercises/practice/swift-scheduling/src/main/java/SwiftScheduling.java new file mode 100644 index 000000000..e5b85bec9 --- /dev/null +++ b/exercises/practice/swift-scheduling/src/main/java/SwiftScheduling.java @@ -0,0 +1,7 @@ +import java.time.LocalDateTime; + +public class SwiftScheduling { + public static LocalDateTime convertToDeliveryDate(LocalDateTime meetingStart, String description) { + throw new UnsupportedOperationException("Delete this statement and write your own implementation."); + } +} diff --git a/exercises/practice/swift-scheduling/src/test/java/SwiftSchedulingTest.java b/exercises/practice/swift-scheduling/src/test/java/SwiftSchedulingTest.java new file mode 100644 index 000000000..03f6c6c9c --- /dev/null +++ b/exercises/practice/swift-scheduling/src/test/java/SwiftSchedulingTest.java @@ -0,0 +1,200 @@ +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.assertThat; + +class SwiftSchedulingTest { + @Test + @DisplayName("NOW at 9 AM") + void testNowAtNineAm() { + LocalDateTime meetingStart = LocalDateTime.parse("2012-02-13T09:00:00"); + LocalDateTime expected = LocalDateTime.parse("2012-02-13T11:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "NOW"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("ASAP before 1 PM") + void testAsapBeforeOnePm() { + LocalDateTime meetingStart = LocalDateTime.parse("1999-06-03T09:45:00"); + LocalDateTime expected = LocalDateTime.parse("1999-06-03T17:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "ASAP"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("ASAP at 1 PM") + void testAsapAtOnePm() { + LocalDateTime meetingStart = LocalDateTime.parse("2008-12-21T13:00:00"); + LocalDateTime expected = LocalDateTime.parse("2008-12-22T13:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "ASAP"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("ASAP after 1 PM") + void testAsapAfterOnePm() { + LocalDateTime meetingStart = LocalDateTime.parse("2008-12-21T14:50:00"); + LocalDateTime expected = LocalDateTime.parse("2008-12-22T13:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "ASAP"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("EOW on Monday") + void testEowOnMonday() { + LocalDateTime meetingStart = LocalDateTime.parse("2025-02-03T16:00:00"); + LocalDateTime expected = LocalDateTime.parse("2025-02-07T17:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "EOW"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("EOW on Tuesday") + void testEowOnTuesday() { + LocalDateTime meetingStart = LocalDateTime.parse("1997-04-29T10:50:00"); + LocalDateTime expected = LocalDateTime.parse("1997-05-02T17:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "EOW"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("EOW on Wednesday") + void testEowOnWednesday() { + LocalDateTime meetingStart = LocalDateTime.parse("2005-09-14T11:00:00"); + LocalDateTime expected = LocalDateTime.parse("2005-09-16T17:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "EOW"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("EOW on Thursday") + void testEowOnThursday() { + LocalDateTime meetingStart = LocalDateTime.parse("2011-05-19T08:30:00"); + LocalDateTime expected = LocalDateTime.parse("2011-05-22T20:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "EOW"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("EOW on Friday") + void testEowOnFriday() { + LocalDateTime meetingStart = LocalDateTime.parse("2022-08-05T14:00:00"); + LocalDateTime expected = LocalDateTime.parse("2022-08-07T20:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "EOW"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("EOW in leap year") + void testEowDuringLeapYear() { + LocalDateTime meetingStart = LocalDateTime.parse("2008-02-25T10:30:00"); + LocalDateTime expected = LocalDateTime.parse("2008-02-29T17:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "EOW"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("2M in January") + void test2MInJanuary() { + LocalDateTime meetingStart = LocalDateTime.parse("2007-01-02T14:15:00"); + LocalDateTime expected = LocalDateTime.parse("2007-02-01T08:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "2M"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("11M in November") + void test11MInNovember() { + LocalDateTime meetingStart = LocalDateTime.parse("2013-11-21T15:30:00"); + LocalDateTime expected = LocalDateTime.parse("2014-11-03T08:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "11M"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("4M in November") + void test4MInNovember() { + LocalDateTime meetingStart = LocalDateTime.parse("2019-11-18T15:15:00"); + LocalDateTime expected = LocalDateTime.parse("2020-04-01T08:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "4M"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("Q1 in Q1") + void testQ1InQ1() { + LocalDateTime meetingStart = LocalDateTime.parse("2003-01-01T10:45:00"); + LocalDateTime expected = LocalDateTime.parse("2003-03-31T08:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "Q1"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("Q4 in Q2") + void testQ4InQ2() { + LocalDateTime meetingStart = LocalDateTime.parse("2001-04-09T09:00:00"); + LocalDateTime expected = LocalDateTime.parse("2001-12-31T08:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "Q4"); + + assertThat(actual).isEqualTo(expected); + } + + @Disabled("Remove to run test") + @Test + @DisplayName("Q3 in Q4") + void testQ3InQ4() { + LocalDateTime meetingStart = LocalDateTime.parse("2022-10-06T11:00:00"); + LocalDateTime expected = LocalDateTime.parse("2023-09-29T08:00:00"); + + LocalDateTime actual = SwiftScheduling.convertToDeliveryDate(meetingStart, "Q3"); + + assertThat(actual).isEqualTo(expected); + } +} diff --git a/exercises/settings.gradle b/exercises/settings.gradle index 61f9b0991..2955a15dc 100644 --- a/exercises/settings.gradle +++ b/exercises/settings.gradle @@ -149,6 +149,7 @@ include 'practice:state-of-tic-tac-toe' // include 'practice:strain' // deprecated include 'practice:sublist' include 'practice:sum-of-multiples' +include 'practice:swift-scheduling' include 'practice:tournament' include 'practice:transpose' include 'practice:tree-building'