refactor and add tests
This commit is contained in:
@@ -94,10 +94,8 @@ publishTestResults:
|
||||
stage: test
|
||||
script:
|
||||
- echo "Publishing JUnit test results"
|
||||
- mkdir -p junit-reports
|
||||
- find app/build/test-results -type f -name "testDebugUnitTest*.xml" -exec cp {} junit-reports/ \;
|
||||
needs: [debugTests]
|
||||
artifacts:
|
||||
when: always
|
||||
reports:
|
||||
junit: junit-reports/*.xml
|
||||
junit: app/build/test-results/testDebugUnitTest/*.xml
|
||||
|
||||
@@ -19,8 +19,8 @@ android {
|
||||
applicationId "in.sminnovations.hpostesting.quality"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 93
|
||||
versionName "2.1.93"
|
||||
versionCode 95
|
||||
versionName "2.1.95"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -80,7 +80,7 @@ dependencies {
|
||||
implementation 'com.google.firebase:firebase-storage-ktx'
|
||||
implementation 'com.firebaseui:firebase-ui-firestore:8.0.2'
|
||||
implementation 'com.google.android.gms:play-services-auth:20.7.0'
|
||||
implementation 'com.google.android.gms:play-services-location:21.0.1'
|
||||
implementation 'com.google.android.gms:play-services-location:21.1.0'
|
||||
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
|
||||
implementation 'com.google.android.things:androidthings:1.0'
|
||||
implementation 'com.google.firebase:firebase-appdistribution:16.0.0-beta11'
|
||||
@@ -95,6 +95,8 @@ dependencies {
|
||||
// Testing
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test:rules:1.0.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
testImplementation "androidx.work:work-testing:2.9.0"
|
||||
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
|
||||
@@ -113,7 +115,6 @@ dependencies {
|
||||
testImplementation "androidx.arch.core:core-testing:2.2.0"
|
||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1'
|
||||
|
||||
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0"
|
||||
implementation 'com.opencsv:opencsv:5.9'
|
||||
implementation 'com.github.mik3y:usb-serial-for-android:3.5.1'
|
||||
|
||||
@@ -888,36 +888,38 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
fun deviceRatioClassification(ratio: Double?): String {
|
||||
try {
|
||||
hemoCubeViewModel.messages.postValue("result classification")
|
||||
if (ratio != null) {
|
||||
if (ratio in 0.2..0.29) {
|
||||
activity?.runOnUiThread {
|
||||
binding.tvSubtitle4.setTextColor(
|
||||
ContextCompat.getColor(
|
||||
requireContext(),
|
||||
R.color.green_2
|
||||
)
|
||||
)
|
||||
}
|
||||
return getString(R.string.normal)
|
||||
// setSubtitleTextColor(R.color.green_2)
|
||||
return "Normal"
|
||||
}
|
||||
if (ratio in 0.29..0.32)
|
||||
return getString(R.string.negative_borderline)
|
||||
return "Negative Borderline, Repeat Test"
|
||||
if (ratio in 0.32..0.35)
|
||||
return getString(R.string.sickle_cell_trait)
|
||||
return "Sickle Cell Trait"
|
||||
if (ratio in 0.35..0.38)
|
||||
return getString(R.string.positive_for_sickle_cell)
|
||||
return "Positive for Sickle Cell. HPLC for Confirmation"
|
||||
if (ratio in 0.38..0.5)
|
||||
return getString(R.string.sickle_cell_disease)
|
||||
return "Sickle Cell Disease"
|
||||
} else {
|
||||
return getString(R.string.invalid)
|
||||
return "Invalid"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
showToast(R.string.error_classification)
|
||||
Firebase.crashlytics.recordException(e)
|
||||
return getString(R.string.error)
|
||||
handleException(e)
|
||||
return "Error"
|
||||
}
|
||||
return getString(R.string.invalid)
|
||||
return "Invalid"
|
||||
}
|
||||
|
||||
fun setSubtitleTextColor(colorResId: Int) {
|
||||
activity?.runOnUiThread {
|
||||
binding.tvSubtitle4.setTextColor(ContextCompat.getColor(requireContext(), colorResId))
|
||||
}
|
||||
}
|
||||
|
||||
fun handleException(e: Exception) {
|
||||
showToast(R.string.error_classification)
|
||||
Firebase.crashlytics.recordException(e)
|
||||
}
|
||||
|
||||
fun slopeRatioClassification(ratio: Double?): String {
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
<string name="normal">Normal</string>
|
||||
<string name="sickle_cell_disease">Sickle Cell Disease</string>
|
||||
<string name="sickle_cell_trait">Sickle Cell Trait</string>
|
||||
<string name="undefined">Undefined\ \ </string>
|
||||
<string name="undefined">Undefined</string>
|
||||
<string name="sicklecell_nconfirmatory">Sicklecell\nConfirmatory</string>
|
||||
<string name="sicklecell_screening">Sicklecell Screening</string>
|
||||
<string name="thalassemia">Thalassemia</string>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.hpostesting
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
||||
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||
@@ -16,6 +17,9 @@ import org.mockito.MockitoAnnotations
|
||||
|
||||
class HemoCubeFragmentTest {
|
||||
|
||||
@Mock
|
||||
lateinit var mockContext: Context
|
||||
|
||||
@Mock
|
||||
private lateinit var mockSharedPreferences: SharedPreferences
|
||||
|
||||
@@ -34,7 +38,7 @@ class HemoCubeFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `extractMiddleString to get device id`() {
|
||||
fun `extractV2HardwareId to get device id`() {
|
||||
// Arrange
|
||||
Mockito.`when`(
|
||||
mockSharedPreferences.getString(
|
||||
@@ -265,4 +269,92 @@ class HemoCubeFragmentTest {
|
||||
// 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 = 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user