This commit is contained in:
akkkihi 2023-05-12 23:04:06 +03:00
parent 61ea85ac1b
commit ac34050285

View File

@ -166,6 +166,45 @@ class MapDiffUtilsTests {
) )
} }
@Test
fun testApplyMapDiffRemovedStrictComparison() {
val oldMap = mutableMapOf("a" to 1, "b" to 2, "c" to 3)
val newMap = mutableMapOf("a" to 1, "c" to 3, "d" to 4)
val diff = oldMap.applyDiff(newMap, true)
assertEquals(
mapOf("b" to 2),
diff.removed
)
}
@Test
fun testApplyMapDiffAddedStrictComparison() {
val oldMap = mutableMapOf("a" to 1, "b" to 2, "c" to 3)
val newMap = mutableMapOf("a" to 1, "c" to 3, "d" to 4)
val diff = oldMap.applyDiff(newMap, true)
assertEquals(
mapOf("d" to 4),
diff.added
)
}
@Test
fun testApplyMapDiffChangedStrictComparison() {
val oldMap = mutableMapOf("a" to 1, "b" to 2, "c" to 3)
val newMap = mutableMapOf("a" to 1, "c" to 5, "d" to 4)
val diff = oldMap.applyDiff(newMap, true)
assertEquals(
mapOf("c" to (3 to 5)),
diff.changed
)
}
@Test @Test
fun testApplyMapDiffRemovedWithCompareFun() { fun testApplyMapDiffRemovedWithCompareFun() {
val originalMap = mutableMapOf("a" to 1, "b" to 2, "c" to 3) val originalMap = mutableMapOf("a" to 1, "b" to 2, "c" to 3)
@ -212,34 +251,47 @@ class MapDiffUtilsTests {
} }
@Test @Test
@OptIn(Warning::class)
fun testMapDiffMixed() { fun testMapDiffMixed() {
val originalMap = mutableMapOf("a" to 1, "b" to 2, "c" to 3) val oldMap = mutableMapOf("a" to 1, "b" to 2, "c" to 3)
val diff = MapDiff(mapOf("b" to 2), mapOf("c" to (3 to 5)), mapOf("d" to 4)) val newMap = mutableMapOf("a" to 1, "c" to 5, "d" to 4)
val mapDiff = MapDiff(mapOf("b" to 2), mapOf("c" to (3 to 5)), mapOf("d" to 4))
originalMap.remove("b") val diff = oldMap.diff(newMap)
// change value
originalMap["c"] = 5
// add value
originalMap["d"] = 4
assertEquals( assertEquals(
mapOf("a" to 1, "c" to 5, "d" to 4), mapDiff.removed,
originalMap diff.removed
)
assertEquals(
mapDiff.changed,
diff.changed
)
assertEquals(
mapDiff.added,
diff.added
) )
} }
@Test @Test
@OptIn(Warning::class)
fun testApplyMapDiffMixed() { fun testApplyMapDiffMixed() {
val originalMap = mutableMapOf("a" to 1, "b" to 2, "c" to 3) val oldMap = mutableMapOf("a" to 1, "b" to 2, "c" to 3)
val diff = MapDiff(mapOf("b" to 2), mapOf("c" to (3 to 5)), mapOf("d" to 4)) val newMap = mutableMapOf("a" to 1, "c" to 5, "d" to 4)
originalMap.applyDiff(diff) val mapDiff = MapDiff(mapOf("b" to 2), mapOf("c" to (3 to 5)), mapOf("d" to 4))
val diff = oldMap.applyDiff(newMap)
assertEquals( assertEquals(
mapOf("a" to 1, "c" to 5, "d" to 4), mapDiff.removed,
originalMap diff.removed
)
assertEquals(
mapDiff.changed,
diff.changed
)
assertEquals(
mapDiff.added,
diff.added
) )
} }