forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashSetExampleTest.java
More file actions
43 lines (37 loc) · 916 Bytes
/
HashSetExampleTest.java
File metadata and controls
43 lines (37 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.examplehub.basics.set;
import static org.junit.jupiter.api.Assertions.*;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;
class HashSetExampleTest {
@Test
void testAdd() {
Set<Integer> set = new HashSet<>();
assertTrue(set.add(2));
assertFalse(set.add(2));
assertTrue(set.add(3));
assertTrue(set.add(1));
assertEquals("[1, 2, 3]", set.toString());
}
@Test
void testRemove() {
Set<Integer> set = new HashSet<>();
set.add(2);
set.add(3);
set.add(1);
assertTrue(set.remove(2));
assertTrue(set.remove(1));
assertFalse(set.remove(1));
assertEquals("[3]", set.toString());
}
@Test
void testClear() {
Set<Integer> set = new HashSet<>();
set.add(2);
set.add(3);
set.add(1);
assertEquals("[1, 2, 3]", set.toString());
set.clear();
assertEquals("[]", set.toString());
}
}