From 0402d11e1ad7897fd2f702474b163b8e846cebb4 Mon Sep 17 00:00:00 2001 From: Christian Bunk Date: Sun, 6 Jan 2019 20:29:49 +0100 Subject: [PATCH] #144 add enhanced MyDate tests --- test/iii_conventions/N25ComparisonKtTest.kt | 33 ++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/test/iii_conventions/N25ComparisonKtTest.kt b/test/iii_conventions/N25ComparisonKtTest.kt index 4031bc681..6247d6420 100644 --- a/test/iii_conventions/N25ComparisonKtTest.kt +++ b/test/iii_conventions/N25ComparisonKtTest.kt @@ -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) + } } \ No newline at end of file