Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

#144 add enhanced MyDate tests #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions test/iii_conventions/N25ComparisonKtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,37 @@ class N25ComparisonKtTest {
assertTrue(task25(MyDate(2014, 1, 1), MyDate(2014, 1, 2)))
}

@Test fun testBefore() {
@Test
fun first_date_should_be_equal_second_date() {
val first = MyDate(2014, 5, 10)
val second = MyDate(2014, 7, 11)
assertTrue("The date ${first.s} should be before ${second.s}", first < second)
val second = MyDate(2014, 5, 10)
assertTrue("The date ${first.s} should be equal ${second.s}", first == second)
}

@Test fun testAfter() {
val first = MyDate(2014, 10, 20)
val second = MyDate(2014, 7, 11)
assertTrue("The date ${first.s} should be after ${second.s}", first > second)
@Test
fun first_date_should_be_before_second_date() {
MyDate(2014, 12, 31).assertBefore(2015, 1, 1)
MyDate(2014, 4, 31).assertBefore(2014, 5, 1)
MyDate(2014, 4, 10).assertBefore(2014, 4, 11)
}

@Test
fun first_date_should_be_after_second_date() {
MyDate(2015, 1, 1).assertAfter(2014, 12, 31)
MyDate(2015, 5, 1).assertAfter(2015, 4, 31)
MyDate(2015, 5, 10).assertAfter(2015, 5, 9)
}

/* If you declare 'compareTo' as an extension function, remove this one to make the code compile */
operator fun MyDate.compareTo(other: MyDate): Int = todoTask25()

private fun MyDate.assertAfter(year: Int, month: Int, dayOfMonth: Int) {
val myDate = MyDate(year, month, dayOfMonth)
assertTrue("The date $s should be after ${myDate.s}", this > myDate)
}

private fun MyDate.assertBefore(year: Int, month: Int, dayOfMonth: Int) {
val myDate = MyDate(year, month, dayOfMonth)
assertTrue("The date $s should be before ${myDate.s}", this < myDate)
}
}