Files
hpos/app/src/test/java/com/example/hpostesting/TrueHemeTestFragmentTest.kt

557 lines
16 KiB
Kotlin
Raw Normal View History

2024-03-18 13:16:11 +05:30
/*
* // Copyright (c) 2024 ShanMukha Innovations Pvt. Ltd. All rights reserved.
* // Notice: All information contained herein is, and remains
* // the property of ShanMukha Innovations Pvt. Ltd. and its suppliers,
* // if any. The intellectual and technical concepts contained
* // herein are proprietary to ShanMukha Innovations Pvt. Ltd.
* // and its suppliers and may be covered by Indian and Foreign Patents,
* // patents in process, and are protected by trade secret or copyright law.
* // Dissemination of this information or reproduction of this material
* // is strictly forbidden unless prior written permission is obtained
* // from ShanMukha Innovations Pvt. Ltd.
*/
2024-01-17 02:44:33 +05:30
package com.example.hpostesting
import android.content.SharedPreferences
import com.example.hpostesting.presentation.trueheme_test.TrueHemeTestFragment
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 TrueHemeTestFragmentTest {
2024-01-17 02:44:33 +05:30
@Mock
private lateinit var mockSharedPreferences: SharedPreferences
private lateinit var trueHemeTestFragment: TrueHemeTestFragment
2024-01-17 02:44:33 +05:30
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
trueHemeTestFragment = TrueHemeTestFragment()
2024-01-17 02:44:33 +05:30
}
@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
val deviceId = trueHemeTestFragment.extractV2HardwareId("SNS HPP1-9000 SNE")
2024-01-17 02:44:33 +05:30
// Assert
2024-02-26 20:28:24 +05:30
assertEquals("HPP1-9000", deviceId)
2024-01-17 02:44:33 +05:30
}
@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
2024-02-26 20:28:24 +05:30
assertEquals("HPP1-0001", deviceId)
2024-01-17 02:44:33 +05:30
}
@Test
fun `allReadingsComplete check`() {
// Arrange
val repeatReadingCount = 1
val readingsPerSample = 1
// Act
val result = trueHemeTestFragment.allReadingsComplete(repeatReadingCount, readingsPerSample)
2024-01-17 02:44:33 +05:30
// Assert
2024-02-26 20:28:24 +05:30
assertEquals(true, result)
assertEquals(trueHemeTestFragment.allReadingsComplete(0, 1), false)
2024-01-17 02:44:33 +05:30
}
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 = trueHemeTestFragment.extractV1HardwareId(input)
2024-01-26 07:48:15 +05:30
// 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 = trueHemeTestFragment.extractV1HardwareId(input)
2024-01-26 07:48:15 +05:30
// Assert
assertNull(result)
}
@Test
fun `extractV1HardwareId should return null when input is empty`() {
// Arrange
val input = ""
// Act
val result = trueHemeTestFragment.extractV1HardwareId(input)
2024-01-26 07:48:15 +05:30
// Assert
assertNull(result)
}
@Test
fun `extractV1HardwareId should return null when input is null`() {
// Arrange
val input: String? = null
// Act
val result = input?.let { trueHemeTestFragment.extractV1HardwareId(it) }
2024-01-26 07:48:15 +05:30
// 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 = trueHemeTestFragment.extractV1HardwareId(input)
2024-01-26 07:48:15 +05:30
// 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 = trueHemeTestFragment.extractV2HardwareId(input)
2024-01-26 07:48:15 +05:30
// 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 = trueHemeTestFragment.extractV2HardwareId(input)
2024-01-26 07:48:15 +05:30
// Assert
assertNull(result)
}
@Test
fun `extractV2HardwareId should handle whitespace around the hardware ID`() {
// Arrange
val input = "SNS XYZ789 SNE"
// Act
val result = trueHemeTestFragment.extractV2HardwareId(input)
2024-01-26 07:48:15 +05:30
// 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 = trueHemeTestFragment.extractV2HardwareId(input)
2024-01-26 07:48:15 +05:30
// 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 = trueHemeTestFragment.extractV2HardwareId(input)
2024-01-26 07:48:15 +05:30
// 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 = trueHemeTestFragment.extractV2HardwareId(input)
2024-01-26 07:48:15 +05:30
// 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 = trueHemeTestFragment.extractV2HardwareId(input)
2024-01-26 11:20:13 +05:30
// 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 = trueHemeTestFragment.extractV2HardwareId(input)
2024-01-26 11:20:13 +05:30
// Assert
assertEquals("HPP-000-5001", result)
}
2024-02-17 09:09:45 +05:30
@Test
fun testDeviceRatioClassificationNormalWithStartRange() {
val ratio = 0.08
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
2024-02-17 09:09:45 +05:30
assertEquals("Normal", result)
}
2024-01-26 11:20:13 +05:30
@Test
fun testDeviceRatioClassificationNormal() {
val ratio = 0.22
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
2024-01-26 11:20:13 +05:30
assertEquals("Normal", result)
}
@Test
fun testDeviceRatioClassificationNegativeBorderline() {
val ratio = 0.235
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
assertEquals("Negative Borderline", result)
}
@Test
fun testDeviceRatioClassificationNegativeBorderlineUpperBound() {
val ratio = 0.265
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
2024-02-10 12:18:52 +05:30
assertEquals("Negative Borderline", result)
2024-01-26 11:20:13 +05:30
}
@Test
2024-02-17 09:43:14 +05:30
fun testDeviceRatioClassificationSickleCellTraitLowerBound() {
val ratio = 0.271
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
assertEquals("Sickle Cell Trait", result)
2024-01-26 11:20:13 +05:30
}
2024-02-17 09:43:14 +05:30
@Test
fun testDeviceRatioClassificationSickleCellTraitUpperBound() {
val ratio = 0.309
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
2024-02-17 09:43:14 +05:30
assertEquals("Sickle Cell Trait", result)
}
2024-01-26 11:20:13 +05:30
@Test
fun testDeviceRatioClassificationPositiveForSickleCell() {
val ratio = 0.312
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result)
}
@Test
fun testDeviceRatioClassificationPositiveForSickleCellUpperBound() {
2024-03-30 14:19:47 +05:30
val ratio = 0.39
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
2024-01-26 11:20:13 +05:30
assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result)
}
2024-02-17 09:43:14 +05:30
@Test
fun testDeviceRatioClassificationSickleCellDiseaseLowerBound() {
2024-03-30 14:19:47 +05:30
val ratio = 0.391
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
assertEquals("Sickle Cell Disease", result)
2024-02-17 09:43:14 +05:30
}
2024-01-26 11:20:13 +05:30
@Test
fun testDeviceRatioClassificationSickleCellDisease() {
val ratio = 0.691
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
2024-01-26 11:20:13 +05:30
assertEquals("Sickle Cell Disease", result)
}
@Test
fun testDeviceRatioClassificationInvalid() {
val ratio: Double? = null
val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio)
2024-01-26 11:20:13 +05:30
assertEquals("Invalid", result)
}
@Test
2024-02-16 14:27:40 +05:30
fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineNormal() {
2024-02-26 20:28:24 +05:30
val result =
trueHemeTestFragment.findResultWithAdditionalMethods("10mm",0.5, "Negative Borderline", 2.5)
assertEquals("Normal", result)
2024-02-16 14:27:40 +05:30
}
@Test
fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineSickleCellTrait1() {
2024-02-26 20:28:24 +05:30
val result =
trueHemeTestFragment.findResultWithAdditionalMethods("10mm",0.5, "Negative Borderline", 2.2)
assertEquals("Normal", result)
2024-02-16 14:27:40 +05:30
}
@Test
fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineSickleCellTrait2() {
val result = trueHemeTestFragment.findResultWithAdditionalMethods(
"10mm",0.5,
2024-02-26 20:28:24 +05:30
"Positive for Sickle Cell. HPLC for Confirmation",
2024-03-30 14:19:47 +05:30
1.4
2024-02-26 20:28:24 +05:30
)
assertEquals("Sickle Cell Trait", result)
2024-02-16 14:27:40 +05:30
}
@Test
fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineSickleCellDisease() {
val result = trueHemeTestFragment.findResultWithAdditionalMethods(
"10mm",0.5,
2024-02-26 20:28:24 +05:30
"Positive for Sickle Cell. HPLC for Confirmation",
1.33
)
assertEquals("Sickle Cell Trait", result)
}
@Test
fun findResultWithAdditionalMethods_NormalDeviceRatio_ReturnsNormalBelowSlopeRatioThreshold() {
val result = trueHemeTestFragment.findResultWithAdditionalMethods("10mm",0.5, "Normal", 30.0)
assertEquals("Normal", result)
}
@Test
fun findResultWithAdditionalMethods_NBL_ReturnsNBL() {
val result = trueHemeTestFragment.findResultWithAdditionalMethods(
"10mm",0.5,
2024-02-26 20:28:24 +05:30
"Negative Borderline, Repeat Test",
70.0
)
assertEquals("Negative Borderline, Repeat Test", result)
}
@Test
fun findResultWithAdditionalMethods_SCT_ReturnsSCT() {
2024-02-26 20:28:24 +05:30
val result =
trueHemeTestFragment.findResultWithAdditionalMethods("10mm",0.5, "Sickle Cell Trait", 70.0)
assertEquals("Sickle Cell Trait", result)
}
@Test
fun findResultWithAdditionalMethods_PBL_ReturnsPBL() {
val result = trueHemeTestFragment.findResultWithAdditionalMethods(
"10mm",0.5,
2024-02-26 20:28:24 +05:30
"Positive for Sickle Cell. HPLC for Confirmation",
1.67
2024-02-26 20:28:24 +05:30
)
assertEquals("Sickle Cell Trait", result)
}
@Test
fun findResultWithAdditionalMethods_SCD_ReturnsSCD() {
2024-02-26 20:28:24 +05:30
val result =
trueHemeTestFragment.findResultWithAdditionalMethods("10mm",0.5, "Sickle Cell Disease", 70.0)
assertEquals("Sickle Cell Disease", result)
}
@Test
fun testReclassifyWithBorderlineMethod2_NegativeBorderlineToNormal() {
// Arrange
val deviceRatio = 0.1
val deviceRatioClass = "Negative Borderline"
val led2Average = 0.2
// Act
val result = trueHemeTestFragment.reclassifyWithBorderlineMethod2(
2024-02-26 20:28:24 +05:30
deviceRatio,
deviceRatioClass,
led2Average
)
// Assert
assertEquals("Borderline. Normal", result)
}
@Test
fun testReclassifyWithBorderlineMethod2_NegativeBorderlineToSCT() {
// Arrange
val deviceRatio = 0.1
val deviceRatioClass = "Negative Borderline"
val led2Average = 0.14
// Act
val result = trueHemeTestFragment.reclassifyWithBorderlineMethod2(
2024-02-26 20:28:24 +05:30
deviceRatio,
deviceRatioClass,
led2Average
)
// Assert
assertEquals("Borderline. Sickle Cell Trait", result)
}
@Test
fun testReclassifyWithBorderlineMethod2_PositiveSickleCell() {
// Arrange
val deviceRatio = 0.2
val deviceRatioClass = "Positive for Sickle Cell. HPLC for Confirmation"
val led2Average = 0.18
// Act
val result = trueHemeTestFragment.reclassifyWithBorderlineMethod2(
2024-02-26 20:28:24 +05:30
deviceRatio,
deviceRatioClass,
led2Average
)
// Assert
assertEquals("Borderline. Sickle Cell Disease", result)
}
@Test
fun testReclassifyWithBorderlineMethod2_PositiveSickleCellToSCT() {
// Arrange
val deviceRatio = 0.2
val deviceRatioClass = "Positive for Sickle Cell. HPLC for Confirmation"
val led2Average = 0.195
// Act
val result = trueHemeTestFragment.reclassifyWithBorderlineMethod2(
2024-02-26 20:28:24 +05:30
deviceRatio,
deviceRatioClass,
led2Average
)
// Assert
assertEquals("Borderline. Sickle Cell Trait", result)
}
2024-02-21 22:05:09 +05:30
@Test
fun testReclassifyWithBorderlineMethod2_PositiveSickleCellToSCD() {
// Arrange
val deviceRatio = 0.2
val deviceRatioClass = "Positive for Sickle Cell. HPLC for Confirmation"
val led2Average = 0.189
// Act
val result = trueHemeTestFragment.reclassifyWithBorderlineMethod2(
2024-02-26 20:28:24 +05:30
deviceRatio,
deviceRatioClass,
led2Average
)
2024-02-21 22:05:09 +05:30
// Assert
assertEquals("Borderline. Sickle Cell Disease", result)
}
2024-01-17 02:44:33 +05:30
}