From 0fe566b7057d8bdb38f53790d96d4810c32e00e8 Mon Sep 17 00:00:00 2001 From: UdaySravanK <> Date: Sat, 18 May 2024 21:51:58 -0400 Subject: [PATCH] Added more test cases --- .../jcnumberpicker/ItemPickerHelperTest.kt | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/JCNumberPicker/src/test/java/com/usk/jcnumberpicker/ItemPickerHelperTest.kt b/JCNumberPicker/src/test/java/com/usk/jcnumberpicker/ItemPickerHelperTest.kt index a6f8992..21934db 100644 --- a/JCNumberPicker/src/test/java/com/usk/jcnumberpicker/ItemPickerHelperTest.kt +++ b/JCNumberPicker/src/test/java/com/usk/jcnumberpicker/ItemPickerHelperTest.kt @@ -28,4 +28,110 @@ class ItemPickerHelperTest { // Verify assertEquals(testList.first(), result) } + + @Test + fun `Case 2 - get second item from the list as selected item`() { + // Execute + val result = determineTheSelectedItem( + offset = 0, + position = 1, + items = testList + ) + + // Verify + assertEquals(testList[1], result) + } + + @Test + fun `Case 2 - get last but one item from the list as selected item`() { + // Execute + val positionOfLastButOne = testList.size - 2 // position 1 + val result = determineTheSelectedItem( + offset = 0, + position = positionOfLastButOne, + items = testList + ) + + // Verify + assertEquals(testList[positionOfLastButOne], result) + } + + @Test + fun `Case 3 - get the last item from list as selected item`() { + // Execute + val positionOfLastItem = testList.size - 1 // position 2 + val result = determineTheSelectedItem( + offset = 0, + position = positionOfLastItem, + items = testList + ) + + // Verify + assertEquals(testList[positionOfLastItem], result) + } + + @Test + fun `Case 4 - get the second item from list as selected item if position is 0 but offset is grater than 0`() { + // Execute + val result = determineTheSelectedItem( + offset = 1, + position = 0, + items = testList + ) + + // Verify + assertEquals(testList[1], result) + } + + @Test + fun `Case 5 - get the last item from list as selected item if position is 1 but offset is grater than 0`() { + // Execute + val result = determineTheSelectedItem( + offset = 1, + position = 1, + items = testList + ) + + // Verify + assertEquals(testList[2], result) + } + + @Test + fun `Case 6 - get the last item from list as selected item if position is 2 but offset is grater than 0`() { + // Execute + val result = determineTheSelectedItem( + offset = 1, + position = 2, + items = testList + ) + + // Verify + assertEquals(testList[2], result) + } + + @Test + fun `offset can be greater than 1`() { + // Execute + val result = determineTheSelectedItem( + offset = 5, + position = 0, + items = testList + ) + + // Verify + assertEquals(testList[1], result) + } + + @Test + fun `return the last item for invalid offset and position combination`() { + // Execute + val result = determineTheSelectedItem( + offset = 5, + position = 2, + items = testList + ) + + // Verify + assertEquals(testList[2], result) + } } \ No newline at end of file