unit test errors
This commit is contained in:
@@ -46,7 +46,6 @@ class HemoCubeFragment : Fragment() {
|
||||
private var loginId: String = ""
|
||||
private var isTestOngoing = false
|
||||
private var startListening = MutableLiveData<Boolean>(false)
|
||||
private val testingTrace = Firebase.performance.newTrace("testing_trace")
|
||||
private var led1BufferForDevice = 0.0
|
||||
private var led2BufferForDevice = 0.0
|
||||
private var led3BufferForDevice = 0.0
|
||||
@@ -408,7 +407,6 @@ class HemoCubeFragment : Fragment() {
|
||||
getString(R.string.sample_completed) + "\n" + getString(R.string.gathering_data))
|
||||
fetchResult()
|
||||
currentResultData = ""
|
||||
testingTrace.stop()
|
||||
}
|
||||
|
||||
resultData.contains("ovf") -> {
|
||||
@@ -952,7 +950,6 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun startSampleProcess() {
|
||||
testingTrace.start()
|
||||
hemoCubeViewModel.progressBar.postValue(true)
|
||||
|
||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.START_SAMPLE,
|
||||
|
||||
@@ -39,7 +39,6 @@ import com.example.hpostesting.data.repository.DatabaseRepository
|
||||
import com.example.hpostesting.data.repository.Repository
|
||||
import com.example.hpostesting.domain.CheckUpdateWorker
|
||||
import com.example.hpostesting.domain.LogFileManager
|
||||
import com.example.hpostesting.data.repository.LocalFileRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
@@ -412,7 +411,6 @@ class HemoCubeViewModel @Inject constructor(
|
||||
hemoCubeBufferDao.updateFieldById(id = bufferId, true)
|
||||
}
|
||||
|
||||
|
||||
fun getLocalUserDataForCsv(context: Context): Boolean {
|
||||
val localUserDataLiveData: LiveData<List<HemoCubeTestData>> = hemoCubeDao.getAll()
|
||||
|
||||
@@ -447,24 +445,24 @@ class HemoCubeViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
private fun getCurrentDate(): String {
|
||||
val dateFormat = SimpleDateFormat("dd-MM-yy", Locale.getDefault())
|
||||
val currentDate = Date()
|
||||
return dateFormat.format(currentDate)
|
||||
}
|
||||
val dateFormat = SimpleDateFormat("dd-MM-yy", Locale.getDefault())
|
||||
val currentDate = Date()
|
||||
return dateFormat.format(currentDate)
|
||||
}
|
||||
|
||||
fun createCSV(hemoCubeTestData: List<HemoCubeTestData>, appContext: Context) =
|
||||
viewModelScope.launch {
|
||||
val fileName = "HPOS${getCurrentDate()}.csv"
|
||||
if (localFileDataSource.exportDataToCSV(fileName, hemoCubeTestData)) {
|
||||
hemoCubeTestData.forEach { data ->
|
||||
data.localFlag = true
|
||||
hemoCubeDao.updateCSVFieldById(
|
||||
data._id,
|
||||
true
|
||||
)
|
||||
}
|
||||
viewModelScope.launch {
|
||||
val fileName = "HPOS${getCurrentDate()}.csv"
|
||||
if (localFileDataSource.exportDataToCSV(fileName, hemoCubeTestData)) {
|
||||
hemoCubeTestData.forEach { data ->
|
||||
data.localFlag = true
|
||||
hemoCubeDao.updateCSVFieldById(
|
||||
data._id,
|
||||
true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getBatteryLevel(): Float? {
|
||||
val batteryPct: Float? = batteryStatus?.let { intent ->
|
||||
|
||||
@@ -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