2024-01-17 02:44:33 +05:30
|
|
|
package com.example.hpostesting
|
|
|
|
|
|
2024-01-26 11:20:13 +05:30
|
|
|
import android.content.Context
|
2024-01-17 02:44:33 +05:30
|
|
|
import android.content.SharedPreferences
|
|
|
|
|
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
|
|
|
|
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
|
|
|
|
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
|
|
|
|
import junit.framework.TestCase
|
2024-01-26 07:48:15 +05:30
|
|
|
import junit.framework.TestCase.assertEquals
|
|
|
|
|
import junit.framework.TestCase.assertNull
|
2024-01-17 02:44:33 +05:30
|
|
|
import org.junit.Before
|
|
|
|
|
import org.junit.Test
|
|
|
|
|
import org.mockito.ArgumentMatchers
|
|
|
|
|
import org.mockito.Mock
|
|
|
|
|
import org.mockito.Mockito
|
|
|
|
|
import org.mockito.MockitoAnnotations
|
|
|
|
|
|
|
|
|
|
class HemoCubeFragmentTest {
|
|
|
|
|
|
2024-01-26 11:20:13 +05:30
|
|
|
@Mock
|
|
|
|
|
lateinit var mockContext: Context
|
|
|
|
|
|
2024-01-17 02:44:33 +05:30
|
|
|
@Mock
|
|
|
|
|
private lateinit var mockSharedPreferences: SharedPreferences
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
private lateinit var mockActivity: HemocubeActivity // Replace with your actual Activity class
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
private lateinit var mockBinding: FragmentHemoCubeReferenceBinding // Replace with your actual Binding class
|
|
|
|
|
|
|
|
|
|
private lateinit var hemoCubeFragment: HemoCubeFragment
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
fun setUp() {
|
|
|
|
|
MockitoAnnotations.initMocks(this)
|
|
|
|
|
hemoCubeFragment = HemoCubeFragment()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2024-01-26 11:20:13 +05:30
|
|
|
fun `extractV2HardwareId to get device id`() {
|
2024-01-17 02:44:33 +05:30
|
|
|
// Arrange
|
|
|
|
|
Mockito.`when`(
|
|
|
|
|
mockSharedPreferences.getString(
|
|
|
|
|
ArgumentMatchers.anyString(),
|
|
|
|
|
ArgumentMatchers.anyString()
|
|
|
|
|
)
|
|
|
|
|
).thenReturn("dummy_value")
|
|
|
|
|
|
|
|
|
|
// Act
|
2024-01-26 07:48:15 +05:30
|
|
|
val deviceId = hemoCubeFragment.extractV2HardwareId("SNS HPP1-9000 SNE")
|
2024-01-17 02:44:33 +05:30
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
TestCase.assertEquals("HPP1-9000", deviceId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `updateDeviceId in shared pref`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
Mockito.`when`(
|
|
|
|
|
mockSharedPreferences.getString(
|
|
|
|
|
ArgumentMatchers.anyString(),
|
|
|
|
|
ArgumentMatchers.anyString()
|
|
|
|
|
)
|
|
|
|
|
).thenReturn("HPP1-0001")
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val deviceId = mockSharedPreferences.getString(
|
|
|
|
|
ArgumentMatchers.anyString(),
|
|
|
|
|
ArgumentMatchers.anyString()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
TestCase.assertEquals("HPP1-0001", deviceId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `allReadingsComplete check`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val repeatReadingCount = 1
|
|
|
|
|
val readingsPerSample = 1
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.allReadingsComplete(repeatReadingCount, readingsPerSample)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
TestCase.assertEquals(true, result)
|
|
|
|
|
TestCase.assertEquals(hemoCubeFragment.allReadingsComplete(0, 1), false)
|
|
|
|
|
}
|
2024-01-26 07:48:15 +05:30
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV1HardwareId should return hardware ID when input contains SN`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = "Some text SN ABC123 some more text"
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV1HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals("ABC123", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV1HardwareId should return null when input does not contain SN`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = "Some text without SN"
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV1HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertNull(result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV1HardwareId should return null when input is empty`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = ""
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV1HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertNull(result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV1HardwareId should return null when input is null`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input: String? = null
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = input?.let { hemoCubeFragment.extractV1HardwareId(it) }
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertNull(result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV1HardwareId should return hardware ID when input contains SN in a specific format`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = """
|
|
|
|
|
SN HCV-000-3001
|
|
|
|
|
#BS
|
|
|
|
|
#BC
|
|
|
|
|
#SS
|
|
|
|
|
#SC
|
|
|
|
|
RESULT
|
|
|
|
|
LB1 20636.32
|
|
|
|
|
LB2 15855.67
|
|
|
|
|
LB3 21801.36
|
|
|
|
|
LB4 18362.33
|
|
|
|
|
LS1 17287
|
|
|
|
|
LS2 14855.67
|
|
|
|
|
LS3 15282.31
|
|
|
|
|
LS4 9737.98
|
|
|
|
|
REND
|
|
|
|
|
""".trimIndent()
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV1HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals("HCV-000-3001", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV2HardwareId should return the correct hardware ID when it exists in the input`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = "SNS ABC123 SNE"
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV2HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals("ABC123", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV2HardwareId should return null when no hardware ID is found in the input`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = "No hardware ID in this input"
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV2HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertNull(result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV2HardwareId should handle whitespace around the hardware ID`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = "SNS XYZ789 SNE"
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV2HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals("XYZ789", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV2HardwareId should handle provided input string with HCV-000-3013`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = "SNS HCV-000-3013 SNE\n" +
|
|
|
|
|
"#SS1\n" +
|
|
|
|
|
"#SC1\n" +
|
|
|
|
|
"RESULT \n" +
|
|
|
|
|
"LB1 23411.00\n" +
|
|
|
|
|
"LB2 21417.00\n" +
|
|
|
|
|
"LB3 23869.00\n" +
|
|
|
|
|
"LB4 24967.00\n" +
|
|
|
|
|
"LS1 3401.00\n" +
|
|
|
|
|
"LS2 1107.00\n" +
|
|
|
|
|
"LS3 14410.00\n" +
|
|
|
|
|
"LS4 15047.00\n" +
|
|
|
|
|
"REND\n"
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV2HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals("HCV-000-3013", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV2HardwareId should handle provided input string with HPP1-4001`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = "SNS HPP1-4001 SNE#SS1\n" +
|
|
|
|
|
"#SC1\n" +
|
|
|
|
|
"RESULT\n" +
|
|
|
|
|
"LB1 23777\n" +
|
|
|
|
|
"LB2 24130\n" +
|
|
|
|
|
"LB3 23442\n" +
|
|
|
|
|
"LB4 23945\n" +
|
|
|
|
|
"LS1 2521\n" +
|
|
|
|
|
"LS2 973\n" +
|
|
|
|
|
"LS3 10252\n" +
|
|
|
|
|
"LS4 11017\n" +
|
|
|
|
|
"REND\n"
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV2HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals("HPP1-4001", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV2HardwareId should handle provided input string with HPP1-000-4001`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = "SNS HPP1-000-4001 SNE#SS1\n" +
|
|
|
|
|
"#SC1\n" +
|
|
|
|
|
"RESULT\n" +
|
|
|
|
|
"LB1 23777\n" +
|
|
|
|
|
"LB2 24130\n" +
|
|
|
|
|
"LB3 23442\n" +
|
|
|
|
|
"LB4 23945\n" +
|
|
|
|
|
"LS1 2521\n" +
|
|
|
|
|
"LS2 973\n" +
|
|
|
|
|
"LS3 10252\n" +
|
|
|
|
|
"LS4 11017\n" +
|
|
|
|
|
"REND\n"
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV2HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals("HPP1-000-4001", result)
|
|
|
|
|
}
|
2024-01-26 11:20:13 +05:30
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV2HardwareId should handle provided input string with HPP-000-4001`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = "SNS HPP-000-4001 SNE#SS1\n" +
|
|
|
|
|
"#SC1\n" +
|
|
|
|
|
"RESULT\n" +
|
|
|
|
|
"LB1 23777\n" +
|
|
|
|
|
"LB2 24130\n" +
|
|
|
|
|
"LB3 23442\n" +
|
|
|
|
|
"LB4 23945\n" +
|
|
|
|
|
"LS1 2521\n" +
|
|
|
|
|
"LS2 973\n" +
|
|
|
|
|
"LS3 10252\n" +
|
|
|
|
|
"LS4 11017\n" +
|
|
|
|
|
"REND\n"
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV2HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals("HPP-000-4001", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun `extractV2HardwareId should handle provided input string with HPP-000-5001`() {
|
|
|
|
|
// Arrange
|
|
|
|
|
val input = "SNS HPP-000-5001 SNE#SS1\n" +
|
|
|
|
|
"#SC1\n" +
|
|
|
|
|
"RESULT\n" +
|
|
|
|
|
"LB1 23777\n" +
|
|
|
|
|
"LB2 24130\n" +
|
|
|
|
|
"LB3 23442\n" +
|
|
|
|
|
"LB4 23945\n" +
|
|
|
|
|
"LS1 2521\n" +
|
|
|
|
|
"LS2 973\n" +
|
|
|
|
|
"LS3 10252\n" +
|
|
|
|
|
"LS4 11017\n" +
|
|
|
|
|
"REND\n"
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
val result = hemoCubeFragment.extractV2HardwareId(input)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
assertEquals("HPP-000-5001", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun testDeviceRatioClassificationNormal() {
|
|
|
|
|
val ratio = 0.25
|
|
|
|
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
|
|
|
|
assertEquals("Normal", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun testDeviceRatioClassificationNegativeBorderline() {
|
|
|
|
|
val ratio = 0.31
|
|
|
|
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
|
|
|
|
assertEquals("Negative Borderline, Repeat Test", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun testDeviceRatioClassificationSickleCellTrait() {
|
|
|
|
|
val ratio = 0.34
|
|
|
|
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
|
|
|
|
assertEquals("Sickle Cell Trait", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun testDeviceRatioClassificationPositiveForSickleCell() {
|
|
|
|
|
val ratio = 0.37
|
|
|
|
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
|
|
|
|
assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun testDeviceRatioClassificationSickleCellDisease() {
|
|
|
|
|
val ratio = 0.45
|
|
|
|
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
|
|
|
|
assertEquals("Sickle Cell Disease", result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
fun testDeviceRatioClassificationInvalid() {
|
|
|
|
|
val ratio: Double? = null
|
|
|
|
|
val result = hemoCubeFragment.deviceRatioClassification(ratio)
|
|
|
|
|
assertEquals("Invalid", result)
|
|
|
|
|
}
|
2024-01-17 02:44:33 +05:30
|
|
|
}
|