unit test errors
This commit is contained in:
@@ -6,6 +6,7 @@ import com.example.hpostesting.presentation.hemocube.HemoCubeFragment
|
||||
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
|
||||
import com.example.hpostesting.presentation.hemocube.HemocubeActivity
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers.any
|
||||
@@ -34,25 +35,15 @@ class HemocubeViewModelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `handleValidResult with valid input`() {
|
||||
fun `extractMiddleString to get device id`() {
|
||||
// Arrange
|
||||
val validString = "valid string"
|
||||
val fullReadOutput = "full read output"
|
||||
`when`(mockSharedPreferences.getString(anyString(), anyString())).thenReturn("dummy_value")
|
||||
`when`(mockActivity.runOnUiThread(any())).thenAnswer {
|
||||
val runnable = it.getArgument(0, Runnable::class.java)
|
||||
runnable.run()
|
||||
}
|
||||
|
||||
// Act
|
||||
hemoCubeFragment.handleValidResult(validString, fullReadOutput)
|
||||
val deviceId = hemoCubeFragment.extractMiddleString("SNS HPP1-9000 SNE")
|
||||
|
||||
// Assert
|
||||
// Add appropriate assertions based on the behavior you expect
|
||||
verify(mockSharedPreferences).edit()
|
||||
verify(mockBinding).btnSubmit.visibility = View.VISIBLE
|
||||
verify(mockBinding).btnSubmit.isEnabled = true
|
||||
// Add more verifications as needed
|
||||
assertEquals("HPP1-9000", deviceId)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,68 +18,9 @@ import java.math.RoundingMode
|
||||
import java.text.DecimalFormat
|
||||
|
||||
class TestRightViewModelTest {
|
||||
<<<<<<< HEAD
|
||||
// private val viewModel = TestRightViewModel()
|
||||
// private val data = InputData()
|
||||
//
|
||||
=======
|
||||
|
||||
@Mock
|
||||
lateinit var mockContext: Context
|
||||
|
||||
@Mock
|
||||
lateinit var mockRepository: DatabaseRepository
|
||||
|
||||
@Mock
|
||||
lateinit var mockSaveRawData: SaveRawData
|
||||
|
||||
@Mock
|
||||
lateinit var mockSaveRawDataTest: SaveRawDataTest
|
||||
|
||||
@Mock
|
||||
lateinit var mockUserDao: UserDao
|
||||
|
||||
lateinit var viewModel: TestRightViewModel<Any?>
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
// Initialize mocks
|
||||
MockitoAnnotations.initMocks(this)
|
||||
|
||||
// Create the ViewModel with mock dependencies
|
||||
viewModel = TestRightViewModel(mockSaveRawData,mockSaveRawDataTest,mockRepository,mockUserDao,mockContext)
|
||||
}
|
||||
private val data = InputData()
|
||||
|
||||
@Test
|
||||
fun test_mapDeviceConstants() {
|
||||
viewModel.mapDeviceConstants(data.inputRead)
|
||||
assertEquals("0", DataHolder.deviceConstant!!.a)
|
||||
assertEquals("1.69989422e-06", DataHolder.deviceConstant!!.b)
|
||||
assertEquals("1.60642711e-01", DataHolder.deviceConstant!!.c)
|
||||
assertEquals("3.85754470e+02", DataHolder.deviceConstant!!.d)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test_mapPixelNumberToWavelength() {
|
||||
viewModel.mapDeviceConstants(data.inputRead)
|
||||
viewModel.mapPixelNumberToWavelength()
|
||||
|
||||
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]))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
>>>>>>> origin/Local-storing-data
|
||||
// @Test
|
||||
// fun test_mapDeviceConstants() {
|
||||
// viewModel.mapDeviceConstants(data.inputRead)
|
||||
@@ -162,52 +103,6 @@ class TestRightViewModelTest {
|
||||
// println(each[0].toString() + " -> " + each[1])
|
||||
// }
|
||||
// }
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
@Test
|
||||
fun test_mapWavelengthToAbsorbance() {
|
||||
|
||||
viewModel.mapDeviceConstants(data.inputRead)
|
||||
viewModel.mapPixelNumberToWavelength()
|
||||
viewModel.mapIntensityValues(TestDataGenerator().getInputReferenceMapIntensityValues(), true)
|
||||
val mapIntensityValues = viewModel.mapIntensityValues(
|
||||
TestDataGenerator().getInputSampleMapIntensityValues(),
|
||||
false
|
||||
)
|
||||
viewModel.testDetails = UserData("Surya", "2", "Male")
|
||||
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]))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testRightViewModel_calculateDataForCSV() {
|
||||
|
||||
viewModel.mapDeviceConstants(data.inputRead)
|
||||
viewModel.mapPixelNumberToWavelength()
|
||||
viewModel.mapIntensityValues(data.printForReference, true)
|
||||
viewModel.mapIntensityValues(data.printForSample, false)
|
||||
// viewModel.patientDetails = PatientData("Surya", 2, "Male", null)
|
||||
// viewModel.calculateResults()
|
||||
viewModel.mapWavelengthToAbsorbance()
|
||||
|
||||
for (each in viewModel.wavelengthToAbsorbance){
|
||||
println(each[0].toString() + " -> " + each[1])
|
||||
}
|
||||
}
|
||||
>>>>>>> origin/Local-storing-data
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user