Skip to content

Commit d76cf34

Browse files
committed
Unit test for computing fractions
1 parent 81b0c7a commit d76cf34

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

core/src/commonMain/kotlin/com/powersync/sync/Progress.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import com.powersync.bucket.LocalOperationCounters
1414
* on [SyncStatusData].
1515
*/
1616
public data class ProgressWithOperations(
17+
val completed: Int,
1718
val total: Int,
18-
val completed: Int
1919
) {
2020
/**
2121
* The relative amount of [total] items that have been [completed], as a number between `0.0` and `1.0`.
@@ -80,7 +80,7 @@ public data class SyncDownloadProgress private constructor(
8080
*/
8181
public fun untilPriority(priority: BucketPriority): ProgressWithOperations {
8282
val (total, completed) = targetAndCompletedCounts(priority)
83-
return ProgressWithOperations(total, completed)
83+
return ProgressWithOperations(completed = completed, total = total)
8484
}
8585

8686
internal fun incrementDownloaded(batch: SyncDataBatch): SyncDownloadProgress {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.powersync.sync
2+
3+
import kotlin.test.Test
4+
import kotlin.test.assertEquals
5+
6+
class ProgressTest {
7+
8+
@Test
9+
fun reportsFraction() {
10+
assertEquals(0.0, ProgressWithOperations(0, 10).fraction)
11+
assertEquals(0.5, ProgressWithOperations(5, 10).fraction)
12+
assertEquals(1.0, ProgressWithOperations(10, 10).fraction)
13+
14+
assertEquals(0.0, ProgressWithOperations(0, 0).fraction)
15+
}
16+
}

0 commit comments

Comments
 (0)