Code Kata Report
diff -r b07211baf7fd -r b35927a3130a src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 20:50:57 2012 -0600 @@ -0,0 +1,15 @@ +package com.nicholas.tuck.katas.range; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +public class RangeTest { + + @Test + public void singleValueRangeContainsSameInteger() throws Exception { + Range range = new Range(3,3); + assertThat(range.contains(3), is(true)); + } +} diff -r b07211baf7fd -r b35927a3130a src/main/java/com/nicholas/tuck/katas/range/Range.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 20:50:57 2012 -0600 @@ -0,0 +1,12 @@ +package com.nicholas.tuck.katas.range; + +public class Range { + + public Range(int initial, int end) { + + } + + public boolean contains(int valueToCheck) { + return true; + } +} ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r b35927a3130a -r 8405ac223966 src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 20:50:57 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 20:54:23 2012 -0600 @@ -6,10 +6,16 @@ import static org.hamcrest.Matchers.*; public class RangeTest { @Test - public void singleValueRangeContainsSameInteger() throws Exception { + public void singleValueRangeContainsSameInteger() { Range range = new Range(3,3); assertThat(range.contains(3), is(true)); } + + @Test + public void singleValueRangeShouldNotContainDifferentInt() { + Range range = new Range(3,3); + assertThat(range.contains(4), is(false)); + } } diff -r b35927a3130a -r 8405ac223966 src/main/java/com/nicholas/tuck/katas/range/Range.java --- a/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 20:50:57 2012 -0600 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 20:54:23 2012 -0600 @@ -1,12 +1,20 @@ package com.nicholas.tuck.katas.range; public class Range { + private int inital; + private int end; + public Range(int initial, int end) { - + this.inital = initial; + this.end = end; } public boolean contains(int valueToCheck) { - return true; + if (valueToCheck == inital) { + return true; + } + + return false; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 8405ac223966 -r 810835d1134a src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 20:54:23 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 20:56:28 2012 -0600 @@ -6,16 +6,22 @@ import static org.hamcrest.Matchers.*; public class RangeTest { @Test - public void singleValueRangeContainsSameInteger() { + public void singleValueRangeShouldContainSameInteger() { Range range = new Range(3,3); assertThat(range.contains(3), is(true)); } @Test public void singleValueRangeShouldNotContainDifferentInt() { Range range = new Range(3,3); assertThat(range.contains(4), is(false)); } + + @Test + public void twoValueRangeShouldContainSecondInt() { + Range range = new Range(3,4); + assertThat(range.contains(4), is(true)); + } } diff -r 8405ac223966 -r 810835d1134a src/main/java/com/nicholas/tuck/katas/range/Range.java --- a/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 20:54:23 2012 -0600 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 20:56:28 2012 -0600 @@ -1,20 +1,20 @@ package com.nicholas.tuck.katas.range; public class Range { private int inital; private int end; public Range(int initial, int end) { this.inital = initial; this.end = end; } public boolean contains(int valueToCheck) { - if (valueToCheck == inital) { + if (valueToCheck == inital || valueToCheck == end) { return true; } return false; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 810835d1134a -r c89ec5e9c26c src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 20:56:28 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 20:58:51 2012 -0600 @@ -22,6 +22,18 @@ @Test public void twoValueRangeShouldContainSecondInt() { Range range = new Range(3,4); assertThat(range.contains(4), is(true)); } + + @Test + public void twoValueRangeShouldNotContainValueOutsideOfRange() { + Range range = new Range(3,4); + assertThat(range.contains(1), is(false)); + } + + @Test + public void rangeShouldContainValueWithinIt() { + Range range = new Range(-3,7); + assertThat(range.contains(4), is(true)); + } } diff -r 810835d1134a -r c89ec5e9c26c src/main/java/com/nicholas/tuck/katas/range/Range.java --- a/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 20:56:28 2012 -0600 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 20:58:51 2012 -0600 @@ -1,20 +1,20 @@ package com.nicholas.tuck.katas.range; public class Range { private int inital; private int end; public Range(int initial, int end) { this.inital = initial; this.end = end; } public boolean contains(int valueToCheck) { - if (valueToCheck == inital || valueToCheck == end) { + if (valueToCheck >= inital && valueToCheck <= end) { return true; } return false; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r c89ec5e9c26c -r 78d2708a6911 src/main/java/com/nicholas/tuck/katas/range/Range.java --- a/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 20:58:51 2012 -0600 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 20:59:30 2012 -0600 @@ -1,20 +1,16 @@ package com.nicholas.tuck.katas.range; public class Range { private int inital; private int end; public Range(int initial, int end) { this.inital = initial; this.end = end; } public boolean contains(int valueToCheck) { - if (valueToCheck >= inital && valueToCheck <= end) { - return true; - } - - return false; + return valueToCheck >= inital && valueToCheck <= end; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 78d2708a6911 -r 13edbb7ebc12 src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 20:59:30 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:05:47 2012 -0600 @@ -34,6 +34,14 @@ @Test public void rangeShouldContainValueWithinIt() { Range range = new Range(-3,7); assertThat(range.contains(4), is(true)); } + + @Test + public void singleRangeShouldIntersectWithSelfExactly() { + Range initialRange = new Range(5,5); + Range secondRange = initialRange; + Range expectedIntersection = new Range(5,5); + assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); + } } diff -r 78d2708a6911 -r 13edbb7ebc12 src/main/java/com/nicholas/tuck/katas/range/Range.java --- a/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 20:59:30 2012 -0600 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 21:05:47 2012 -0600 @@ -1,16 +1,27 @@ package com.nicholas.tuck.katas.range; + +import org.apache.commons.lang.builder.EqualsBuilder; public class Range { private int inital; private int end; public Range(int initial, int end) { this.inital = initial; this.end = end; } public boolean contains(int valueToCheck) { return valueToCheck >= inital && valueToCheck <= end; } + + public Range intersection(Range secondRange) { + return this; + } + + @Override + public boolean equals(Object otherRange) { + return EqualsBuilder.reflectionEquals(this, otherRange); + } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 13edbb7ebc12 -r f4d2143c6466 src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:05:47 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:11:59 2012 -0600 @@ -41,7 +41,15 @@ public void singleRangeShouldIntersectWithSelfExactly() { Range initialRange = new Range(5,5); Range secondRange = initialRange; Range expectedIntersection = new Range(5,5); assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); + } + + @Test + public void twoValueRangeShouldIntersectWithSingleValueRangeCorrectly() { + Range initialRange = new Range(4,5); + Range secondRange = new Range(5,5); + Range expectedIntersection = secondRange; + assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); } } diff -r 13edbb7ebc12 -r f4d2143c6466 src/main/java/com/nicholas/tuck/katas/range/Range.java --- a/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 21:05:47 2012 -0600 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 21:11:59 2012 -0600 @@ -1,27 +1,35 @@ package com.nicholas.tuck.katas.range; import org.apache.commons.lang.builder.EqualsBuilder; public class Range { - private int inital; + private int initial; private int end; public Range(int initial, int end) { - this.inital = initial; + this.initial = initial; this.end = end; } public boolean contains(int valueToCheck) { - return valueToCheck >= inital && valueToCheck <= end; + return valueToCheck >= this.initial && valueToCheck <= end; } public Range intersection(Range secondRange) { - return this; + if (this.initial == secondRange.getInitial()) { + return this; + } else { + return secondRange; + } } @Override public boolean equals(Object otherRange) { return EqualsBuilder.reflectionEquals(this, otherRange); } + + public int getInitial() { + return initial; + } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r f4d2143c6466 -r 90d7e485159a src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:11:59 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:38:44 2012 -0600 @@ -50,6 +50,14 @@ Range initialRange = new Range(4,5); Range secondRange = new Range(5,5); Range expectedIntersection = secondRange; assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); } + + @Test + public void twoValueRangeShouldIntersectWith1ValueOverlapTwoValueRangeCorrectly() { + Range initialRange = new Range(4,5); + Range secondRange = new Range(5,6); + Range expectedIntersection = new Range(5,5); + assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); + } } diff -r f4d2143c6466 -r 90d7e485159a src/main/java/com/nicholas/tuck/katas/range/Range.java --- a/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 21:11:59 2012 -0600 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 21:38:44 2012 -0600 @@ -1,35 +1,44 @@ package com.nicholas.tuck.katas.range; import org.apache.commons.lang.builder.EqualsBuilder; public class Range { private int initial; private int end; public Range(int initial, int end) { this.initial = initial; this.end = end; } public boolean contains(int valueToCheck) { return valueToCheck >= this.initial && valueToCheck <= end; } public Range intersection(Range secondRange) { if (this.initial == secondRange.getInitial()) { return this; - } else { + } else if (this.end == secondRange.getEnd()) { return secondRange; + } else if (this.initial == secondRange.getEnd()) { + return new Range(initial, initial); + } else if (this.end == secondRange.getInitial()) { + return new Range(end, end); } + return null; + } + + public int getInitial() { + return initial; + } + + public int getEnd() { + return end; } @Override public boolean equals(Object otherRange) { return EqualsBuilder.reflectionEquals(this, otherRange); } - - public int getInitial() { - return initial; - } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 90d7e485159a -r fc345c4bb120 src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:38:44 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:43:59 2012 -0600 @@ -58,6 +58,14 @@ Range initialRange = new Range(4,5); Range secondRange = new Range(5,6); Range expectedIntersection = new Range(5,5); assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); } + + @Test + public void twoValueRangeShouldIntersectWith2ValueOverlap3ValueRangeCorrectly() { + Range initialRange = new Range(4,6); + Range secondRange = new Range(4,5); + Range expectedIntersection = new Range(4,5); + assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); + } } diff -r 90d7e485159a -r fc345c4bb120 src/main/java/com/nicholas/tuck/katas/range/Range.java --- a/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 21:38:44 2012 -0600 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 21:43:59 2012 -0600 @@ -1,44 +1,44 @@ package com.nicholas.tuck.katas.range; import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; public class Range { private int initial; private int end; public Range(int initial, int end) { this.initial = initial; this.end = end; } public boolean contains(int valueToCheck) { return valueToCheck >= this.initial && valueToCheck <= end; } public Range intersection(Range secondRange) { - if (this.initial == secondRange.getInitial()) { - return this; - } else if (this.end == secondRange.getEnd()) { - return secondRange; - } else if (this.initial == secondRange.getEnd()) { - return new Range(initial, initial); - } else if (this.end == secondRange.getInitial()) { - return new Range(end, end); - } - return null; + int newInitial = Math.max(this.initial, secondRange.getInitial()); + int newEnd = Math.min(this.end, secondRange.getEnd()); + + return new Range(newInitial, newEnd); } public int getInitial() { return initial; } public int getEnd() { return end; } @Override public boolean equals(Object otherRange) { return EqualsBuilder.reflectionEquals(this, otherRange); } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r fc345c4bb120 -r 8e1e8ab51069 src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:43:59 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:47:07 2012 -0600 @@ -66,6 +66,22 @@ Range initialRange = new Range(4,6); Range secondRange = new Range(4,5); Range expectedIntersection = new Range(4,5); assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); } + + @Test + public void oneRangeEncompassingAnotherShouldIntersectTheSmaller() { + Range initialRange = new Range(4,12); + Range secondRange = new Range(7,9); + Range expectedIntersection = new Range(7,9); + assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); + } + + @Test + public void bigRangeOverlappingAnotherBigRangeShouldIntersectCorrectly() { + Range initialRange = new Range(-50, 73); + Range secondRange = new Range(27, 1040); + Range expectedIntersection = new Range(27,73); + assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); + } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 8e1e8ab51069 -r 9b8596eb1f8d src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:47:07 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:59:45 2012 -0600 @@ -82,6 +82,14 @@ Range initialRange = new Range(-50, 73); Range secondRange = new Range(27, 1040); Range expectedIntersection = new Range(27,73); assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); } + + @Test + public void rangesThatDontIntersectShouldReturnNoIntersectRange() { + Range initialRange = new Range(7, 9); + Range secondRange = new Range(15, 20); + Range expectedIntersection = Range.NO_INTERSECTION_RANGE; + assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); + } } diff -r 8e1e8ab51069 -r 9b8596eb1f8d src/main/java/com/nicholas/tuck/katas/range/Range.java --- a/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 21:47:07 2012 -0600 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 21:59:45 2012 -0600 @@ -1,44 +1,85 @@ package com.nicholas.tuck.katas.range; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.ToStringBuilder; public class Range { private int initial; private int end; + public static final Range NO_INTERSECTION_RANGE = new NO_INTERSECTION(); + public Range(int initial, int end) { this.initial = initial; this.end = end; } public boolean contains(int valueToCheck) { return valueToCheck >= this.initial && valueToCheck <= end; } public Range intersection(Range secondRange) { int newInitial = Math.max(this.initial, secondRange.getInitial()); int newEnd = Math.min(this.end, secondRange.getEnd()); - + + if (newInitial > this.end || newInitial > secondRange.getEnd() + || newEnd < this.initial || newEnd < secondRange.getInitial()){ + return NO_INTERSECTION_RANGE; + } + return new Range(newInitial, newEnd); } public int getInitial() { return initial; } public int getEnd() { return end; } @Override public boolean equals(Object otherRange) { return EqualsBuilder.reflectionEquals(this, otherRange); } @Override public String toString() { return ToStringBuilder.reflectionToString(this); } + + private static class NO_INTERSECTION extends Range { + + public static final String UNSUPPORTED_MESSAGE = "Can't call on NO_INTERSECTION"; + + public NO_INTERSECTION(int initial, int end) { + super(initial, end); + } + + public NO_INTERSECTION() { + this(0,0); + } + + @Override + public boolean contains(int valueToCheck) { + throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE); + } + + @Override + public Range intersection(Range secondRange) { + throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE); + } + + @Override + public int getInitial() { + throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE); + } + + @Override + public int getEnd() { + throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE); + } + + } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 9b8596eb1f8d -r 86d9c220d73e src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 21:59:45 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 22:14:09 2012 -0600 @@ -90,6 +90,14 @@ Range initialRange = new Range(7, 9); Range secondRange = new Range(15, 20); Range expectedIntersection = Range.NO_INTERSECTION_RANGE; assertThat(initialRange.intersection(secondRange), is(equalTo(expectedIntersection))); } + + @Test + public void rangesThatDontIntersectShouldNotEqual00Range() { + Range initialRange = new Range(7, 9); + Range secondRange = new Range(15, 20); + Range unexpectedIntersection = new Range(0,0); + assertThat(initialRange.intersection(secondRange), is(not(equalTo(unexpectedIntersection)))); + } } diff -r 9b8596eb1f8d -r 86d9c220d73e src/main/java/com/nicholas/tuck/katas/range/Range.java --- a/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 21:59:45 2012 -0600 +++ b/src/main/java/com/nicholas/tuck/katas/range/Range.java Sat Dec 01 22:14:09 2012 -0600 @@ -1,85 +1,92 @@ package com.nicholas.tuck.katas.range; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.ToStringBuilder; public class Range { private int initial; private int end; public static final Range NO_INTERSECTION_RANGE = new NO_INTERSECTION(); public Range(int initial, int end) { this.initial = initial; this.end = end; } public boolean contains(int valueToCheck) { return valueToCheck >= this.initial && valueToCheck <= end; } public Range intersection(Range secondRange) { int newInitial = Math.max(this.initial, secondRange.getInitial()); int newEnd = Math.min(this.end, secondRange.getEnd()); if (newInitial > this.end || newInitial > secondRange.getEnd() || newEnd < this.initial || newEnd < secondRange.getInitial()){ return NO_INTERSECTION_RANGE; } return new Range(newInitial, newEnd); } public int getInitial() { return initial; } public int getEnd() { return end; } @Override public boolean equals(Object otherRange) { + if (otherRange == NO_INTERSECTION_RANGE) { + return false; + } return EqualsBuilder.reflectionEquals(this, otherRange); } @Override public String toString() { return ToStringBuilder.reflectionToString(this); } private static class NO_INTERSECTION extends Range { public static final String UNSUPPORTED_MESSAGE = "Can't call on NO_INTERSECTION"; public NO_INTERSECTION(int initial, int end) { super(initial, end); } public NO_INTERSECTION() { this(0,0); } @Override public boolean contains(int valueToCheck) { throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE); } @Override public Range intersection(Range secondRange) { throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE); } @Override public int getInitial() { throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE); } @Override public int getEnd() { throw new UnsupportedOperationException(UNSUPPORTED_MESSAGE); } + @Override + public boolean equals(Object otherRange) { + return EqualsBuilder.reflectionEquals(this, otherRange); + } } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 86d9c220d73e -r ae28bd06410d src/test/java/com/nicholas/tuck/katas/range/RangeTest.java --- a/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 22:14:09 2012 -0600 +++ b/src/test/java/com/nicholas/tuck/katas/range/RangeTest.java Sat Dec 01 22:22:05 2012 -0600 @@ -1,7 +1,8 @@ package com.nicholas.tuck.katas.range; +import org.junit.Assert; import org.junit.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; @@ -98,6 +99,33 @@ Range initialRange = new Range(7, 9); Range secondRange = new Range(15, 20); Range unexpectedIntersection = new Range(0,0); assertThat(initialRange.intersection(secondRange), is(not(equalTo(unexpectedIntersection)))); } + + @Test + public void noIntersectRangeShouldThrowExceptionOnMethodCalls() { + boolean hasThrown = false; + try { Range.NO_INTERSECTION_RANGE.getEnd(); } catch (Exception e){ + hasThrown = true; + } + if (!hasThrown) Assert.fail("Didn't throw on getEnd"); + + hasThrown = false; + try { Range.NO_INTERSECTION_RANGE.getInitial(); } catch (Exception e){ + hasThrown = true; + } + if (!hasThrown) Assert.fail("Didn't throw on getInitial"); + + hasThrown = false; + try { Range.NO_INTERSECTION_RANGE.contains(-1); } catch (Exception e){ + hasThrown = true; + } + if (!hasThrown) Assert.fail("Didn't throw on contains"); + + hasThrown = false; + try { Range.NO_INTERSECTION_RANGE.intersection(Range.NO_INTERSECTION_RANGE); } catch (Exception e){ + hasThrown = true; + } + if (!hasThrown) Assert.fail("Didn't throw on intersection"); + } }