Added UnitTest cases.
This commit is contained in:
@@ -41,8 +41,8 @@ class TestRightViewModel : ViewModel() {
|
||||
val calculationVariableList = ArrayList<CalculationVariableForTest>()
|
||||
|
||||
fun mapDeviceConstants(string: String) {
|
||||
Log.d(TAG, "mapDeviceConstants() called")
|
||||
// viewModelScope.launch {
|
||||
// Log.d(TAG, "mapDeviceConstants() called")
|
||||
// Log.d(TAG, "mapDeviceConstants() value -> $string")
|
||||
if (string.isNotEmpty()) {
|
||||
val listOfStrings = string.split(",")
|
||||
if (listOfStrings.size >= 4) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.example.hpos
|
||||
|
||||
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 = """
|
||||
Buf 1 : 31
|
||||
|
||||
60
app/src/test/java/com/example/hpos/TestDataGenerator.kt
Normal file
60
app/src/test/java/com/example/hpos/TestDataGenerator.kt
Normal 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> {
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
package com.example.hpos
|
||||
|
||||
import com.example.hpos.data.constant.Constants
|
||||
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.TestRightResultType
|
||||
import com.example.hpos.presentation.testRight.TestRightViewModel
|
||||
import junit.framework.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import java.math.RoundingMode
|
||||
import java.text.DecimalFormat
|
||||
|
||||
class TestRightViewModelTest {
|
||||
private val viewModel = TestRightViewModel()
|
||||
private val data = InputData()
|
||||
|
||||
@Test
|
||||
fun testRightViewModel_mapDeviceConstants() {
|
||||
fun test_mapDeviceConstants() {
|
||||
viewModel.mapDeviceConstants(data.inputRead)
|
||||
assertEquals("0", DataHolder.deviceConstant!!.a)
|
||||
assertEquals("1.69989422e-06", DataHolder.deviceConstant!!.b)
|
||||
@@ -22,31 +24,60 @@ class TestRightViewModelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRightViewModel_mapPixelNumberToWavelength() {
|
||||
fun test_mapPixelNumberToWavelength() {
|
||||
viewModel.mapDeviceConstants(data.inputRead)
|
||||
viewModel.mapPixelNumberToWavelength()
|
||||
|
||||
var i = 1
|
||||
for (each in DataHolder.wavelengthToPixelArray){
|
||||
System.out.print(i)
|
||||
System.out.print(" -> ")
|
||||
System.out.println(each)
|
||||
i++
|
||||
}
|
||||
val outputList = TestDataGenerator().getOutputMapPixelNumberToWavelength()
|
||||
|
||||
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
|
||||
fun testRightViewModel_calculateResults() {
|
||||
fun test_mapWavelengthToAbsorbance() {
|
||||
|
||||
viewModel.mapDeviceConstants(data.inputRead)
|
||||
viewModel.mapPixelNumberToWavelength()
|
||||
viewModel.mapIntensityValues(data.printForReference, true)
|
||||
viewModel.mapIntensityValues(data.printForSample, false)
|
||||
viewModel.mapIntensityValues(TestDataGenerator().getInputReferenceMapIntensityValues(), true)
|
||||
viewModel.mapIntensityValues(TestDataGenerator().getInputSampleMapIntensityValues(), false)
|
||||
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
Reference in New Issue
Block a user