File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
main/kotlin/info/appdev/charting/data
test/kotlin/info/appdev/charting/test Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ package info.appdev.charting.data
2+
3+ class EntryDouble (val xDouble : Double , y : Float ) : Entry(xDouble.toFloat(), y)
Original file line number Diff line number Diff line change 1+ package info.appdev.charting.test
2+
3+ import android.content.Context
4+ import org.junit.Assert
5+ import org.junit.Before
6+ import org.junit.Test
7+ import org.mockito.Mock
8+ import org.mockito.MockitoAnnotations
9+
10+ class FloatTest {
11+
12+ @Mock
13+ private lateinit var mockContext: Context
14+
15+ @Before
16+ fun setUp () {
17+ MockitoAnnotations .openMocks(this )
18+ }
19+
20+ @Test
21+ fun testFloatConversion () {
22+ val timestamp: Long = System .currentTimeMillis()
23+
24+ // 2) Cast to Float and back
25+ val asFloat: Float = timestamp.toFloat()
26+ val roundTripFromFloat: Long = asFloat.toLong()
27+
28+ // 3) Cast to Double and back
29+ val asDouble: Double = timestamp.toDouble()
30+ val roundTripFromDouble: Long = asDouble.toLong()
31+
32+ println (" Original timestamp: $timestamp " )
33+ println (" → as Float: $asFloat " )
34+ println (" → back to Long (Float): $roundTripFromFloat " )
35+ println ()
36+ println (" → as Double: $asDouble " )
37+ println (" → back to Long (Double): $roundTripFromDouble " )
38+ println ()
39+ Assert .assertNotEquals(timestamp, roundTripFromFloat)
40+ Assert .assertEquals(timestamp, roundTripFromDouble)
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments