~ubuntu-branches/ubuntu/wily/gs-collections/wily

« back to all changes in this revision

Viewing changes to gs-collections-code-generator/src/main/resources/test/stack/mutable/abstractMutablePrimitiveStackTestCase.stg

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2015-07-23 12:42:30 UTC
  • Revision ID: package-import@ubuntu.com-20150723124230-2rjvfv6elyn2m7d4
Tags: upstream-5.1.0
ImportĀ upstreamĀ versionĀ 5.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import "copyright.stg"
 
2
import "primitiveHashCode.stg"
 
3
import "primitiveLiteral.stg"
 
4
 
 
5
isTest() ::= "true"
 
6
 
 
7
skipBoolean() ::="true"
 
8
 
 
9
targetPath() ::= "com/gs/collections/impl/stack/mutable/primitive"
 
10
 
 
11
fileName(primitive) ::= "AbstractMutable<primitive.name>StackTestCase"
 
12
 
 
13
class(primitive) ::= <<
 
14
<body(primitive.type, primitive.wrapperName, primitive.name)>
 
15
>>
 
16
 
 
17
body(type, wrapperName, name) ::= <<
 
18
<copyright()>
 
19
 
 
20
package com.gs.collections.impl.stack.mutable.primitive;
 
21
 
 
22
import java.util.EmptyStackException;
 
23
 
 
24
import com.gs.collections.api.<name>Iterable;
 
25
import com.gs.collections.api.stack.primitive.Mutable<name>Stack;
 
26
import com.gs.collections.impl.list.mutable.primitive.<name>ArrayList;
 
27
import com.gs.collections.impl.stack.primitive.Abstract<name>StackTestCase;
 
28
import com.gs.collections.impl.test.Verify;
 
29
import org.junit.Assert;
 
30
import org.junit.Test;
 
31
 
 
32
/**
 
33
 * Abstract JUnit test for {@link Mutable<name>Stack}.
 
34
 * This file was automatically generated from template file abstractMutablePrimitiveStackTestCase.stg.
 
35
 */
 
36
public abstract class AbstractMutable<name>StackTestCase extends Abstract<name>StackTestCase
 
37
{
 
38
    @Override
 
39
    protected abstract Mutable<name>Stack classUnderTest();
 
40
 
 
41
    @Override
 
42
    protected abstract Mutable<name>Stack newWith(<type>... elements);
 
43
 
 
44
    @Override
 
45
    protected abstract Mutable<name>Stack newMutableCollectionWith(<type>... elements);
 
46
 
 
47
    @Override
 
48
    protected abstract Mutable<name>Stack newWithTopToBottom(<type>... elements);
 
49
 
 
50
    protected abstract Mutable<name>Stack newWithIterableTopToBottom(<name>Iterable iterable);
 
51
 
 
52
    protected abstract Mutable<name>Stack newWithIterable(<name>Iterable iterable);
 
53
 
 
54
 
 
55
    @Override
 
56
    public void peekAtIndex()
 
57
    {
 
58
        super.peekAtIndex();
 
59
        Mutable<name>Stack stack = this.classUnderTest();
 
60
        int size = stack.size();
 
61
        stack.pop(2);
 
62
        Assert.assertEquals(size - 2, stack.peekAt(0)<wideDelta.(type)>);
 
63
    }
 
64
 
 
65
    @Override
 
66
    @Test
 
67
    public void peek()
 
68
    {
 
69
        super.peek();
 
70
        Mutable<name>Stack stack = this.classUnderTest();
 
71
        int size = this.classUnderTest().size();
 
72
        for (int i = 0; i \< size; i++)
 
73
        {
 
74
            Assert.assertEquals(size - i, stack.peek()<wideDelta.(type)>);
 
75
            stack.pop();
 
76
        }
 
77
    }
 
78
 
 
79
    @Test
 
80
    public void peekWithCount()
 
81
    {
 
82
        Mutable<name>Stack stack = this.classUnderTest();
 
83
        int size = stack.size();
 
84
        Assert.assertEquals(<name>ArrayList.newListWith(<(castIntToNarrowType.(type))("size")>, <(castIntToNarrowTypeWithParens.(type))("size - 1")>), stack.peek(2));
 
85
        stack.pop(2);
 
86
        Assert.assertEquals(<name>ArrayList.newListWith(<(castIntToNarrowTypeWithParens.(type))("size - 2")>), stack.peek(1));
 
87
    }
 
88
 
 
89
    @Test(expected = EmptyStackException.class)
 
90
    public void peek_empty_stack_throws_exception()
 
91
    {
 
92
        this.newWith().peek();
 
93
    }
 
94
 
 
95
    @Test
 
96
    public void testNewStackWithOrder()
 
97
    {
 
98
        Mutable<name>Stack stack = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">);
 
99
        Assert.assertEquals(<(literal.(type))("3")>, stack.pop()<wideDelta.(type)>);
 
100
        Assert.assertEquals(<(literal.(type))("2")>, stack.pop()<wideDelta.(type)>);
 
101
        Assert.assertEquals(<(literal.(type))("1")>, stack.pop()<wideDelta.(type)>);
 
102
    }
 
103
 
 
104
    @Test
 
105
    public void testNewStackIterableOrder()
 
106
    {
 
107
        Mutable<name>Stack stack = this.newWithIterable(<name>ArrayList.newListWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">));
 
108
        Assert.assertEquals(<(literal.(type))("3")>, stack.pop()<wideDelta.(type)>);
 
109
        Assert.assertEquals(<(literal.(type))("2")>, stack.pop()<wideDelta.(type)>);
 
110
        Assert.assertEquals(<(literal.(type))("1")>, stack.pop()<wideDelta.(type)>);
 
111
    }
 
112
 
 
113
 
 
114
    @Test
 
115
    public void testNewStackFromTopToBottomOrder()
 
116
    {
 
117
        Mutable<name>Stack stack = this.newWithTopToBottom(<["3", "2", "1"]:(literal.(type))(); separator=", ">);
 
118
        Assert.assertEquals(<(literal.(type))("3")>, stack.pop()<wideDelta.(type)>);
 
119
        Assert.assertEquals(<(literal.(type))("2")>, stack.pop()<wideDelta.(type)>);
 
120
        Assert.assertEquals(<(literal.(type))("1")>, stack.pop()<wideDelta.(type)>);
 
121
    }
 
122
 
 
123
    @Test
 
124
    public void testNewStackFromTopToBottomIterableOrder()
 
125
    {
 
126
        Mutable<name>Stack stack = this.newWithIterableTopToBottom(<name>ArrayList.newListWith(<["3", "2", "1"]:(literal.(type))(); separator=", ">));
 
127
        Assert.assertEquals(<(literal.(type))("3")>, stack.pop()<wideDelta.(type)>);
 
128
        Assert.assertEquals(<(literal.(type))("2")>, stack.pop()<wideDelta.(type)>);
 
129
        Assert.assertEquals(<(literal.(type))("1")>, stack.pop()<wideDelta.(type)>);
 
130
    }
 
131
 
 
132
    @Test
 
133
    public void push()
 
134
    {
 
135
        Mutable<name>Stack stack = this.classUnderTest();
 
136
        int size = stack.size();
 
137
        stack.push(<(literal.(type))("5")>);
 
138
        Verify.assertSize(size + 1, stack);
 
139
        stack.pop();
 
140
        Verify.assertSize(size, stack);
 
141
        Assert.assertEquals(<name>ArrayList.newListWith(<(castIntToNarrowType.(type))("size")>, <(castIntToNarrowTypeWithParens.(type))("size - 1")>), stack.peek(2));
 
142
    }
 
143
 
 
144
    @Test
 
145
    public void pop()
 
146
    {
 
147
        Mutable<name>Stack stack = this.classUnderTest();
 
148
        int size = stack.size();
 
149
        for (int i = 0; i \< size; i++)
 
150
        {
 
151
            Assert.assertEquals(<(castIntToNarrowTypeWithParens.(type))("size - i")>, stack.pop()<wideDelta.(type)>);
 
152
            Verify.assertSize(size - i - 1, stack);
 
153
        }
 
154
    }
 
155
 
 
156
    @Test
 
157
    public void popWithCount()
 
158
    {
 
159
        int size = this.classUnderTest().size();
 
160
        Assert.assertEquals(<name>ArrayList.newListWith(<(castIntToNarrowType.(type))("size")>, <(castIntToNarrowTypeWithParens.(type))("size - 1")>), this.classUnderTest().pop(2));
 
161
    }
 
162
 
 
163
    @Test
 
164
    public void clear()
 
165
    {
 
166
        Mutable<name>Stack stack = this.classUnderTest();
 
167
        stack.clear();
 
168
        Verify.assertSize(0, stack);
 
169
        Mutable<name>Stack stack1 = this.newWith();
 
170
        Verify.assertSize(0, stack1);
 
171
        stack1.clear();
 
172
        Verify.assertSize(0, stack1);
 
173
    }
 
174
 
 
175
    @Test(expected = EmptyStackException.class)
 
176
    public void pop_empty_stack_throws_exception()
 
177
    {
 
178
        this.newWith().pop();
 
179
    }
 
180
 
 
181
    @Test(expected = IllegalArgumentException.class)
 
182
    public void pop_with_negative_count_throws_exception()
 
183
    {
 
184
        this.newWith(<(literal.(type))("1")>).pop(-1);
 
185
    }
 
186
 
 
187
    @Test(expected = IllegalArgumentException.class)
 
188
    public void pop_with_count_greater_than_stack_size_throws_exception()
 
189
    {
 
190
        this.newWith(<(literal.(type))("1")>).pop(2);
 
191
    }
 
192
 
 
193
    @Test
 
194
    public void asSynchronized()
 
195
    {
 
196
        Verify.assertInstanceOf(Synchronized<name>Stack.class, this.classUnderTest().asSynchronized());
 
197
        Assert.assertEquals(this.classUnderTest(), this.classUnderTest().asSynchronized());
 
198
    }
 
199
 
 
200
    @Test
 
201
    public void asUnmodifiable()
 
202
    {
 
203
        Verify.assertInstanceOf(Unmodifiable<name>Stack.class, this.classUnderTest().asUnmodifiable());
 
204
        Assert.assertEquals(this.classUnderTest(), this.classUnderTest().asUnmodifiable());
 
205
    }
 
206
}
 
207
 
 
208
>>