1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
12 import cc
.squirreljme
.jvm
.mle
.brackets
.UIDisplayBracket
;
13 import cc
.squirreljme
.jvm
.mle
.brackets
.UIFormBracket
;
14 import cc
.squirreljme
.jvm
.mle
.brackets
.UIItemBracket
;
15 import cc
.squirreljme
.jvm
.mle
.constants
.UIItemType
;
16 import cc
.squirreljme
.runtime
.lcdui
.mle
.UIBackend
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
19 import java
.util
.Random
;
22 * Tests that removing items shifts them accordingly.
26 public class TestItemRemoveShift
34 protected void test(UIBackend __backend
, UIDisplayBracket __display
,
37 // Setup all the items and add to the form beforehand
38 List
<__Holder__
> items
= new ArrayList
<>();
39 for (int i
= 0; i
< UIItemType
.NUM_TYPES
; i
++)
41 UIItemBracket item
= __backend
.itemNew(i
);
43 items
.add(new __Holder__(item
));
44 __backend
.formItemPosition(__form
, item
, i
);
47 // We will be removing random elements!
48 Random random
= new Random(12);
50 while (!items
.isEmpty())
52 int count
= items
.size();
54 // Determine index to be removed
55 int dx
= (count
== 1 ?
0 : random
.nextInt(count
));
58 UIItemBracket old
= __backend
.formItemRemove(__form
, dx
);
60 // Should both be the same items from the list
61 this.secondary("same-" + removalCount
,
62 __backend
.equals(old
, items
.remove(dx
).item
));
64 // Count should be reduced by one
65 int subCount
= count
- 1;
66 this.secondary("subcount-" + removalCount
,
67 subCount
== __backend
.formItemCount(__form
));
69 // All of these should be the same item in the list
70 boolean[] matches
= new boolean[subCount
];
71 for (int j
= 0; j
< subCount
; j
++)
72 matches
[j
] = __backend
.equals(items
.get(j
).item
,
73 __backend
.formItemAtPosition(__form
, j
));
74 this.secondary("sameitems-" + removalCount
, matches
);
76 // For the next run (in testing)
80 // Form should be empty
81 this.secondary("empty", __backend
.formItemCount(__form
));