Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 1846b38

Browse files
committed
Add Range class
1 parent e32490d commit 1846b38

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

Geometry.iml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id="Geometry" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.kylecorry.geometry" external.system.module.version="0.7" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
7+
<excludeFolder url="file://$MODULE_DIR$/build" />
8+
<excludeFolder url="file://$MODULE_DIR$/out" />
9+
</content>
10+
<orderEntry type="inheritedJdk" />
11+
<orderEntry type="sourceFolder" forTests="false" />
12+
</component>
13+
</module>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.kylecorry.geometry'
2-
version '0.6.1'
2+
version '0.7'
33

44
apply plugin: 'java-library'
55

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.kylecorry.geometry;
2+
3+
public class Range {
4+
5+
private double low;
6+
private double high;
7+
8+
public Range(double low, double high) {
9+
this.low = low;
10+
this.high = high;
11+
}
12+
13+
public double getLow() {
14+
return low;
15+
}
16+
17+
public double getHigh() {
18+
return high;
19+
}
20+
21+
public boolean inRangeInclusive(double value){
22+
return getLow() <= value && getHigh() >= value;
23+
}
24+
25+
public boolean inRangeExclusive(double value){
26+
return getLow() < value && getHigh() > value;
27+
}
28+
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.kylecorry.geometry;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.*;
6+
7+
public class RangeTest {
8+
9+
@Test
10+
public void testRangeInclusive(){
11+
Range r = new Range(0, 100);
12+
assertTrue(r.inRangeInclusive(0));
13+
assertTrue(r.inRangeInclusive(100));
14+
assertTrue(r.inRangeInclusive(50));
15+
assertFalse(r.inRangeInclusive(-1));
16+
assertFalse(r.inRangeInclusive(101));
17+
}
18+
19+
@Test
20+
public void testRangeExclusive(){
21+
Range r = new Range(0, 100);
22+
assertFalse(r.inRangeExclusive(0));
23+
assertFalse(r.inRangeExclusive(100));
24+
assertTrue(r.inRangeExclusive(50));
25+
assertFalse(r.inRangeExclusive(-1));
26+
assertFalse(r.inRangeExclusive(101));
27+
}
28+
29+
}

0 commit comments

Comments
 (0)