Added UnitTest cases.

This commit is contained in:
vsuryakumar
2023-02-04 21:19:21 +05:30
parent 3b782ea863
commit bbf3ba8de0
8 changed files with 14886 additions and 20 deletions

View File

@@ -41,8 +41,8 @@ class TestRightViewModel : ViewModel() {
val calculationVariableList = ArrayList<CalculationVariableForTest>() val calculationVariableList = ArrayList<CalculationVariableForTest>()
fun mapDeviceConstants(string: String) { fun mapDeviceConstants(string: String) {
Log.d(TAG, "mapDeviceConstants() called") // Log.d(TAG, "mapDeviceConstants() called")
// viewModelScope.launch { // Log.d(TAG, "mapDeviceConstants() value -> $string")
if (string.isNotEmpty()) { if (string.isNotEmpty()) {
val listOfStrings = string.split(",") val listOfStrings = string.split(",")
if (listOfStrings.size >= 4) { if (listOfStrings.size >= 4) {

View File

@@ -1,7 +1,7 @@
package com.example.hpos package com.example.hpos
class InputData { class InputData {
val inputRead = "0,1.69989422e-06,1.60642711e-01, 3.85754470e+02,0,0,1,0, FFF-EEEE-PPP-WW-YY-NNNN\nОК [01]" val inputRead = "0,1.69989422e-06,1.60642711e-01,3.85754470e+02,0,0,1,0,FFF-EEEE-PPPP-WW-YY-NNNN\nOK [0]"
val printForReference: String = """ val printForReference: String = """
Buf 1 : 31 Buf 1 : 31

View File

@@ -0,0 +1,60 @@
package com.example.hpos
import org.junit.Test
import java.io.File
import java.io.InputStream
import java.util.*
import kotlin.collections.ArrayList
class TestDataGenerator {
fun getOutputMapPixelNumberToWavelength() : ArrayList<Double> {
val path = "/Users/vsuryakumar/SMInnovations/AndroidProjects/refactoredapp/app/src/test/java/com/example/hpos"
val fileName = "mapPixelNumberToWavelength_output.txt"
val file = File("$path/$fileName")
val text = file.readText()
val pixelList = ArrayList<Double>()
for (each in text.split('\n')){
pixelList.add(each.toDouble())
}
return pixelList
}
fun getOutputMapWavelengthToAbsorbance(): ArrayList<Double> {
val path = "/Users/vsuryakumar/SMInnovations/AndroidProjects/refactoredapp/app/src/test/java/com/example/hpos"
val fileName = "getOutputMapWavelengthToAbsorbance_output.txt"
val file = File("$path/$fileName")
val text = file.readText()
val pixelList = ArrayList<Double>()
for (each in text.split('\n')){
pixelList.add(each.toDouble())
}
return pixelList
}
fun getInputReferenceMapIntensityValues(): String {
val path = "/Users/vsuryakumar/SMInnovations/AndroidProjects/refactoredapp/app/src/test/java/com/example/hpos"
val fileName = "getInputReferenceMapIntensityValues_input.txt"
val file = File("$path/$fileName")
return file.readText()
}
fun getInputSampleMapIntensityValues(): String {
val path = "/Users/vsuryakumar/SMInnovations/AndroidProjects/refactoredapp/app/src/test/java/com/example/hpos"
val fileName = "getInputSampleMapIntensityValues_input.txt"
val file = File("$path/$fileName")
return file.readText()
}
// fun getOutputReferenceMapIntensityValues(): ArrayList<Double> {
//
// }
//
// fun getOutputSampleMapIntensityValues(): ArrayList<Double> {
//
// }
}

View File

@@ -1,19 +1,21 @@
package com.example.hpos package com.example.hpos
import com.example.hpos.data.constant.Constants
import com.example.hpos.data.DataHolder import com.example.hpos.data.DataHolder
import com.example.hpos.data.constant.Constants
import com.example.hpos.data.model.PatientData import com.example.hpos.data.model.PatientData
import com.example.hpos.data.model.TestRightResultType import com.example.hpos.data.model.TestRightResultType
import com.example.hpos.presentation.testRight.TestRightViewModel import com.example.hpos.presentation.testRight.TestRightViewModel
import junit.framework.Assert.assertEquals import junit.framework.Assert.assertEquals
import org.junit.Test import org.junit.Test
import java.math.RoundingMode
import java.text.DecimalFormat
class TestRightViewModelTest { class TestRightViewModelTest {
private val viewModel = TestRightViewModel() private val viewModel = TestRightViewModel()
private val data = InputData() private val data = InputData()
@Test @Test
fun testRightViewModel_mapDeviceConstants() { fun test_mapDeviceConstants() {
viewModel.mapDeviceConstants(data.inputRead) viewModel.mapDeviceConstants(data.inputRead)
assertEquals("0", DataHolder.deviceConstant!!.a) assertEquals("0", DataHolder.deviceConstant!!.a)
assertEquals("1.69989422e-06", DataHolder.deviceConstant!!.b) assertEquals("1.69989422e-06", DataHolder.deviceConstant!!.b)
@@ -22,31 +24,60 @@ class TestRightViewModelTest {
} }
@Test @Test
fun testRightViewModel_mapPixelNumberToWavelength() { fun test_mapPixelNumberToWavelength() {
viewModel.mapDeviceConstants(data.inputRead) viewModel.mapDeviceConstants(data.inputRead)
viewModel.mapPixelNumberToWavelength() viewModel.mapPixelNumberToWavelength()
var i = 1 val outputList = TestDataGenerator().getOutputMapPixelNumberToWavelength()
for (each in DataHolder.wavelengthToPixelArray){
System.out.print(i)
System.out.print(" -> ")
System.out.println(each)
i++
}
assertEquals(Constants.TEST_RIGHT_TOTAL_PIXEL, DataHolder.wavelengthToPixelArray.size) assertEquals(Constants.TEST_RIGHT_TOTAL_PIXEL, DataHolder.wavelengthToPixelArray.size)
assertEquals(Constants.TEST_RIGHT_TOTAL_PIXEL, outputList.size)
val df = DecimalFormat("#.###")
df.roundingMode = RoundingMode.FLOOR
for (i in 0 until Constants.TEST_RIGHT_TOTAL_PIXEL){
assertEquals(df.format(outputList[i]), df.format(DataHolder.wavelengthToPixelArray[i]))
}
} }
// @Test
// fun test_mapIntensityValues() {
// val inputReference = TestDataGenerator().getInputReferenceMapIntensityValues()
// val inputSample = TestDataGenerator().getInputSampleMapIntensityValues()
//
// viewModel.mapIntensityValues(inputReference, true)
// viewModel.mapIntensityValues(inputSample, false)
//
// val outputReference = TestDataGenerator().getOutputReferenceMapIntensityValues()
// val outputSample = TestDataGenerator().getOutputSampleMapIntensityValues()
//
// assertEquals(outputReference, DataHolder.intensityReferenceArray)
// assertEquals(outputSample, viewModel.intensitySampleArray)
// }
@Test @Test
fun testRightViewModel_calculateResults() { fun test_mapWavelengthToAbsorbance() {
viewModel.mapDeviceConstants(data.inputRead) viewModel.mapDeviceConstants(data.inputRead)
viewModel.mapPixelNumberToWavelength() viewModel.mapPixelNumberToWavelength()
viewModel.mapIntensityValues(data.printForReference, true) viewModel.mapIntensityValues(TestDataGenerator().getInputReferenceMapIntensityValues(), true)
viewModel.mapIntensityValues(data.printForSample, false) viewModel.mapIntensityValues(TestDataGenerator().getInputSampleMapIntensityValues(), false)
viewModel.patientDetails = PatientData("Surya", 2, "Male", TestRightResultType.UNDEFINED) viewModel.patientDetails = PatientData("Surya", 2, "Male", TestRightResultType.UNDEFINED)
viewModel.calculateResults() viewModel.mapWavelengthToAbsorbance()
val wavelengthList = TestDataGenerator().getOutputMapPixelNumberToWavelength()
val absorbanceList = TestDataGenerator().getOutputMapWavelengthToAbsorbance()
val df = DecimalFormat("#.###")
df.roundingMode = RoundingMode.FLOOR
assertEquals(Constants.TEST_RIGHT_TOTAL_PIXEL, viewModel.wavelengthToAbsorbance.size)
for (i in 0 until Constants.TEST_RIGHT_TOTAL_PIXEL){
assertEquals(df.format(wavelengthList[i]), df.format(viewModel.wavelengthToAbsorbance[i][0]))
assertEquals(df.format(absorbanceList[i]), df.format(viewModel.wavelengthToAbsorbance[i][1]))
}
} }
@@ -67,7 +98,4 @@ class TestRightViewModelTest {
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff