Skip to content

Commit 7c37518

Browse files
committed
Fix unit tests
1 parent 80aee16 commit 7c37518

File tree

11 files changed

+38
-50
lines changed

11 files changed

+38
-50
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/jobs/AnimatedMoveViewJob.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AnimatedMoveViewJob(
4141
private val pool = ObjectPool.Companion.create(4, AnimatedMoveViewJob(ViewPortHandler(), 0f, 0f, null, null, 0f, 0f, 0))
4242

4343
init {
44-
pool.setReplenishPercentage(0.5f)
44+
pool.replenishPercentage = 0.5f
4545
}
4646

4747
fun getInstance(

MPChartLib/src/main/java/com/github/mikephil/charting/jobs/MoveViewJob.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ open class MoveViewJob(viewPortHandler: ViewPortHandler, xValue: Float, yValue:
2828
private val pool = ObjectPool.Companion.create(2, MoveViewJob(ViewPortHandler(), 0f, 0f, null, null))
2929

3030
init {
31-
pool.setReplenishPercentage(0.5f)
31+
pool.replenishPercentage = 0.5f
3232
}
3333

3434
fun getInstance(viewPortHandler: ViewPortHandler, xValue: Float, yValue: Float, trans: Transformer?, v: View?): MoveViewJob {

MPChartLib/src/main/java/com/github/mikephil/charting/jobs/ZoomJob.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ open class ZoomJob(
4949
private val pool = ObjectPool.Companion.create(1, ZoomJob(ViewPortHandler(), 0f, 0f, 0f, 0f, null, null, null))
5050

5151
init {
52-
pool.setReplenishPercentage(0.5f)
52+
pool.replenishPercentage = 0.5f
5353
}
5454

5555
fun getInstance(

MPChartLib/src/main/java/com/github/mikephil/charting/utils/FSize.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ open class FSize : Poolable<FSize> {
5454
private val pool: ObjectPool<FSize> = ObjectPool.create(256, FSize(0f, 0f))
5555

5656
init {
57-
pool.setReplenishPercentage(0.5f)
57+
pool.replenishPercentage = 0.5f
5858
}
5959

6060

MPChartLib/src/main/java/com/github/mikephil/charting/utils/MPPointD.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MPPointD private constructor(var x: Double, var y: Double) : Poolable<MPPo
2323
private val pool: ObjectPool<MPPointD> = ObjectPool.Companion.create(64, MPPointD(0.0, 0.0))
2424

2525
init {
26-
pool.setReplenishPercentage(0.5f)
26+
pool.replenishPercentage = 0.5f
2727
}
2828

2929
fun getInstance(x: Double, y: Double): MPPointD {

MPChartLib/src/main/java/com/github/mikephil/charting/utils/MPPointF.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class MPPointF : Poolable<MPPointF> {
3838
private var pool: ObjectPool<MPPointF> = ObjectPool.Companion.create(32, MPPointF(0f, 0f))
3939

4040
init {
41-
pool.setReplenishPercentage(0.5f)
41+
pool.replenishPercentage = 0.5f
4242
}
4343

4444
fun getInstance(x: Float, y: Float): MPPointF {

MPChartLib/src/main/java/com/github/mikephil/charting/utils/ObjectPool.kt

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,25 @@ class ObjectPool<T : Poolable<T>> private constructor(withCapacity: Int, `object
2626
private var desiredCapacity: Int
2727
private val objects = ArrayList<T>(withCapacity)
2828
private val modelObject: T?
29-
private var replenishPercentage: Float
29+
var replenishPercentage: Float = 1.0f
30+
set(value) {
31+
var p = value
32+
if (p > 1) {
33+
p = 1f
34+
} else if (p < 0f) {
35+
p = 0f
36+
}
37+
field = p
38+
}
3039

3140

3241
init {
3342
require(withCapacity > 0) { "Object Pool must be instantiated with a capacity greater than 0!" }
3443
this.desiredCapacity = withCapacity
3544
this.modelObject = `object`
36-
this.replenishPercentage = 1.0f
3745
this.refillPool()
3846
}
3947

40-
/**
41-
* Set the percentage of the pool to replenish on empty. Valid values are between
42-
* 0.00f and 1.00f
43-
*
44-
* @param percentage a value between 0 and 1, representing the percentage of the pool to replenish.
45-
*/
46-
fun setReplenishPercentage(percentage: Float) {
47-
var p = percentage
48-
if (p > 1) {
49-
p = 1f
50-
} else if (p < 0f) {
51-
p = 0f
52-
}
53-
this.replenishPercentage = p
54-
}
55-
56-
fun getReplenishPercentage(): Float {
57-
return replenishPercentage
58-
}
59-
6048
private fun refillPool(percentage: Float = this.replenishPercentage) {
6149
var portionOfCapacity = (desiredCapacity * percentage).toInt()
6250

@@ -68,7 +56,7 @@ class ObjectPool<T : Poolable<T>> private constructor(withCapacity: Int, `object
6856

6957
this.objects.clear()
7058

71-
repeat(portionOfCapacity + 1) {
59+
repeat(portionOfCapacity) {
7260
this.objects.add(modelObject!!.instantiate())
7361
}
7462
}
@@ -122,7 +110,7 @@ class ObjectPool<T : Poolable<T>> private constructor(withCapacity: Int, `object
122110
* @param objects A list of objects of type T to recycle
123111
*/
124112
@Synchronized
125-
fun recycle(objects: MutableList<T>) {
113+
fun recycle(objects: List<T>) {
126114
val objectsListSize = objects.size
127115

128116
while (objectsListSize + this.objects.size > this.desiredCapacity) {

MPChartLib/src/main/java/com/github/mikephil/charting/utils/Utils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ object Utils {
152152
return paint.measureText(demoText).toInt()
153153
}
154154

155-
private val mCalcTextHeightRect = Rect()
155+
private val mCalcTextHeightRect by lazy { Rect() }
156156

157157
/**
158158
* calculates the approximate height of a text, depending on a demo text

MPChartLib/src/test/java/com/github/mikephil/charting/test/ChartDataTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ class ChartDataTest {
3939
Assert.assertEquals(-2f, data.yMin, 0.01f)
4040
Assert.assertEquals(50f, data.yMax, 0.01f)
4141

42-
Assert.assertEquals(3, data.maxEntryCountSet.entryCount)
42+
Assert.assertEquals(3, data.maxEntryCountSet?.entryCount)
4343

4444
// now add and remove values
4545
data.addEntry(Entry(-10f, -10f), 0)
4646

4747
Assert.assertEquals(set1, data.maxEntryCountSet)
48-
Assert.assertEquals(4, data.maxEntryCountSet.entryCount)
48+
Assert.assertEquals(4, data.maxEntryCountSet?.entryCount)
4949

5050
Assert.assertEquals(-10f, data.getYMin(YAxis.AxisDependency.LEFT), 0.01f)
5151
Assert.assertEquals(50f, data.getYMax(YAxis.AxisDependency.LEFT), 0.01f)

MPChartLib/src/test/java/com/github/mikephil/charting/test/DataSetTest.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,31 +137,31 @@ class DataSetTest {
137137
val set = ScatterDataSet(entries, "")
138138

139139
var closest = set.getEntryForXValue(17f, Float.NaN, DataSet.Rounding.CLOSEST)
140-
Assert.assertEquals(15f, closest.x, 0.01f)
140+
Assert.assertEquals(15f, closest!!.x, 0.01f)
141141
Assert.assertEquals(5f, closest.y, 0.01f)
142142

143143
closest = set.getEntryForXValue(17f, Float.NaN, DataSet.Rounding.DOWN)
144-
Assert.assertEquals(15f, closest.x, 0.01f)
144+
Assert.assertEquals(15f, closest!!.x, 0.01f)
145145
Assert.assertEquals(5f, closest.y, 0.01f)
146146

147147
closest = set.getEntryForXValue(15f, Float.NaN, DataSet.Rounding.DOWN)
148-
Assert.assertEquals(15f, closest.x, 0.01f)
148+
Assert.assertEquals(15f, closest!!.x, 0.01f)
149149
Assert.assertEquals(5f, closest.y, 0.01f)
150150

151151
closest = set.getEntryForXValue(14f, Float.NaN, DataSet.Rounding.DOWN)
152-
Assert.assertEquals(10f, closest.x, 0.01f)
152+
Assert.assertEquals(10f, closest!!.x, 0.01f)
153153
Assert.assertEquals(10f, closest.y, 0.01f)
154154

155155
closest = set.getEntryForXValue(17f, Float.NaN, DataSet.Rounding.UP)
156-
Assert.assertEquals(21f, closest.x, 0.01f)
156+
Assert.assertEquals(21f, closest!!.x, 0.01f)
157157
Assert.assertEquals(5f, closest.y, 0.01f)
158158

159159
closest = set.getEntryForXValue(21f, Float.NaN, DataSet.Rounding.UP)
160-
Assert.assertEquals(21f, closest.x, 0.01f)
160+
Assert.assertEquals(21f, closest!!.x, 0.01f)
161161
Assert.assertEquals(5f, closest.y, 0.01f)
162162

163163
closest = set.getEntryForXValue(21f, Float.NaN, DataSet.Rounding.CLOSEST)
164-
Assert.assertEquals(21f, closest.x, 0.01f)
164+
Assert.assertEquals(21f, closest!!.x, 0.01f)
165165
Assert.assertEquals(5f, closest.y, 0.01f)
166166
}
167167

@@ -186,27 +186,27 @@ class DataSetTest {
186186
val set = ScatterDataSet(values, "")
187187

188188
var closest = set.getEntryForXValue(0f, Float.NaN, DataSet.Rounding.CLOSEST)
189-
Assert.assertEquals(0f, closest.x, 0.01f)
189+
Assert.assertEquals(0f, closest!!.x, 0.01f)
190190
Assert.assertEquals(10f, closest.y, 0.01f)
191191

192192
closest = set.getEntryForXValue(5f, Float.NaN, DataSet.Rounding.CLOSEST)
193-
Assert.assertEquals(5f, closest.x, 0.01f)
193+
Assert.assertEquals(5f, closest!!.x, 0.01f)
194194
Assert.assertEquals(80f, closest.y, 0.01f)
195195

196196
closest = set.getEntryForXValue(5.4f, Float.NaN, DataSet.Rounding.CLOSEST)
197-
Assert.assertEquals(5f, closest.x, 0.01f)
197+
Assert.assertEquals(5f, closest!!.x, 0.01f)
198198
Assert.assertEquals(80f, closest.y, 0.01f)
199199

200200
closest = set.getEntryForXValue(4.6f, Float.NaN, DataSet.Rounding.CLOSEST)
201-
Assert.assertEquals(5f, closest.x, 0.01f)
201+
Assert.assertEquals(5f, closest!!.x, 0.01f)
202202
Assert.assertEquals(80f, closest.y, 0.01f)
203203

204204
closest = set.getEntryForXValue(7f, Float.NaN, DataSet.Rounding.CLOSEST)
205-
Assert.assertEquals(7f, closest.x, 0.01f)
205+
Assert.assertEquals(7f, closest!!.x, 0.01f)
206206
Assert.assertEquals(100f, closest.y, 0.01f)
207207

208208
closest = set.getEntryForXValue(4f, Float.NaN, DataSet.Rounding.CLOSEST)
209-
Assert.assertEquals(4f, closest.x, 0.01f)
209+
Assert.assertEquals(4f, closest!!.x, 0.01f)
210210
Assert.assertEquals(60f, closest.y, 0.01f)
211211

212212
var entries = set.getEntriesForXValue(4f)

0 commit comments

Comments
 (0)