-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetsTester.java
More file actions
82 lines (67 loc) · 1.6 KB
/
SetsTester.java
File metadata and controls
82 lines (67 loc) · 1.6 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* A simple tester for Sets class
*/
public class SetsTester {
/*
* NOTE: In case you haven't implemented a certain 'Sets' method,
* comment out the relevant test method in the main below.
* For example, if you only implemented the 'exist' method, comment out
* all method calls except 'testExists()' ( // testExists(),
* // testUnion(), etc.).
*/
public static void main(String[] args) {
// Perform tests
testPrintSet();
testExists();
testUnion();
testIntersection();
}
/*
* Tests Sets.intersection(int[], int[]).
*
* Expected output:
* { 7, 1 }
*/
private static void testIntersection() {
int[] a = new int[] { 5, 2, 1, 7 };
int[] b = new int[] { 7, 3, 1 };
Sets.printSet(Sets.intersection(a, b));
}
/*
* Tests Sets.union(int[], int[]).
*
* Expected output:
* { 5, 2, 1, 7, 3 }
*/
private static void testUnion() {
int[] a = new int[] { 5, 2, 1, 7 };
int[] b = new int[] { 7, 3, 1, 9, 7 };
Sets.printSet(Sets.union(a, b));
}
/*
* Tests Sets.exists(int, int[]).
*
* Expected output:
* false
* true
*/
private static void testExists() {
int[] a = new int[] { 5, 2, 1, 7 };
int[] b = new int[] { 7, 3, 1 };
System.out.println(Sets.exists(3, a));
System.out.println(Sets.exists(3, b));
}
/*
* Tests Sets.printSet(int[]).
*
* Expected output:
* { 5, 2, 1, 7 }
* {}
*/
private static void testPrintSet() {
int[] s = new int[] { 5, 2, 1, 7 };
int[] empty = new int[] {};
Sets.printSet(s);
Sets.printSet(empty);
}
}