Skip to content

Commit

Permalink
Learnt something new about paramterised test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmood199 committed Feb 27, 2024
1 parent ef75229 commit c917464
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 26 deletions.
3 changes: 0 additions & 3 deletions app/src/androidTest/AndroidTestingFilesHere.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.scrutinizing_the_service
package com.example.audify

/**
* Instrumented test, which will execute on an Android device.
Expand Down

This file was deleted.

22 changes: 22 additions & 0 deletions app/src/main/java/com/example/audify/Sample.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.audify

class Sample {


fun isPalindrome(input: String): Boolean {
var i = 0
var j = input.length - 1
var result = true

while (i < j) {
if (input[i] != input[j]) {
result = false
break
}

i++
j--
}
return result
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.scrutinizing_the_service.utils
package com.example.audify

import org.junit.Test

Expand Down
36 changes: 36 additions & 0 deletions app/src/test/java/com/example/audify/ParameterizedSampleTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.example.audify

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters

@RunWith(value = Parameterized::class)
class ParameterizedSampleTest(
val input: String,
val expectedValue: Boolean
) {

@Test
fun test() {
val sample = Sample()
val result = sample.isPalindrome(input = input)
assertEquals(result, expectedValue)
}

companion object {

@JvmStatic
@Parameters(name = "{index} : {0} is palindrome - {1}")
fun data(): List<Array<Any>> {
return listOf(
arrayOf("Hellow", false),
arrayOf("level", true),
arrayOf("m", true),
arrayOf("", true),
)
}
}

}
41 changes: 41 additions & 0 deletions app/src/test/java/com/example/audify/SampleTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.example.audify

import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test


class SampleTest {

lateinit var sample: Sample

@Before
fun setup() {
sample = Sample()
}

@Test
fun isPalindrome_input_hello_expect_false() {
// Arrange
// Act
val result = sample.isPalindrome("Hello")
// Assert
Assert.assertEquals(false, result)
}

@Test
fun isPalindrome_input_level_expect_true() {
// Arrange
// Act
val result = sample.isPalindrome("level")
// Assert
Assert.assertEquals(true, result)
}

@After
fun tearDown() {
println("After running the test")
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.scrutinizing_the_service.utils
package com.example.audify

import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
Expand Down

0 comments on commit c917464

Please sign in to comment.