Change the project into Testing app
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package com.example.hpostesting
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
class CubicEquationSolver {
|
||||
|
||||
@Test
|
||||
fun test() {
|
||||
val a: Double = 12.toDouble()
|
||||
val b: Double = (15).toDouble()
|
||||
val c: Double = (9).toDouble()
|
||||
val d: Double = (-2456).toDouble()
|
||||
|
||||
solve(a, b, c, d)
|
||||
}
|
||||
|
||||
fun solve(a: Double, b: Double, c: Double, d: Double) {
|
||||
val f: Double = getF(a, b, c)
|
||||
val g: Double = getG(a, b, c, d)
|
||||
val h: Double = getH(f, g)
|
||||
println("f = $f & g = $g & h = $h")
|
||||
|
||||
if (f == 0.0 && g == 0.0 && h == 0.0)
|
||||
solveOneRoot(a, d)
|
||||
else if (h <= 0)
|
||||
solveRealRoots(a, b, g, h)
|
||||
else
|
||||
solveNotRealRoots(a, b, g, h)
|
||||
}
|
||||
|
||||
private fun getF(a: Double, b: Double, c: Double): Double {
|
||||
return (3 * c / a - b * b / (a * a)) / 3
|
||||
}
|
||||
|
||||
private fun getG(a: Double, b: Double, c: Double, d: Double): Double {
|
||||
var g: Double = 2 * b * b * b / (a * a * a)
|
||||
g += -9 * b * c / (a * a)
|
||||
g += 27 * d / a
|
||||
g /= 27.0
|
||||
return g
|
||||
}
|
||||
|
||||
private fun getH(f: Double, g: Double): Double {
|
||||
return g * g / 4 + f * f * f / 27
|
||||
}
|
||||
|
||||
private fun solveOneRoot(a: Double, d: Double) {
|
||||
val x: Double = -Math.pow(d / a, 1.0 / 3)
|
||||
println("The solution is: $x")
|
||||
|
||||
println("rounded off solutions are:")
|
||||
println(String.format("%.3g%n", x))
|
||||
}
|
||||
|
||||
private fun solveRealRoots(a: Double, b: Double, g: Double, h: Double) {
|
||||
val i: Double = Math.sqrt(g * g / 4 - h)
|
||||
val j: Double = Math.pow(i, 1.0 / 3)
|
||||
val k: Double = Math.acos(-g / (2 * i))
|
||||
|
||||
val l: Double = -j
|
||||
val m: Double = Math.cos(k / 3)
|
||||
val n: Double = Math.sqrt(3.0) * Math.sin(k / 3)
|
||||
val p: Double = -b / (3 * a)
|
||||
|
||||
val x1: Double = 2 * j * Math.cos(k / 3) - b / (3 * a)
|
||||
val x2: Double = l * (m + n) + p
|
||||
val x3: Double = l * (m - n) + p
|
||||
|
||||
println("The solutions are:")
|
||||
println(x1)
|
||||
println(x2)
|
||||
println(x3)
|
||||
|
||||
println("rounded off solutions are:")
|
||||
println(String.format("%.3g", x1))
|
||||
println(String.format("%.3g", x2))
|
||||
println(String.format("%.3g", x3))
|
||||
}
|
||||
|
||||
private fun solveNotRealRoots(a: Double, b: Double, g: Double, h: Double) {
|
||||
|
||||
val r: Double = -(g / 2) + Math.sqrt(h)
|
||||
val s: Double = if (r >= 0) Math.pow(r, 1.0 / 3) else -Math.pow(-r, 1.0 / 3)
|
||||
val t: Double = -(g / 2) - Math.sqrt(h)
|
||||
val u: Double = if (t >= 0) Math.pow(t, 1.0 / 3) else -Math.pow(-t, 1.0 / 3)
|
||||
|
||||
val x1: Double = s + u - b / (3 * a)
|
||||
val x2: Double = -((s + u) / 2) - b / (3 * a)
|
||||
val immaginary: Double = (s - u) * Math.sqrt(3.0) / 2
|
||||
|
||||
println("The solutions are:")
|
||||
println(x1)
|
||||
println(x2.toString() + " + " + immaginary + "i")
|
||||
println(x2.toString() + " - " + immaginary + "i")
|
||||
}
|
||||
}
|
||||
16
app/src/test/java/com/example/hpostesting/ExampleUnitTest.kt
Normal file
16
app/src/test/java/com/example/hpostesting/ExampleUnitTest.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.example.hpostesting
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
7427
app/src/test/java/com/example/hpostesting/InputData.kt
Normal file
7427
app/src/test/java/com/example/hpostesting/InputData.kt
Normal file
File diff suppressed because it is too large
Load Diff
14
app/src/test/java/com/example/hpostesting/OtherTests.kt
Normal file
14
app/src/test/java/com/example/hpostesting/OtherTests.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.example.hpostesting
|
||||
|
||||
import org.junit.Test
|
||||
import java.util.Date
|
||||
|
||||
class OtherTests {
|
||||
|
||||
@Test
|
||||
fun uniqueId() {
|
||||
val date = Date()
|
||||
date.day
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.example.hpostesting
|
||||
|
||||
import java.io.File
|
||||
|
||||
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> {
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.example.hpostesting
|
||||
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.model.PatientData
|
||||
import com.example.hpostesting.data.model.test.TestRightResultType
|
||||
import com.example.hpostesting.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 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]))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @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 test_mapWavelengthToAbsorbance() {
|
||||
|
||||
viewModel.mapDeviceConstants(data.inputRead)
|
||||
viewModel.mapPixelNumberToWavelength()
|
||||
viewModel.mapIntensityValues(TestDataGenerator().getInputReferenceMapIntensityValues(), true)
|
||||
viewModel.mapIntensityValues(TestDataGenerator().getInputSampleMapIntensityValues(), false)
|
||||
viewModel.patientDetails = PatientData("Surya", 2, "Male", TestRightResultType.UNDEFINED)
|
||||
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])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
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