Adds equals/hashCode tests.
package com.valkryst.VTerminal.misc;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
public class IntRangeTest {
+ private IntRange range;
+
+ @Before
+ public void initializeRange() {
+ range = new IntRange(1, 200);
+ }
+
@Test
public void testConstructor() {
final IntRange range = new IntRange(1, 2);
@@ -32,9 +40,48 @@ public class IntRangeTest {
Assert.assertEquals(1, range.getEnd());
}
+ @Test
+ public void testEquals_withSelf() {
+ Assert.assertEquals(range, range);
+ }
+
+ @Test
+ public void testEquals_withEqualRanges() {
+ final IntRange rangeB = new IntRange(1, 200);
+ Assert.assertEquals(range, rangeB);
+ }
+
+ @Test
+ public void testEquals_withNonIntRangeObject() {
+ Assert.assertNotEquals(range, 7);
+ }
+
+ @Test
+ public void testEquals_withNonEqualBegin() {
+ final IntRange rangeB = new IntRange(6, 200);
+ Assert.assertNotEquals(range, rangeB);
+ }
+
+ @Test
+ public void testEquals_withNonEqualEnd() {
+ final IntRange rangeB = new IntRange(1, 300);
+ Assert.assertNotEquals(range, rangeB);
+ }
+
+ @Test
+ public void testHashCode_withEqualRanges() {
+ final IntRange rangeB = new IntRange(1, 200);
+ Assert.assertEquals(range.hashCode(), rangeB.hashCode());
+ }
+
+ @Test
+ public void testHashCode_withNonEqualRanges() {
+ final IntRange rangeB = new IntRange(6, 200);
+ Assert.assertNotEquals(range.hashCode(), rangeB.hashCode());
+ }
+
@Test
public void testClampValuesToRange() {
- final IntRange range = new IntRange(1, 200);
range.clampValuesToRange(1, 50);
Assert.assertEquals(1, range.getBegin());
Assert.assertEquals(50, range.getEnd());
@@ -42,7 +89,6 @@ public class IntRangeTest {
@Test
public void testClampValuesToRange_withBeginLessThanClampBegin() {
- final IntRange range = new IntRange(1, 200);
range.clampValuesToRange(10, 200);
Assert.assertEquals(10, range.getBegin());
Assert.assertEquals(200, range.getEnd());
@@ -50,7 +96,6 @@ public class IntRangeTest {
@Test
public void testClampValuesToRange_withBeginEqualToClampBegin() {
- final IntRange range = new IntRange(1, 200);
range.clampValuesToRange(1, 200);
Assert.assertEquals(1, range.getBegin());
Assert.assertEquals(200, range.getEnd());
@@ -66,8 +111,7 @@ public class IntRangeTest {
@Test
public void testClampValuesToRange_withBeginEqualToClampEnd() {
- final IntRange range = new IntRange(200, 200);
- range.clampValuesToRange(1, 200);
+ range.clampValuesToRange(200, 200);
Assert.assertEquals(200, range.getBegin());
Assert.assertEquals(200, range.getEnd());
}
