1+ package test.assertk
2+
3+ import assertk.assertions.support.ListDiffer
4+ import org.junit.Test
5+ import kotlin.test.assertEquals
6+
7+ class ListDifferTest {
8+ @Test
9+ fun empty_diff () {
10+ val diff = ListDiffer .diff(emptyList<Any >(), emptyList<Any >())
11+
12+ assertEquals(emptyList(), diff)
13+ }
14+
15+ @Test
16+ fun single_item_no_change () {
17+ val diff = ListDiffer .diff(listOf (1 ), listOf (1 ))
18+
19+ assertEquals(listOf (ListDiffer .Edit .Eq (oldIndex = 0 , oldValue = 1 , newIndex = 0 , newValue = 1 )), diff)
20+ }
21+
22+ @Test
23+ fun singe_insert () {
24+ val diff = ListDiffer .diff(emptyList<Int >(), listOf (1 ))
25+
26+ assertEquals(listOf (ListDiffer .Edit .Ins (newIndex = 0 , newValue = 1 )), diff)
27+ }
28+
29+ @Test
30+ fun singe_delete () {
31+ val diff = ListDiffer .diff(listOf (1 ), emptyList<Int >())
32+
33+ assertEquals(listOf (ListDiffer .Edit .Del (oldIndex = 0 , oldValue = 1 )), diff)
34+ }
35+
36+ @Test
37+ fun single_insert_middle () {
38+ val diff = ListDiffer .diff(listOf (1 , 3 ), listOf (1 , 2 , 3 ))
39+
40+ assertEquals(
41+ listOf (
42+ ListDiffer .Edit .Eq (oldIndex = 0 , oldValue = 1 , newIndex = 0 , newValue = 1 ),
43+ ListDiffer .Edit .Ins (newIndex = 1 , newValue = 2 ),
44+ ListDiffer .Edit .Eq (oldIndex = 1 , oldValue = 3 , newIndex = 2 , newValue = 3 )
45+ ), diff
46+ )
47+ }
48+
49+ @Test
50+ fun singe_delete_middle () {
51+ val diff = ListDiffer .diff(listOf (1 , 2 , 3 ), listOf (1 , 3 ))
52+
53+ assertEquals(
54+ listOf (
55+ ListDiffer .Edit .Eq (oldIndex = 0 , oldValue = 1 , newIndex = 0 , newValue = 1 ),
56+ ListDiffer .Edit .Del (oldIndex = 1 , oldValue = 2 ),
57+ ListDiffer .Edit .Eq (oldIndex = 2 , oldValue = 3 , newIndex = 1 , newValue = 3 )
58+ ), diff
59+ )
60+ }
61+
62+ @Test
63+ fun single_delete_multiple_inserts () {
64+ val diff = ListDiffer .diff(listOf (3 ), listOf (1 , 2 ))
65+
66+ assertEquals(
67+ listOf (
68+ ListDiffer .Edit .Del (oldIndex = 0 , oldValue = 3 ),
69+ ListDiffer .Edit .Ins (newIndex = 0 , newValue = 1 ),
70+ ListDiffer .Edit .Ins (newIndex = 1 , newValue = 2 )
71+ ), diff
72+ )
73+ }
74+ }
0 commit comments