-
Notifications
You must be signed in to change notification settings - Fork 18
251114_02_김현진 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
japygo
wants to merge
2
commits into
SurvivalCodingCampus:master
Choose a base branch
from
japygo:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
251114_02_김현진 #13
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,76 +1,46 @@ | ||
| package com.survivalcoding | ||
|
|
||
| import java.time.LocalDateTime | ||
| import java.time.format.DateTimeFormatter | ||
|
|
||
| class YukymController { | ||
|
|
||
| val nowDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-mm-dd")) | ||
|
|
||
| lateinit var nowTime: String | ||
|
|
||
| fun getTyA(): String { | ||
| val timeDataOne = _getTimeDataOne(nowDate) | ||
|
|
||
| if (timeDataOne.isNotEmpty()) { | ||
| nowTime = timeDataOne.first().ty1 | ||
|
|
||
| val month = nowDate.substring(5, 7) | ||
| return when (month) { | ||
| "01", "02" -> "경오1국" | ||
| "03", "04" -> "경오2국" | ||
| "05", "06" -> "경오3국" | ||
| "07", "08" -> "경오4국" | ||
| "09", "10" -> "경오5국" | ||
| "11", "12" -> "경오6국" | ||
| else -> nowTime | ||
| } | ||
| } else { | ||
| return "경오7국" | ||
| } | ||
| class YukymController( | ||
| private val now: LocalDateTime = LocalDateTime.now() | ||
| ) { | ||
| fun getTyA(): String = when (now.monthValue) { | ||
| 1, 2 -> "경오1국" | ||
| 3, 4 -> "경오2국" | ||
| 5, 6 -> "경오3국" | ||
| 7, 8 -> "경오4국" | ||
| 9, 10 -> "경오5국" | ||
| 11, 12 -> "경오6국" | ||
| else -> TY1 | ||
| } | ||
|
|
||
| fun getTyB(): String { | ||
| val timeDataOne = _getTimeDataOne(nowDate) | ||
| var result = timeDataOne.first().ty12 | ||
|
|
||
| val nowTime = LocalDateTime.now() | ||
| when { | ||
| nowTime.hour >= 0 || nowTime.hour < 2 -> return timeDataOne.first().ty1 | ||
| nowTime.hour >= 4 || nowTime.hour < 6 -> return timeDataOne.first().ty2 | ||
| nowTime.hour >= 6 || nowTime.hour < 8 -> return timeDataOne.first().ty3 | ||
| nowTime.hour >= 8 || nowTime.hour < 10 -> return timeDataOne.first().ty4 | ||
| nowTime.hour >= 10 || nowTime.hour < 12 -> return timeDataOne.first().ty5 | ||
| nowTime.hour >= 12 || nowTime.hour < 14 -> return timeDataOne.first().ty6 | ||
| nowTime.hour >= 16 || nowTime.hour < 18 -> return timeDataOne.first().ty7 | ||
| nowTime.hour >= 18 || nowTime.hour < 20 -> return timeDataOne.first().ty8 | ||
| nowTime.hour >= 20 || nowTime.hour < 22 -> return timeDataOne.first().ty9 | ||
| nowTime.hour >= 22 || nowTime.hour < 24 -> return timeDataOne.first().ty10 | ||
| } | ||
|
|
||
| return result | ||
| fun getTyB(): String = when (now.hour) { | ||
| in 0..<2 -> TY1 | ||
| in 4..<6 -> TY2 | ||
| in 6..<8 -> TY3 | ||
| in 8..<10 -> TY4 | ||
| in 10..<12 -> TY5 | ||
| in 12..<14 -> TY6 | ||
| in 16..<18 -> TY7 | ||
| in 18..<20 -> TY8 | ||
| in 20..<22 -> TY9 | ||
| in 22..<24 -> TY10 | ||
| else -> TY12 | ||
| } | ||
|
|
||
| private fun _getTimeDataOne(nowDate: String): List<YukymTimeModel> { | ||
| val timeDataOne = mutableListOf<YukymTimeModel>() | ||
| for (i in 0..24) { | ||
| timeDataOne.add(YukymTimeModel()) | ||
| } | ||
| return timeDataOne | ||
| companion object { | ||
| const val TY1: String = "갑자1국" | ||
| const val TY2: String = "갑자2국" | ||
| const val TY3: String = "갑자3국" | ||
| const val TY4: String = "갑자4국" | ||
| const val TY5: String = "갑자5국" | ||
| const val TY6: String = "갑자6국" | ||
| const val TY7: String = "갑자7국" | ||
| const val TY8: String = "갑자8국" | ||
| const val TY9: String = "갑자9국" | ||
| const val TY10: String = "갑자10국" | ||
| const val TY11: String = "갑자11국" | ||
| const val TY12: String = "갑자12국" | ||
| } | ||
| } | ||
|
|
||
| data class YukymTimeModel( | ||
| val ty1: String = "갑자1국", | ||
| val ty2: String = "갑자2국", | ||
| val ty3: String = "갑자3국", | ||
| val ty4: String = "갑자4국", | ||
| val ty5: String = "갑자5국", | ||
| val ty6: String = "갑자6국", | ||
| val ty7: String = "갑자7국", | ||
| val ty8: String = "갑자8국", | ||
| val ty9: String = "갑자9국", | ||
| val ty10: String = "갑자10국", | ||
| val ty11: String = "갑자11국", | ||
| val ty12: String = "갑자12국" | ||
| ) | ||
This file contains hidden or 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,60 @@ | ||
| import com.survivalcoding.YukymController | ||
| import org.junit.jupiter.api.Assertions.* | ||
| import java.time.LocalDateTime | ||
| import kotlin.test.Test | ||
|
|
||
| class YukymControllerTest { | ||
| @Test | ||
| fun `해당 월에 맞는 자시의 국 표시된다`() { | ||
| assertMonthRange(1..2, "경오1국") | ||
| assertMonthRange(3..4, "경오2국") | ||
| assertMonthRange(5..6, "경오3국") | ||
| assertMonthRange(7..8, "경오4국") | ||
| assertMonthRange(9..10, "경오5국") | ||
| assertMonthRange(11..12, "경오6국") | ||
| } | ||
|
|
||
| @Test | ||
| fun `해당 시간에 맞는 자시의 국 표시된다`() { | ||
| assertHourRange(0..<2, "갑자1국") | ||
| assertHourRange(2..<4, "갑자12국") | ||
| assertHourRange(4..<6, "갑자2국") | ||
| assertHourRange(6..<8, "갑자3국") | ||
| assertHourRange(8..<10, "갑자4국") | ||
| assertHourRange(10..<12, "갑자5국") | ||
| assertHourRange(12..<14, "갑자6국") | ||
| assertHourRange(14..<16, "갑자12국") | ||
| assertHourRange(16..<18, "갑자7국") | ||
| assertHourRange(18..<20, "갑자8국") | ||
| assertHourRange(20..<22, "갑자9국") | ||
| assertHourRange(22..<24, "갑자10국") | ||
| } | ||
|
|
||
| private fun assertMonthRange(months: IntRange, expected: String) { | ||
| months.forEach { month -> | ||
| // given | ||
| val now = LocalDateTime.of(2020, month, 2, 2, 22) | ||
| val yukymController = YukymController(now) | ||
|
|
||
| // when | ||
| val tyA = yukymController.getTyA() | ||
|
|
||
| // then | ||
| assertEquals(expected, tyA) | ||
| } | ||
| } | ||
|
|
||
| private fun assertHourRange(hours: IntRange, expected: String) { | ||
| hours.forEach { hour -> | ||
| // given | ||
| val now = LocalDateTime.of(2020, 2, 2, hour, 22) | ||
| val yukymController = YukymController(now) | ||
|
|
||
| // when | ||
| val tyB = yukymController.getTyB() | ||
|
|
||
| // then | ||
| assertEquals(expected, tyB) | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.