@@ -7,10 +7,34 @@ package tests.contract.list
77
88import kotlinx.collections.immutable.implementations.immutableList.MAX_BUFFER_SIZE
99
10+ /* *
11+ * Checks the assumption behind the hand-picked sizes in the list contract tests.
12+ *
13+ * The persistent list is a 32-way trie plus a tail buffer, so it changes shape at fixed sizes.
14+ * With [MAX_BUFFER_SIZE] = 32 the boundaries used across these tests are:
15+ * - 32: a full tail and no trie, the largest small vector;
16+ * - 33: the first leaf is pushed into the root;
17+ * - 64, 96: the tail is full again, with one and two leaves in the root;
18+ * - 65, 97: the second and the third leaf are pushed into the root;
19+ * - 1056: the root and the tail are both full;
20+ * - 1057: the root grows a level, producing a two-level trie;
21+ * - 1089: the first leaf is pushed into the root after it grew;
22+ * - 1091 (0..1090): a two-level root with two top-level children;
23+ * - 2146 (0..2145): a two-level root with three top-level children, so trimming the trie
24+ * down to 1057 elements has a stale top-level child to nullify.
25+ *
26+ * Sizes between the boundaries (40, 100, 1100, ...) only need to stay inside the shape
27+ * named by their test, their exact values carry no meaning. The exception is an inserted
28+ * collection whose size is a multiple of 32: it preserves the tail size on purpose.
29+ *
30+ * If [MAX_BUFFER_SIZE] changes, this check fails: re-pick every size from the rules above
31+ * and verify with a coverage run (koverHtmlReport) that all branches of the immutableList
32+ * implementation are still exercised.
33+ */
1034internal fun checkTrieShapeAssumptions () {
1135 check(MAX_BUFFER_SIZE == 32 ) {
1236 """
13- The sizes in this class are hand-picked trie shape boundaries for the buffer size of 32.
37+ The sizes in these tests are hand-picked trie shape boundaries for the buffer size of 32.
1438 If MAX_BUFFER_SIZE changes, revisit each size manually
1539 and verify that all branches of the code under test are still covered.
1640 """ .trimIndent()
0 commit comments