Skip to content

Commit 224452c

Browse files
committed
Updated to lib 2.2.2
1 parent 7818fc1 commit 224452c

File tree

4 files changed

+23
-35
lines changed

4 files changed

+23
-35
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ scalacOptions ++= Seq("-feature")
1010
resolvers += Resolver.mavenLocal
1111

1212
libraryDependencies ++= Seq(
13-
"com.mapcode" % "mapcode" % "2.0.2" withSources(),
13+
"com.mapcode" % "mapcode" % "2.2.2" withSources(),
1414
"com.google.code.findbugs" % "jsr305" % "1.3.+",
1515
"org.slf4j" % "slf4j-api" % "1.7.2" % "test",
1616
"org.slf4j" % "slf4j-log4j12" % "1.7.2" % "test",

src/main/scala/com/mapcode/scala/Mapcode.scala

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ object Mapcode {
165165
* check if the mapcode is really a valid mapcode representing a position on Earth.
166166
*
167167
* @param mapcode Mapcode (optionally with a territory).
168-
* @return Type of mapcode code format.
168+
* @return Type of mapcode precision format (0-8).
169169
* @throws UnknownPrecisionFormatException If precision format is incorrect.
170170
*/
171-
def precisionFormat(mapcode: String): PrecisionFormat =
171+
def precisionFormat(mapcode: String): Integer =
172172
JMapcode.getPrecisionFormat(mapcode)
173173

174174
/**
@@ -230,29 +230,5 @@ object Mapcode {
230230

231231
implicit def toJava(mapcode: Mapcode): JMapcode =
232232
mapcode.delegate
233-
234-
/**
235-
* This enum describes the types of available mapcodes (as returned by [[com.mapcode.scala.Mapcode#precisionFormat(String)]].
236-
*/
237-
case class PrecisionFormat(delegate: JMapcode.PrecisionFormat) {
238-
239-
override def toString: String =
240-
delegate.toString
241-
}
242-
243-
object PrecisionFormat {
244-
val PRECISION_0 = PrecisionFormat(JMapcode.PrecisionFormat.PRECISION_0)
245-
val PRECISION_1 = PrecisionFormat(JMapcode.PrecisionFormat.PRECISION_1)
246-
val PRECISION_2 = PrecisionFormat(JMapcode.PrecisionFormat.PRECISION_2)
247-
248-
def values: Seq[PrecisionFormat] =
249-
JMapcode.PrecisionFormat.values.map(PrecisionFormat(_))
250-
251-
implicit def fromJava(format: JMapcode.PrecisionFormat): PrecisionFormat =
252-
PrecisionFormat(format)
253-
254-
implicit def toJava(format: PrecisionFormat): JMapcode.PrecisionFormat =
255-
format.delegate
256-
}
257233
}
258234

src/test/scala/com/mapcode/scala/DecoderTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
*/
1616
package com.mapcode.scala
1717

18-
import com.mapcode.UnknownMapcodeException
18+
import com.mapcode.{UnknownPrecisionFormatException, UnknownMapcodeException}
1919
import org.scalatest.prop.GeneratorDrivenPropertyChecks
2020
import org.scalatest.{FunSuite, Matchers}
2121

2222
class DecoderTest extends FunSuite with Matchers with GeneratorDrivenPropertyChecks {
2323

2424
test("decodeMapcodeWithTerritory") {
2525
val point = MapcodeCodec.decode("49.4V", Territory.NLD)
26-
52.376514 shouldBe point.latDeg
26+
52.376514 shouldBe (point.latDeg +- 0.000001)
2727
4.908542 shouldBe (point.lonDeg +- 0.00001)
2828
}
2929

@@ -58,7 +58,7 @@ class DecoderTest extends FunSuite with Matchers with GeneratorDrivenPropertyChe
5858
}
5959

6060
test("invalidMapcode1") {
61-
an[UnknownMapcodeException] should be thrownBy MapcodeCodec.decode("494.V494V", Territory.NLD)
61+
an[UnknownPrecisionFormatException] should be thrownBy MapcodeCodec.decode("494.V494V", Territory.NLD)
6262
}
6363

6464
test("invalidHighPrecisionCharacter") {

src/test/scala/com/mapcode/scala/MapcodeTest.scala

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@ class MapcodeTest extends FunSuite with Matchers {
2828
Mapcode.isValidMapcodeFormat("AAAA.BBB") shouldBe true
2929
Mapcode.isValidMapcodeFormat("AAAA.BBBB") shouldBe true
3030
Mapcode.isValidMapcodeFormat("AAAAA.BBBB") shouldBe true
31-
Mapcode.isValidMapcodeFormat("AAAAA.BBBBB") shouldBe true
3231
Mapcode.isValidMapcodeFormat("AA.AA-0") shouldBe true
3332
Mapcode.isValidMapcodeFormat("AA.AA-01") shouldBe true
3433
Mapcode.isValidMapcodeFormat("AA.AA-A") shouldBe true
3534
Mapcode.isValidMapcodeFormat("AA.AA-AA") shouldBe true
3635
Mapcode.isValidMapcodeFormat("AA.AA-Y") shouldBe true
3736
Mapcode.isValidMapcodeFormat("AA.AA-1Y") shouldBe true
37+
Mapcode.isValidMapcodeFormat("AA.AA-012") shouldBe true
38+
Mapcode.isValidMapcodeFormat("AA.AA-0123") shouldBe true
39+
Mapcode.isValidMapcodeFormat("AA.AA-01234") shouldBe true
40+
Mapcode.isValidMapcodeFormat("AA.AA-012345") shouldBe true
41+
Mapcode.isValidMapcodeFormat("AA.AA-0123456") shouldBe true
42+
Mapcode.isValidMapcodeFormat("AA.AA-01234567") shouldBe true
3843
}
3944

4045
test("checkInvalidMapcodeFormats") {
46+
Mapcode.isValidMapcodeFormat("AA.AA-012345678") shouldBe false
47+
Mapcode.isValidMapcodeFormat("AA.AA-0123456789") shouldBe false
4148
Mapcode.isValidMapcodeFormat("A") shouldBe false
4249
Mapcode.isValidMapcodeFormat("AB") shouldBe false
4350
Mapcode.isValidMapcodeFormat("AB.") shouldBe false
@@ -56,7 +63,6 @@ class MapcodeTest extends FunSuite with Matchers {
5663
Mapcode.isValidMapcodeFormat("00.01-") shouldBe false
5764
Mapcode.isValidMapcodeFormat("AAAAAA.BBBBB") shouldBe false
5865
Mapcode.isValidMapcodeFormat("AAAAA.BBBBBB") shouldBe false
59-
Mapcode.isValidMapcodeFormat("AA.AA-012") shouldBe false
6066
Mapcode.isValidMapcodeFormat("AA.AA-Z") shouldBe false
6167
Mapcode.isValidMapcodeFormat("AA.AA-1Z") shouldBe false
6268
Mapcode.isValidMapcodeFormat("A.AAA") shouldBe false
@@ -69,9 +75,15 @@ class MapcodeTest extends FunSuite with Matchers {
6975

7076
test("checkMapcodeFormatType") {
7177

72-
Mapcode.precisionFormat("AA.BB") should be(Mapcode.PrecisionFormat.PRECISION_0)
73-
Mapcode.precisionFormat("AA.BB-1") should be(Mapcode.PrecisionFormat.PRECISION_1)
74-
Mapcode.precisionFormat("AA.BB-12") should be(Mapcode.PrecisionFormat.PRECISION_2)
78+
Mapcode.precisionFormat("AA.BB") should be(0)
79+
Mapcode.precisionFormat("AA.BB-1") should be(1)
80+
Mapcode.precisionFormat("AA.BB-12") should be(2)
81+
Mapcode.precisionFormat("AA.BB-123") should be(3)
82+
Mapcode.precisionFormat("AA.BB-1234") should be(4)
83+
Mapcode.precisionFormat("AA.BB-12345") should be(5)
84+
Mapcode.precisionFormat("AA.BB-123456") should be(6)
85+
Mapcode.precisionFormat("AA.BB-1234567") should be(7)
86+
Mapcode.precisionFormat("AA.BB-12345678") should be(8)
7587
}
7688

7789
test("invalid map code") {

0 commit comments

Comments
 (0)