Gridarta Editor
Size2DTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 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.utils;
21 
22 import org.junit.Assert;
23 import org.junit.Test;
24 
29 @SuppressWarnings("FeatureEnvy")
30 // This is a test. It has feature envy by definition.
31 public class Size2DTest {
32 
36  @Test
37  public void testSize2D() {
38  final Size2D size = new Size2D(100, 200);
39  Assert.assertEquals("width MUST be stored", 100, size.getWidth());
40  Assert.assertEquals("height MUST be stored", 200, size.getHeight());
41  }
42 
46  @Test
47  public void testEquals() {
48  final Size2D size1 = new Size2D(100, 200);
49  final Size2D size2 = new Size2D(100, 200);
50  final Size2D size3 = new Size2D(100, 200);
51  final Size2D differWidth = new Size2D(50, 200);
52  final Size2D differHeight = new Size2D(100, 80);
53  final Size2D differBoth = new Size2D(50, 80);
54  Assert.assertEquals("Sizes with identical width and height MUST be equal.", size1, size2);
55  Assert.assertEquals("Sizes with identical width and height MUST be equal.", size1, size3);
56  Assert.assertEquals("Sizes with identical width and height MUST be equal.", size2, size1);
57  Assert.assertEquals("Sizes with identical width and height MUST be equal.", size2, size3);
58  Assert.assertEquals("Sizes with identical width and height MUST be equal.", size3, size1);
59  Assert.assertEquals("Sizes with identical width and height MUST be equal.", size3, size2);
60  Assert.assertFalse("Sizes with different width or height MUST be unequal", size1.equals(differBoth));
61  Assert.assertFalse("Sizes with different width or height MUST be unequal", size1.equals(differWidth));
62  Assert.assertFalse("Sizes with different width or height MUST be unequal", size1.equals(differHeight));
63  }
64 
68  @Test
69  public void testHashCode() {
70  final Size2D size1 = new Size2D(100, 200);
71  final Size2D size2 = new Size2D(100, 200);
72  Assert.assertEquals("Equal sizes MUST return the same hashCode.", size1.hashCode(), size2.hashCode());
73  }
74 
78  @Test
79  public void testGetWidth() {
80  final Size2D size = new Size2D(100, 200);
81  Assert.assertEquals("width MUST be stored", 100, size.getWidth());
82  }
83 
87  @Test
88  public void testGetHeight() {
89  final Size2D size = new Size2D(100, 200);
90  Assert.assertEquals("height MUST be stored", 200, size.getHeight());
91  }
92 
93 }
boolean equals(@Nullable final Object obj)
Definition: Size2D.java:76
void testSize2D()
Test case for Size2D#Size2D(int, int).
Definition: Size2DTest.java:37
void testGetWidth()
Test case for Size2D#getWidth().
Definition: Size2DTest.java:79
void testHashCode()
Test case for Size2D#hashCode().
Definition: Size2DTest.java:69
int getWidth()
Returns the width of the area.
Definition: Size2D.java:96
int getHeight()
Returns the height of the area.
Definition: Size2D.java:104
void testGetHeight()
Test case for Size2D#getHeight().
Definition: Size2DTest.java:88
void testEquals()
Test case for Size2D#equals(Object).
Definition: Size2DTest.java:47
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30