source: java2python/core/src/test/remove/testcode/Remove.java

Last change on this file was 1428, checked in by wouter, 8 days ago

user removeFirst to implement list,set.remove. Added test to show it works

File size: 1.3 KB
Line 
1package testcode;
2
3import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.HashSet;
6import java.util.List;
7import java.util.Set;
8
9import org.eclipse.jdt.annotation.NonNull;
10
11/**
12 * Test various remove, removeall, etc.
13 */
14public class Remove {
15
16 static public void main(String[] args) {
17 testRemoveFromList();
18 testRemoveFromSet();
19 }
20
21 private static void testRemoveFromList() {
22 final @NonNull List<@NonNull String> lst = new ArrayList<>(
23 Arrays.asList("a", "b", "c", "b"));
24 boolean result = lst.remove("b");
25 if (!result)
26 throw new IllegalStateException("removing b should have succeeded");
27 result = lst.remove("b");
28 if (!result)
29 throw new IllegalStateException("removing b should have succeeded");
30 result = lst.remove("b");
31 if (result)
32 throw new IllegalStateException("removing b should have failed");
33 System.out.println("ok0");
34 }
35
36 private static void testRemoveFromSet() {
37 final @NonNull Set<@NonNull String> st = new HashSet<>(
38 Arrays.asList("a", "b", "c", "b"));
39 // note, duplicate b, one will be removed as this is a set.
40 boolean result = st.remove("b");
41 if (!result)
42 throw new IllegalStateException("removing b should have succeeded");
43 result = st.remove("b");
44 if (result)
45 throw new IllegalStateException("removing b should have failed");
46 System.out.println("ok1");
47 }
48
49}
Note: See TracBrowser for help on using the repository browser.