Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scalashop
- import java.util.concurrent._
- import scala.collection._
- import org.scalatest.FunSuite
- import org.junit.runner.RunWith
- import org.scalatest.junit.JUnitRunner
- import common._
- import org.scalatest._
- @RunWith(classOf[JUnitRunner])
- class BlurSuite extends FunSuite {
- test("boxBlurKernel should correctly handle radius 0") {
- val src = new Img(5, 5)
- for (x <- 0 until 5; y <- 0 until 5)
- src(x, y) = rgba(x, y, x + y, math.abs(x - y))
- for (x <- 0 until 5; y <- 0 until 5)
- assert(boxBlurKernel(src, x, y, 0) === rgba(x, y, x + y, math.abs(x - y)),
- "boxBlurKernel(_,_,0) should be identity.")
- }
- test("boxBlurKernel should return the correct value on an interior pixel " +
- "of a 3x4 image with radius 1") {
- val src = new Img(3, 4)
- src(0, 0) = 0; src(1, 0) = 1; src(2, 0) = 2
- src(0, 1) = 3; src(1, 1) = 4; src(2, 1) = 5
- src(0, 2) = 6; src(1, 2) = 7; src(2, 2) = 8
- src(0, 3) = 50; src(1, 3) = 11; src(2, 3) = 16
- assert(boxBlurKernel(src, 1, 2, 1) === 12,
- s"(boxBlurKernel(1, 2, 1) should be 12, " +
- s"but it's ${boxBlurKernel(src, 1, 2, 1)})")
- }
- test("boxBlurKernel should return the correct value on an interior pixel " +
- "of a 3x3 image with radius 1") {
- val src = new Img(3, 4)
- src(0, 0) = 0; src(1, 0) = 1; src(2, 0) = 2
- src(0, 1) = 3; src(1, 1) = 4; src(2, 1) = 5
- src(0, 2) = 6; src(1, 2) = 7; src(2, 2) = 8
- assert(boxBlurKernel(src, 1, 1, 1) === 4,
- s"(boxBlurKernel(1, 1, 1) should be 4, " +
- s"but it's ${boxBlurKernel(src, 1, 1, 1)})")
- }
- test("HorizontalBoxBlur.blur with radius 1 should correctly blur the entire 3x3 image") {
- val w = 3
- val h = 3
- val src = new Img(w, h)
- val dst = new Img(w, h)
- src(0, 0) = 0; src(1, 0) = 1; src(2, 0) = 2
- src(0, 1) = 3; src(1, 1) = 4; src(2, 1) = 5
- src(0, 2) = 6; src(1, 2) = 7; src(2, 2) = 8
- HorizontalBoxBlur.blur(src, dst, 0, 2, 1)
- def check(x: Int, y: Int, expected: Int) =
- assert(dst(x, y) == expected,
- s"(destination($x, $y) should be $expected)")
- check(0, 0, 2)
- check(1, 0, 2)
- check(2, 0, 3)
- check(0, 1, 3)
- check(1, 1, 4)
- check(2, 1, 4)
- check(0, 2, 0)
- check(1, 2, 0)
- check(2, 2, 0)
- }
- test("VerticalBoxBlur.blur with radius 1 and 1 task should correctly blur the entire 3x3 image") {
- val w = 3
- val h = 3
- val src = new Img(w, h)
- val dst = new Img(w, h)
- src(0, 0) = 0; src(1, 0) = 1; src(2, 0) = 2
- src(0, 1) = 3; src(1, 1) = 4; src(2, 1) = 5
- src(0, 2) = 6; src(1, 2) = 7; src(2, 2) = 8
- VerticalBoxBlur.blur(src, dst, 0, 3, 1)
- def checkBox(x: Int, y: Int, expected: Int) =
- assert(dst(x, y) == expected,
- s"(destination($x, $y) should be $expected)")
- checkBox(0, 0, 2)
- checkBox(1, 0, 2)
- checkBox(2, 0, 3)
- checkBox(0, 1, 3)
- checkBox(1, 1, 4)
- checkBox(2, 1, 4)
- checkBox(0, 2, 5)
- checkBox(1, 2, 5)
- checkBox(2, 2, 6)
- }
- test("VerticalBoxBlur.blur with radius 1 should correctly blur all the pixels of the entire 7x2 image") {
- val w = 7
- val h = 2
- val r = 1
- val src = new Img(w, h)
- val dst = new Img(w, h)
- src(0, 0) = 0; src(1, 0) = 1; src(2, 0) = 2; src(3, 0) = 3; src(4, 0) = 4; src(5, 0) = 5; src(6, 0) = 6
- src(0, 1) = 7; src(1, 1) = 8; src(2, 1) = 9; src(3, 1) = 10; src(4, 1) = 11; src(5, 1) = 12; src(6, 1) = 13;
- def checkBox(x: Int, y: Int, expected: Int) =
- assert(scalashop.boxBlurKernel(src, x, y, r) == expected,
- s"(destination($x, $y) should be $expected)")
- checkBox(0, 0, 4)
- checkBox(1, 0, 4)
- checkBox(2, 0, 5)
- checkBox(3, 0, 6)
- checkBox(4, 0, 7)
- checkBox(5, 0, 8)
- checkBox(6, 0, 9)
- checkBox(0, 1, 4)
- checkBox(1, 1, 4)
- checkBox(2, 1, 5)
- checkBox(3, 1, 6)
- checkBox(4, 1, 7)
- checkBox(5, 1, 8)
- checkBox(6, 1, 9)
- }
- test("HorizontalBoxBlur.blur with radius 1 should correctly blur the entire 2x4 image") {
- val w = 2
- val h = 4
- val r = 1
- val src = new Img(w, h)
- val dst = new Img(w, h)
- val from = 0
- src(0, 0) = 0; src(1, 0) = 1; src(0, 1) = 2; src(1, 1) = 3
- src(0, 2) = 4; src(1, 2) = 5; src(0, 3) = 6; src(1, 3) = 7
- HorizontalBoxBlur.blur(src, dst, from, h, r)
- def check(x: Int, y: Int, expected: Int) =
- assert(dst(x, y) == expected,
- s"(destination($x, $y) should be $expected)")
- check(0, 0, 1);
- check(1, 0, 1);
- check(0, 1, 2);
- check(1, 1, 2);
- check(0, 2, 4);
- check(1, 2, 4);
- check(0, 3, 5);
- check(1, 3, 5)
- }
- test("HorinzontalBoxBlur.parBlur with radius 1 and task 1 should correctly blur the entire 3*3 image") {
- val w = 3
- val h = 3
- val r = 1
- val n = 1
- val src = new Img(w, h)
- val dst = new Img(w, h)
- val from = 0
- src(0, 0) = 0; src(1, 0) = 1; src(2, 0) = 2;
- src(0, 1) = 3; src(1, 1) = 4; src(2, 1) = 5;
- src(0, 2) = 6; src(1, 2) = 7; src(2, 2) = 8;
- HorizontalBoxBlur.parBlur(src, dst, n, r)
- def check(x: Int, y: Int, expected: Int) =
- assert(dst(x, y) == expected,
- s"(destination($x, $y) should be $expected)")
- check(0, 0, 2);
- check(1, 0, 2);
- check(0, 1, 3);
- check(0, 1, 3);
- check(0, 2, 5);
- check(1, 2, 5);
- check(0, 2, 5);
- check(1, 2, 5);
- check(2, 2, 6)
- }
- test("VerticalBoxBlur.blur with radius 2 should correctly blur the entire " +
- "4x3 image") {
- val w = 4
- val h = 3
- val src = new Img(w, h)
- val dst = new Img(w, h)
- src(0, 0) = 0; src(1, 0) = 1; src(2, 0) = 2; src(3, 0) = 9
- src(0, 1) = 3; src(1, 1) = 4; src(2, 1) = 5; src(3, 1) = 10
- src(0, 2) = 6; src(1, 2) = 7; src(2, 2) = 8; src(3, 2) = 11
- VerticalBoxBlur.blur(src, dst, 0, 4, 2)
- def check(x: Int, y: Int, expected: Int) =
- assert(dst(x, y) == expected,
- s"(destination($x, $y) should be $expected)")
- check(0, 0, 4)
- check(1, 0, 5)
- check(2, 0, 5)
- check(3, 0, 6)
- check(0, 1, 4)
- check(1, 1, 5)
- check(2, 1, 5)
- check(3, 1, 6)
- check(0, 2, 4)
- check(1, 2, 5)
- check(2, 2, 5)
- check(3, 2, 6)
- }
- test("VerticalBoxBlur.parBlur with radius 1 and tasks 3 should correctly blur the entire " +
- "7x2 image") {
- val w = 7
- val h = 2
- val n = 7
- val r = 1
- val src = new Img(w, h)
- val dst = new Img(w, h)
- src(0, 0) = 0; src(1, 0) = 1; src(2, 0) = 2; src(3, 0) = 3; src(4, 0) = 4; src(5, 0) = 5; src(6, 0) = 6
- src(0, 1) = 7; src(1, 1) = 8; src(2, 1) = 9; src(3, 1) = 10; src(4, 1) = 11; src(5, 1) = 12; src(6, 1) = 13;
- VerticalBoxBlur.parBlur(src, dst, n, r)
- def checkBox(x: Int, y: Int, expected: Int) =
- assert(dst(x, y) == expected,
- s"(destination($x, $y) should be $expected)")
- checkBox(0, 0, 4)
- checkBox(1, 0, 4)
- checkBox(2, 0, 5)
- checkBox(3, 0, 6)
- checkBox(4, 0, 7)
- checkBox(5, 0, 8)
- checkBox(6, 0, 9)
- checkBox(0, 1, 4)
- checkBox(1, 1, 4)
- checkBox(2, 1, 5)
- checkBox(3, 1, 6)
- checkBox(4, 1, 7)
- checkBox(5, 1, 8)
- checkBox(6, 1, 9)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement