/* * // 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. */ package com.example.hpostesting import android.content.SharedPreferences import com.example.hpostesting.presentation.trueheme_test.TrueHemeTestFragment import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertNull 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 { @Mock private lateinit var mockSharedPreferences: SharedPreferences private lateinit var trueHemeTestFragment: TrueHemeTestFragment @Before fun setUp() { MockitoAnnotations.initMocks(this) trueHemeTestFragment = TrueHemeTestFragment() } @Test fun `extractV2HardwareId to get device id`() { // Arrange Mockito.`when`( mockSharedPreferences.getString( ArgumentMatchers.anyString(), ArgumentMatchers.anyString() ) ).thenReturn("dummy_value") // Act val deviceId = trueHemeTestFragment.extractV2HardwareId("SNS HPP1-9000 SNE") // Assert 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 assertEquals("HPP1-0001", deviceId) } @Test fun `allReadingsComplete check`() { // Arrange val repeatReadingCount = 1 val readingsPerSample = 1 // Act val result = trueHemeTestFragment.allReadingsComplete(repeatReadingCount, readingsPerSample) // Assert assertEquals(true, result) assertEquals(trueHemeTestFragment.allReadingsComplete(0, 1), false) } @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) // 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) // Assert assertNull(result) } @Test fun `extractV1HardwareId should return null when input is empty`() { // Arrange val input = "" // Act val result = trueHemeTestFragment.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 { trueHemeTestFragment.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 = trueHemeTestFragment.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 = trueHemeTestFragment.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 = trueHemeTestFragment.extractV2HardwareId(input) // 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) // 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) // 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) // 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) // Assert assertEquals("HPP1-000-4001", result) } @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) // 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) // Assert assertEquals("HPP-000-5001", result) } @Test fun testDeviceRatioClassificationNormalWithStartRange() { val ratio = 0.08 val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio) assertEquals("Normal", result) } @Test fun testDeviceRatioClassificationNormal() { val ratio = 0.22 val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio) 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) assertEquals("Negative Borderline", result) } @Test fun testDeviceRatioClassificationSickleCellTraitLowerBound() { val ratio = 0.271 val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio) assertEquals("Sickle Cell Trait", result) } @Test fun testDeviceRatioClassificationSickleCellTraitUpperBound() { val ratio = 0.309 val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio) assertEquals("Sickle Cell Trait", result) } @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() { val ratio = 0.39 val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio) assertEquals("Positive for Sickle Cell. HPLC for Confirmation", result) } @Test fun testDeviceRatioClassificationSickleCellDiseaseLowerBound() { val ratio = 0.391 val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio) assertEquals("Sickle Cell Disease", result) } @Test fun testDeviceRatioClassificationSickleCellDisease() { val ratio = 0.691 val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio) assertEquals("Sickle Cell Disease", result) } @Test fun testDeviceRatioClassificationInvalid() { val ratio: Double? = null val result = trueHemeTestFragment.deviceRatioClassification("10mm",ratio) assertEquals("Invalid", result) } @Test fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineNormal() { val result = trueHemeTestFragment.findResultWithAdditionalMethods("10mm",0.5, "Negative Borderline", 2.5) assertEquals("Normal", result) } @Test fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineSickleCellTrait1() { val result = trueHemeTestFragment.findResultWithAdditionalMethods("10mm",0.5, "Negative Borderline", 2.2) assertEquals("Normal", result) } @Test fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineSickleCellTrait2() { val result = trueHemeTestFragment.findResultWithAdditionalMethods( "10mm",0.5, "Positive for Sickle Cell. HPLC for Confirmation", 1.4 ) assertEquals("Sickle Cell Trait", result) } @Test fun findResultWithAdditionalMethods_ValidInput_ReturnsBorderlineSickleCellDisease() { val result = trueHemeTestFragment.findResultWithAdditionalMethods( "10mm",0.5, "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, "Negative Borderline, Repeat Test", 70.0 ) assertEquals("Negative Borderline, Repeat Test", result) } @Test fun findResultWithAdditionalMethods_SCT_ReturnsSCT() { 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, "Positive for Sickle Cell. HPLC for Confirmation", 1.67 ) assertEquals("Sickle Cell Trait", result) } @Test fun findResultWithAdditionalMethods_SCD_ReturnsSCD() { 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( 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( 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( 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( deviceRatio, deviceRatioClass, led2Average ) // Assert assertEquals("Borderline. Sickle Cell Trait", result) } @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( deviceRatio, deviceRatioClass, led2Average ) // Assert assertEquals("Borderline. Sickle Cell Disease", result) } }