-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James McClain
committed
Mar 28, 2016
1 parent
0ea2a4c
commit 2b3c42c
Showing
2 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
raster-test/src/test/scala/geotrellis/raster/OrderedMultibandTileSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright (c) 2016 Azavea. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package geotrellis.raster | ||
|
||
import org.scalatest._ | ||
|
||
|
||
class OrderedMultibandTileSpec | ||
extends FunSpec | ||
with Matchers { | ||
|
||
val first = ArrayMultibandTile(IntArrayTile.fill(1, 10, 10), IntArrayTile.fill(2, 10, 10)) | ||
val second = ArrayMultibandTile(IntArrayTile.fill(3, 10, 10), IntArrayTile.fill(4, 10, 10)) | ||
|
||
describe("The OrderedMultibandTile constructor") { | ||
it("should throw when the tile and order are not of the same size") { | ||
intercept[IllegalArgumentException] { | ||
OrderedMultibandTile(first, IntArrayTile.empty(11, 11)) | ||
} | ||
} | ||
} | ||
|
||
describe("The merge method") { | ||
it("should takes values from higher-priority multi-pixels") { | ||
val ot1 = OrderedMultibandTile(first, IntArrayTile.fill(3, 10, 10)) | ||
val ot2 = OrderedMultibandTile(second, IntArrayTile.fill(7, 10, 10)) | ||
val ot3 = ot1.merge(ot2) | ||
val ot4 = ot2.merge(ot1) | ||
|
||
var onesAndTwosCount = 0 | ||
var threesAndFoursCount = 0 | ||
|
||
ot3.foreach({ (band: Int, z: Int) => | ||
if (z == 1 || z == 2) onesAndTwosCount += 1 // from ot1 | ||
else if (z == 3 || z == 4) threesAndFoursCount += 1 // from ot2 | ||
}) | ||
onesAndTwosCount should be (0) // from ot1 | ||
threesAndFoursCount should be (200) // from ot2 | ||
|
||
onesAndTwosCount = 0; threesAndFoursCount = 0 | ||
ot4.foreach({ (band: Int, z: Int) => | ||
if (z == 1 || z == 2) onesAndTwosCount += 1 // from ot1 | ||
else if (z == 3 || z == 4) threesAndFoursCount += 1 // from ot2 | ||
}) | ||
onesAndTwosCount should be (0) // from ot1 | ||
threesAndFoursCount should be (200) // from ot2 | ||
} | ||
|
||
it("should give NODATA pixels minimum priority") { | ||
val ot1 = OrderedMultibandTile(first, IntArrayTile.fill(3, 10, 10)) | ||
val ar = IntArrayTile.fill(3, 10, 10) | ||
val ot2 = OrderedMultibandTile(MultibandTile(ar, IntArrayTile.fill(4, 10, 10)), IntArrayTile.fill(7, 10, 10)) | ||
|
||
// Poke a hole in the higher priority OrderedMultibandTile, ot2 | ||
ar.set(5, 5, NODATA) | ||
|
||
val ot3 = ot1.merge(ot2) | ||
|
||
var onesAndTwosCount = 0 | ||
var threesAndFoursCount = 0 | ||
|
||
ot3.foreach({ (band: Int, z: Int) => | ||
if (z == 1 || z == 2) onesAndTwosCount += 1 // from ot1 | ||
else if (z == 3 || z == 4) threesAndFoursCount += 1 //from ot2 | ||
}) | ||
onesAndTwosCount should be (1) // from ot1 | ||
threesAndFoursCount should be (199) // from ot2 | ||
} | ||
|
||
it("should have as many bands as the least of its inputs") { | ||
val ot1 = OrderedMultibandTile(first, IntArrayTile.empty(10, 10)) // two bands | ||
val ot2 = OrderedMultibandTile( // seven bands | ||
MultibandTile( | ||
IntArrayTile.empty(10, 10), | ||
IntArrayTile.empty(10, 10), | ||
IntArrayTile.empty(10, 10), | ||
IntArrayTile.empty(10, 10), | ||
IntArrayTile.empty(10, 10), | ||
IntArrayTile.empty(10, 10), | ||
IntArrayTile.empty(10, 10) | ||
), IntArrayTile.empty(10, 10)) | ||
val ot3 = ot1.merge(ot2) | ||
val ot4 = ot2.merge(ot1) | ||
|
||
ot3.bandCount should be (2) | ||
ot4.bandCount should be (2) | ||
} | ||
|
||
it("should throw when sizes do not match") { | ||
val ot1 = OrderedMultibandTile(first, IntArrayTile.empty(10, 10)) | ||
val ot2 = OrderedMultibandTile(MultibandTile(IntArrayTile.empty(11, 11), IntArrayTile.empty(11, 11)), IntArrayTile.empty(11, 11)) | ||
intercept[IllegalArgumentException] { | ||
ot1.merge(ot2) | ||
} | ||
} | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
raster-test/src/test/scala/geotrellis/raster/OrderedTileSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2016 Azavea. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package geotrellis.raster | ||
|
||
import org.scalatest._ | ||
|
||
|
||
class OrderedTileSpec | ||
extends FunSpec | ||
with Matchers { | ||
|
||
val ones = IntArrayTile.fill(1, 10, 10) | ||
val twos = IntArrayTile.fill(2, 10, 10) | ||
|
||
describe("The OrderedTile constructor") { | ||
it("should throw when the tile and order are not of the same size") { | ||
intercept[IllegalArgumentException] { | ||
OrderedTile(IntArrayTile.empty(10, 10), IntArrayTile.empty(11, 11)) | ||
} | ||
} | ||
} | ||
|
||
describe("The merge method") { | ||
it("should takes values from higher-priority pixels") { | ||
val ot1 = OrderedTile(ones, IntArrayTile.fill(3, 10, 10)) | ||
val ot2 = OrderedTile(twos, IntArrayTile.fill(7, 10, 10)) | ||
val ot3 = ot1.merge(ot2) | ||
val ot4 = ot2.merge(ot1) | ||
|
||
var onesCount = 0 | ||
var twosCount = 0 | ||
|
||
ot3.foreach({ z: Int => | ||
if (z == 1) onesCount += 1 // from ot1 | ||
else if (z == 2) twosCount += 1 // from ot2 | ||
}) | ||
onesCount should be (0) // from ot1 | ||
twosCount should be (100) // from ot2 | ||
|
||
onesCount = 0; twosCount = 0 | ||
ot4.foreach({ z: Int => | ||
if (z == 1) onesCount += 1 // from ot1 | ||
else if (z == 2) twosCount += 1 // from ot2 | ||
}) | ||
onesCount should be (0) // from ot1 | ||
twosCount should be (100) // from ot2 | ||
} | ||
|
||
it("should give NODATA pixels minimum priority") { | ||
val ot1 = OrderedTile(ones, IntArrayTile.fill(3, 10, 10)) | ||
val ar = IntArrayTile.fill(2, 10, 10) | ||
val ot2 = OrderedTile(ar, IntArrayTile.fill(7, 10, 10)) | ||
|
||
// Poke a hole in the higher priority OrderedTile, ot2 | ||
ar.set(5, 5, NODATA) | ||
|
||
val ot3 = ot1.merge(ot2) | ||
|
||
var onesCount = 0 | ||
var twosCount = 0 | ||
|
||
ot3.foreach({ z: Int => | ||
if (z == 1) onesCount += 1 // from ot1 | ||
else if (z == 2) twosCount += 1 // from ot2 | ||
}) | ||
onesCount should be (1) // from ot1 | ||
twosCount should be (99) // from ot2 | ||
} | ||
|
||
it("should throw when sizes do not match") { | ||
val ot1 = OrderedTile(ones, IntArrayTile.empty(10, 10)) | ||
val ot2 = OrderedTile(IntArrayTile.empty(11, 11), IntArrayTile.empty(11, 11)) | ||
intercept[IllegalArgumentException] { | ||
ot1.merge(ot2) | ||
} | ||
} | ||
} | ||
} |