Gridarta Editor
TopLevelGameObjectIteratorTest.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.jetbrains.annotations.NotNull;
28 import org.junit.Assert;
29 import org.junit.Test;
30 
36 
40  @Test
41  public void testIteratorForwardEmpty() {
42  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
43  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
44  final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<>(mapModel, new Point(1, 1), +1, false);
45  Assert.assertFalse(it.hasNext());
46  }
47 
51  @Test
52  public void testIteratorBackwardEmpty() {
53  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
54  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
55  final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<>(mapModel, new Point(1, 1), -1, false);
56  Assert.assertFalse(it.hasNext());
57  }
58 
62  @Test
63  public void testIteratorForward() {
65  final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<>(mapModel, new Point(1, 1), +1, false);
66  Assert.assertTrue(it.hasNext());
67  Assert.assertEquals("n4", it.next().getBestName());
68  Assert.assertTrue(it.hasNext());
69  Assert.assertEquals("n5", it.next().getBestName());
70  Assert.assertTrue(it.hasNext());
71  Assert.assertEquals("n1", it.next().getBestName());
72  Assert.assertTrue(it.hasNext());
73  Assert.assertEquals("n2", it.next().getBestName());
74  Assert.assertTrue(it.hasNext());
75  Assert.assertEquals("n3", it.next().getBestName());
76  Assert.assertFalse(it.hasNext());
77  }
78 
82  @Test
83  public void testIteratorBackward() {
85  final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<>(mapModel, new Point(1, 1), -1, false);
86  Assert.assertTrue(it.hasNext());
87  Assert.assertEquals("n4", it.next().getBestName());
88  Assert.assertTrue(it.hasNext());
89  Assert.assertEquals("n3", it.next().getBestName());
90  Assert.assertTrue(it.hasNext());
91  Assert.assertEquals("n1", it.next().getBestName());
92  Assert.assertTrue(it.hasNext());
93  Assert.assertEquals("n2", it.next().getBestName());
94  Assert.assertTrue(it.hasNext());
95  Assert.assertEquals("n5", it.next().getBestName());
96  Assert.assertFalse(it.hasNext());
97  }
98 
102  @Test
103  public void testIteratorForwardSkip() {
105  final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<>(mapModel, new Point(1, 1), +1, true);
106  Assert.assertTrue(it.hasNext());
107  Assert.assertEquals("n5", it.next().getBestName());
108  Assert.assertTrue(it.hasNext());
109  Assert.assertEquals("n1", it.next().getBestName());
110  Assert.assertTrue(it.hasNext());
111  Assert.assertEquals("n2", it.next().getBestName());
112  Assert.assertTrue(it.hasNext());
113  Assert.assertEquals("n3", it.next().getBestName());
114  Assert.assertTrue(it.hasNext());
115  Assert.assertEquals("n4", it.next().getBestName());
116  Assert.assertFalse(it.hasNext());
117  }
118 
122  @Test
123  public void testIteratorBackwardSkip() {
125  final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<>(mapModel, new Point(1, 1), -1, true);
126  Assert.assertTrue(it.hasNext());
127  Assert.assertEquals("n3", it.next().getBestName());
128  Assert.assertTrue(it.hasNext());
129  Assert.assertEquals("n1", it.next().getBestName());
130  Assert.assertTrue(it.hasNext());
131  Assert.assertEquals("n2", it.next().getBestName());
132  Assert.assertTrue(it.hasNext());
133  Assert.assertEquals("n5", it.next().getBestName());
134  Assert.assertTrue(it.hasNext());
135  Assert.assertEquals("n4", it.next().getBestName());
136  Assert.assertFalse(it.hasNext());
137  }
138 
143  @NotNull
145  final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
146  final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2);
147  final InsertionMode insertionMode = mapModelCreator.getTopmostInsertionMode();
148  mapModelCreator.addGameObjectToMap(mapModel, "arch", "n1", 0, 0, insertionMode);
149  mapModelCreator.addGameObjectToMap(mapModel, "arch", "n2", 0, 0, insertionMode);
150  mapModelCreator.addGameObjectToMap(mapModel, "arch", "n3", 2, 0, insertionMode);
151  mapModelCreator.addGameObjectToMap(mapModel, "arch", "n4", 1, 1, insertionMode);
152  mapModelCreator.addGameObjectToMap(mapModel, "arch", "n5", 2, 1, insertionMode);
153 
154  //noinspection ConstantConditions
155  mapModelCreator.insertGameObject(mapModel.getMapSquare(new Point(2, 0)).getFirst(), "arch", "i1");
156 
157  return mapModel;
158  }
159 
160 }
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.TopLevelGameObjectIteratorTest.testIteratorBackwardSkip
void testIteratorBackwardSkip()
Checks the backward iterator with skipped first element.
Definition: TopLevelGameObjectIteratorTest.java:123
net.sf.gridarta.model.mapmodel.TopLevelGameObjectIteratorTest.testIteratorForward
void testIteratorForward()
Checks the forward iterator.
Definition: TopLevelGameObjectIteratorTest.java:63
net.sf.gridarta.model.mapmodel.TopLevelGameObjectIteratorTest.testIteratorBackwardEmpty
void testIteratorBackwardEmpty()
Checks the backward iterator on an empty map.
Definition: TopLevelGameObjectIteratorTest.java:52
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.mapmodel.TopLevelGameObjectIteratorTest.testIteratorBackward
void testIteratorBackward()
Checks the backward iterator.
Definition: TopLevelGameObjectIteratorTest.java:83
net.sf.gridarta.model.gameobject.TestGameObject
A GameObject implementation for testing purposes.
Definition: TestGameObject.java:34
net.sf
net.sf.gridarta.model.mapmodel.TopLevelGameObjectIterator
Iterator for iterating over top-level game object of a map model.
Definition: TopLevelGameObjectIterator.java:35
net.sf.gridarta.model.mapmodel.TestMapModelCreator.insertGameObject
void insertGameObject(@NotNull final GameObject< TestGameObject, TestMapArchObject, TestArchetype > gameObject, @NotNull final String archetypeName, @NotNull final String name)
Inserts a game object into the inventory of another game object.
Definition: TestMapModelCreator.java:220
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.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.TopLevelGameObjectIteratorTest.testIteratorForwardSkip
void testIteratorForwardSkip()
Checks the forward iterator with skipped first element.
Definition: TopLevelGameObjectIteratorTest.java:103
net.sf.gridarta.model.mapmodel.TopLevelGameObjectIteratorTest.createMap
static MapModel< TestGameObject, TestMapArchObject, TestArchetype > createMap()
Creates a new MapModel instance filled with game objects.
Definition: TopLevelGameObjectIteratorTest.java:144
net.sf.gridarta.model.mapmodel.InsertionMode
Insertion modes.
Definition: InsertionMode.java:33
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.TestMapModelCreator.getTopmostInsertionMode
InsertionMode getTopmostInsertionMode()
Returns the "topmost" insertion mode.
Definition: TestMapModelCreator.java:239
net.sf.gridarta.model.mapmodel.TopLevelGameObjectIteratorTest.testIteratorForwardEmpty
void testIteratorForwardEmpty()
Checks the forward iterator on an empty map.
Definition: TopLevelGameObjectIteratorTest.java:41
net.sf.gridarta.model
net.sf.gridarta.model.mapmodel.TopLevelGameObjectIteratorTest
Regression tests for TopLevelGameObjectIterator.
Definition: TopLevelGameObjectIteratorTest.java:35
net.sf.gridarta.model.mapmodel.TestMapModelCreator.addGameObjectToMap
void addGameObjectToMap(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final String archetypeName, @NotNull final String name, final int x, final int y, @NotNull final InsertionMode insertionMode)
Inserts a game object into a map.
Definition: TestMapModelCreator.java:209
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
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