Skip to content

Commit

Permalink
Merge branch 'main' into test-median
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokankara committed Mar 5, 2024
2 parents f81e446 + 7bf4242 commit 187fe0c
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 23 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Java CI with Maven

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ target/
*.iws
*.iml
*.ipr
.idea/sonarlint
target
.mvn

### Eclipse ###
.apt_generated
Expand All @@ -35,4 +38,4 @@ build/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store
16 changes: 16 additions & 0 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions .idea/sonarlint/securityhotspotstore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified README.md
Binary file not shown.
4 changes: 1 addition & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@
<version>7.9.0</version>
<scope>test</scope>
</dependency>

</dependencies>

</project>
</project>
39 changes: 39 additions & 0 deletions src/main/java/time/MonthDaysCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package time;

public class MonthDaysCalculator {

private MonthDaysCalculator() {
}

public static String[] getMonthsByDays(int days) {
return isValidDay(days)
? getMonthNames(days)
: new String[0];
}

private static String[] getMonthNames(int days) {
if (days == 28 || days == 29) {
return new String[]{MonthType.FEBRUARY.getName()};
}
int index = 0;
String[] monthNames = new String[getSize(days)];
for (MonthType month : MonthType.values()) {
if (month.getDays() == days) {
monthNames[index++] = (month.getName());
}
}
return monthNames;
}

private static int getSize(int days) {
return switch (days) {
case 31 -> 7;
case 30 -> 4;
default -> 1;
};
}

public static boolean isValidDay(int days) {
return !(days < 1 || days > 31);
}
}
45 changes: 45 additions & 0 deletions src/main/java/time/MonthType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package time;

import java.time.LocalDate;

public enum MonthType {
JANUARY("January"),
FEBRUARY("February"),
MARCH("March"),
APRIL("April"),
MAY("May"),
JUNE("June"),
JULY("July"),
AUGUST("August"),
SEPTEMBER("September"),
OCTOBER("October"),
NOVEMBER("November"),
DECEMBER("December");

private final String name;

MonthType(String name) {
this.name = name;
}

public String getName() {
return name;
}

public int getDays() {
return getDaysBy();
}

public int getDaysBy() {
return switch (this) {
case FEBRUARY -> (isLeap() ? 29 : 28);
case APRIL, JUNE, SEPTEMBER, NOVEMBER -> 30;
case JANUARY, MARCH, MAY, JULY, AUGUST, OCTOBER, DECEMBER -> 31;
};
}

private static boolean isLeap() {
int year = LocalDate.now().getYear();
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
}
1 change: 0 additions & 1 deletion src/test/java/MedianTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public void beforeClass() {

@Test
public void testMedianHN() {

}

@Test(dataProvider = "validNumberArrayProvider",
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/time/MonthDaysCalculatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package time;

import org.testng.annotations.Test;

public class MonthDaysCalculatorTest {

@Test(dataProvider = "validDays", dataProviderClass = MonthProvider.class)
public void testName(int days, String[] expected) {

}
}
10 changes: 10 additions & 0 deletions src/test/java/time/MonthProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package time;

import org.testng.annotations.DataProvider;

public class MonthProvider {
@DataProvider(name = "validDays")
public Object[][] daysProvider() {
return new Object[][]{};
}
}

0 comments on commit 187fe0c

Please sign in to comment.