summaryrefslogtreecommitdiffstats
path: root/core/test/ch/asynk/rustanddust/Util.java
blob: 5ed7b13a0bb3e879284bec3b11ed6db997f377a2 (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
package ch.asynk.rustanddust;

import org.junit.Test;

import ch.asynk.rustanddust.engine.util.IterableArray;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;

public class Util
{
    @Test
    public void testArray()
    {
        IterableArray<Object> a = new IterableArray<Object>(3);
        assertTrue(a.isEmpty());
        assertTrue(a.size() == 0);
        a.add(new Object());
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 1);
        a.add(new Object());
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 2);
        Object o = new Object();
        assertFalse(a.contains(o));
        a.add(o);
        assertTrue(a.contains(o));
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 3);
        a.add(new Object());
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 4);

        assertTrue(a.get(2) == o);

        a.clear();
        assertTrue(a.isEmpty());
        assertTrue(a.size() == 0);

        a.add(new Object());
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 1);
        a.add(new Object());
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 2);
        assertFalse(a.contains(o));
        a.add(o);
        assertTrue(a.contains(o));
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 3);
        a.add(new Object());
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 4);

        assertTrue(a.get(2) == o);
        a.add(o);
        assertTrue(a.contains(o));

        assertFalse(a.isEmpty());
        assertTrue(a.size() == 5);
        assertTrue(a.remove(o));
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 4);
        assertTrue(a.remove(o));
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 3);
        assertFalse(a.remove(o));

        assertNotNull(a.remove(1));
        assertFalse(a.isEmpty());
        assertTrue(a.size() == 2);
    }
}