summaryrefslogtreecommitdiff
path: root/src/test/java/bjc/esodata/ThresholdSetTest.java
blob: 8f1b995adc6c79da9374af61bc491463ab1fe38c (plain)
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
package bjc.esodata;

import org.junit.Test;

import static bjc.TestUtils.*;

import static bjc.esodata.ThresholdSet.*;

import static org.junit.Assert.*;

/**
 * Tests for ThresholdSet
 *
 * @author Ben Culkin.
 */
public class ThresholdSetTest {
	@Test
	public void testAdd() {
		ThresholdSet<String> thst = TS("a", "b");

		assertIteratorSet(false, thst.setView().iterator(), "a", "b");
		assertEquals(thst.setSize(), 2);
	}

	@Test
	public void testAddMulti() {
		ThresholdSet<String> thst = TS("a", "b", "a");

		assertIteratorSet(false, thst.setView().iterator(), "b");
		assertEquals(thst.setSize(), 1);
	}

	@Test
	public void testAddMulti2() {
		ThresholdSet<String> thst = TS("a", "b");
		thst.add("a");

		assertIteratorSet(false, thst.setView().iterator(), "b");
		assertEquals(thst.setSize(), 1);
	}

	@Test
	public void testContains() {
		ThresholdSet<String> thst = TS("1", "2", "2", "x", "z");

		int[] exps = new int[] {
				1, 2, -1
		};
		assertArrayEquals(exps, thst.containsKeys("1", "2", "y"));
	}

	@Test
	public void testRemoveMulti() {
		ThresholdSet<String> thst = TS("a", "a", "b");

		thst.remove("a");

		assertIteratorSet(false, thst.setView().iterator(), "a", "b");
		assertEquals(2, thst.setSize());

		thst.remove("a");

		assertIteratorSet(false, thst.setView().iterator(), "b");
		assertEquals(1, thst.setSize());
	}

	@Test
	public void testSetTransparency() {
		ThresholdSet<String> thst = TS("a", "b", "c");

		thst.setView().add("b");
		assertIteratorSet(false, thst.setView().iterator(), "a", "c");
		assertEquals(2, thst.setView().size());

		thst.setView().remove("c");
		assertIteratorSet(false, thst.setView().iterator(), "a");
	}
}