-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(7-kyu): kata/day-of-the-year (#455)
- Loading branch information
1 parent
66b4e5b
commit b54d97f
Showing
5 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# [Day of the Year](https://www.codewars.com/kata/day-of-the-year "https://www.codewars.com/kata/5a1ebe0d46d843454100004c") | ||
|
||
Work out what number day of the year it is. | ||
|
||
``` | ||
toDayOfYear([1, 1, 2000]) => 1 | ||
``` | ||
|
||
The argument passed into the function is an array with the format `[D, M, YYYY]`, | ||
e.g. `[1, 2, 2000]` for February 1st, 2000 or `[22, 12, 1999]` for December 22nd, 1999. | ||
|
||
Don't forget to check for whether it's a [leap year](https://en.wikipedia.org/wiki/Leap_year)! Three | ||
criteria must be taken into account to identify leap years: | ||
|
||
- The year can be evenly divided by 4; | ||
- If the year can be evenly divided by 100, it is NOT a leap year, unless; | ||
- The year is also evenly divisible by 400. Then it is a leap year. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import static java.time.LocalDate.of; | ||
|
||
interface DateToInt { | ||
static int toDayOfYear(int[] date) { | ||
return of(date[2], date[1], date[0]).getDayOfYear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class SolutionTest { | ||
@Test | ||
void sample() { | ||
assertEquals(145, DateToInt.toDayOfYear(new int[]{25, 5, 2022})); | ||
assertEquals(137, DateToInt.toDayOfYear(new int[]{17, 5, 1991})); | ||
assertEquals(295, DateToInt.toDayOfYear(new int[]{22, 10, 1990})); | ||
assertEquals(1, DateToInt.toDayOfYear(new int[]{1, 1, 2001})); | ||
assertEquals(1, DateToInt.toDayOfYear(new int[]{1, 1, 2000})); | ||
assertEquals(365, DateToInt.toDayOfYear(new int[]{31, 12, 2003})); | ||
assertEquals(366, DateToInt.toDayOfYear(new int[]{31, 12, 2004})); | ||
assertEquals(60, DateToInt.toDayOfYear(new int[]{29, 2, 2008})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters