Gridarta Editor
MapSquareIteratorTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.mapmodel;
21 
22 import java.awt.Point;
23 import java.util.Iterator;
27 import org.junit.Assert;
28 import org.junit.Test;
29 
34 public class MapSquareIteratorTest {
35 
39  @Test
40  public void testIteratorForward() {
41  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
42  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
43  final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<>(mapModel, null, +1, false);
44  Assert.assertTrue(it.hasNext());
45  Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next());
46  Assert.assertTrue(it.hasNext());
47  Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next());
48  Assert.assertTrue(it.hasNext());
49  Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next());
50  Assert.assertTrue(it.hasNext());
51  Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next());
52  Assert.assertTrue(it.hasNext());
53  Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next());
54  Assert.assertTrue(it.hasNext());
55  Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next());
56  Assert.assertFalse(it.hasNext());
57  }
58 
62  @Test
63  public void testIteratorBackward() {
64  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
65  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
66  final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<>(mapModel, null, -1, false);
67  Assert.assertTrue(it.hasNext());
68  Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next());
69  Assert.assertTrue(it.hasNext());
70  Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next());
71  Assert.assertTrue(it.hasNext());
72  Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next());
73  Assert.assertTrue(it.hasNext());
74  Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next());
75  Assert.assertTrue(it.hasNext());
76  Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next());
77  Assert.assertTrue(it.hasNext());
78  Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next());
79  Assert.assertFalse(it.hasNext());
80  }
81 
85  @Test
86  public void testIteratorForwardStart() {
87  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
88  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
89  final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<>(mapModel, new Point(0, 1), +1, false);
90  Assert.assertTrue(it.hasNext());
91  Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next());
92  Assert.assertTrue(it.hasNext());
93  Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next());
94  Assert.assertTrue(it.hasNext());
95  Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next());
96  Assert.assertTrue(it.hasNext());
97  Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next());
98  Assert.assertTrue(it.hasNext());
99  Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next());
100  Assert.assertTrue(it.hasNext());
101  Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next());
102  Assert.assertFalse(it.hasNext());
103  }
104 
108  @Test
110  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
111  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
112  final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<>(mapModel, new Point(0, 1), -1, false);
113  Assert.assertTrue(it.hasNext());
114  Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next());
115  Assert.assertTrue(it.hasNext());
116  Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next());
117  Assert.assertTrue(it.hasNext());
118  Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next());
119  Assert.assertTrue(it.hasNext());
120  Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next());
121  Assert.assertTrue(it.hasNext());
122  Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next());
123  Assert.assertTrue(it.hasNext());
124  Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next());
125  Assert.assertFalse(it.hasNext());
126  }
127 
132  @Test
134  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
135  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
136  final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<>(mapModel, new Point(0, 1), +1, true);
137  Assert.assertTrue(it.hasNext());
138  Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next());
139  Assert.assertTrue(it.hasNext());
140  Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next());
141  Assert.assertTrue(it.hasNext());
142  Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next());
143  Assert.assertTrue(it.hasNext());
144  Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next());
145  Assert.assertTrue(it.hasNext());
146  Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next());
147  Assert.assertTrue(it.hasNext());
148  Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next());
149  Assert.assertFalse(it.hasNext());
150  }
151 
156  @Test
158  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
159  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
160  final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<>(mapModel, new Point(0, 1), -1, true);
161  Assert.assertTrue(it.hasNext());
162  Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next());
163  Assert.assertTrue(it.hasNext());
164  Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next());
165  Assert.assertTrue(it.hasNext());
166  Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next());
167  Assert.assertTrue(it.hasNext());
168  Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next());
169  Assert.assertTrue(it.hasNext());
170  Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next());
171  Assert.assertTrue(it.hasNext());
172  Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next());
173  Assert.assertFalse(it.hasNext());
174  }
175 
179  @Test(expected = IllegalArgumentException.class)
180  public void testIteratorDirection0() {
181  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
182  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
183  new MapSquareIterator<>(mapModel, null, 0, false);
184  }
185 
189  @Test(expected = IllegalArgumentException.class)
190  public void testIteratorDirection2() {
191  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
192  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
193  new MapSquareIterator<>(mapModel, null, 2, false);
194  }
195 
196 }
net.sf.gridarta.model.archetype.TestArchetype
An Archetype implementation for testing purposes.
Definition: TestArchetype.java:30
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.model.mapmodel.MapSquareIteratorTest.testIteratorDirection0
void testIteratorDirection0()
Checks that invalid directions are rejected.
Definition: MapSquareIteratorTest.java:180
net.sf.gridarta.model.mapmodel.MapSquareIteratorTest.testIteratorBackward
void testIteratorBackward()
Checks that the backward iterator returns all map squares.
Definition: MapSquareIteratorTest.java:63
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.gameobject.TestGameObject
A GameObject implementation for testing purposes.
Definition: TestGameObject.java:34
net.sf.gridarta.model.mapmodel.MapSquareIteratorTest.testIteratorForward
void testIteratorForward()
Checks that the forward iterator returns all map squares.
Definition: MapSquareIteratorTest.java:40
net.sf
net.sf.gridarta.model.mapmodel.TestMapModelCreator
Helper class for regression tests to create MapModel instances.
Definition: TestMapModelCreator.java:63
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.mapmodel.MapSquareIteratorTest.testIteratorForwardStart
void testIteratorForwardStart()
Checks that the forward iterator returns all map squares.
Definition: MapSquareIteratorTest.java:86
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.mapmodel.TestMapModelCreator.newMapModel
MapModel< TestGameObject, TestMapArchObject, TestArchetype > newMapModel(final int w, final int h)
Creates a new MapModel instance.
Definition: TestMapModelCreator.java:168
net.sf.gridarta.model.mapmodel.MapSquareIteratorTest.testIteratorDirection2
void testIteratorDirection2()
Checks that invalid directions are rejected.
Definition: MapSquareIteratorTest.java:190
net.sf.gridarta.model.mapmodel.MapModel.getMapSquare
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
net.sf.gridarta.model.mapmodel.MapSquareIteratorTest.testIteratorBackwardStartSkip
void testIteratorBackwardStartSkip()
Checks that the backward iterator returns all map squares when skip is enabled.
Definition: MapSquareIteratorTest.java:157
net.sf.gridarta.model
net.sf.gridarta.model.mapmodel.MapSquareIteratorTest
Regression tests for MapSquareIterator.
Definition: MapSquareIteratorTest.java:34
net.sf.gridarta.model.maparchobject.TestMapArchObject
A MapArchObject implementation for testing purposes.
Definition: TestMapArchObject.java:28
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.mapmodel.MapSquareIteratorTest.testIteratorBackwardStart
void testIteratorBackwardStart()
Checks that the backward iterator returns all map squares.
Definition: MapSquareIteratorTest.java:109
net.sf.gridarta.model.mapmodel.MapSquareIteratorTest.testIteratorForwardStartSkip
void testIteratorForwardStartSkip()
Checks that the forward iterator returns all map squares when skip is enabled.
Definition: MapSquareIteratorTest.java:133
net.sf.gridarta.model.mapmodel.MapSquareIterator
Iterator for iterating over all squares of a model.
Definition: MapSquareIterator.java:37
it
This document describes some hints and requirements for general development on the CrossfireEditor If you plan to make changes to the editor code or setup please read the following and keep it in derived from a basic editor application called Gridder by Pasi Ker�nen so please communicate with best through the cf devel mailing before considering any fundamental changes About code DO NOT USE TABS No matter what Java development platform you are please configure insert indent Tabs are displayed totally different in every editor and there are millions of different editors out there The insertion of tabs in the source code is messing up the syntax formatting in a way that is UNREPAIRABLE Apart from please keep code indentation accurate This is not just good it helps to keep code readable and in that way dramatically decreases the chance for overlooked bugs Everyone is welcomed to correct indentation errors wherever they are spotted Before you start to do this please double check that your editor is really configured to insert spaces Line feeds may be checked in either in windows or in unix linux style All reasonable text and java editors can deal with both linefeed formats Converting line feeds is but in this case please make sure that only linefeed characters are changed and nothing else is affected Due to the platform independent nature of the editor has the potential to run on almost any given operating system the build process differs greatly between systems as well as java environments In the several people have attempted to add build scripts along with structural changes to optimize the setup on one particular system environment which has led to conflict Please do *not *attempt to change the structure or any directories for the mere purpose of improving a build process or performance in a java environment Build scripts may be placed in the root it would be especially fine if it is just one or two files but the latter is not required Please excuse me for placing such restriction I and many users of the editor greatly appreciate build scripts We just had some real troubles over this issue in the past and I don t want to have them repeated the editor has relatively high performance requirements I ve spent a lot of extra work to keep everything as fast and memory efficient as possible when you add new data fields or calculations in the archetype please make sure they are as efficient as possible and worth both the time and space they consume Now don t be afraid too much No development would be possible without adding calculations and data at all Just bear in mind unlike for many other open source performance does make a difference for the CrossfireEditor The for as many systems as possible In case you are unexperienced with java and note that the graphics look different on every and with every font They also have different sizes proportions and behave different A seemingly trivial and effectless change can wreck havoc for the same GUI run on another system please don t be totally afraid of it
Definition: Developer_README.txt:76