modify Test code
authorHsuan-Hao <perng781202@gmail.com>
Thu, 29 Jun 2017 10:36:20 +0000 (12:36 +0200)
committerHsuan-Hao <perng781202@gmail.com>
Thu, 29 Jun 2017 10:36:20 +0000 (12:36 +0200)
finalproject_Hao/TestColor.java

index 23c085f..7276646 100644 (file)
@@ -19,6 +19,7 @@ public class TestColor {
 \r
        BufferedImage  input_image;\r
        BufferedImage  output_image;\r
+       BufferedImage  output_image_gray;\r
        BufferedImage  image;\r
        int width;\r
        int height;\r
@@ -27,9 +28,7 @@ public class TestColor {
        public void setUp() throws Exception {\r
                LoadFile file = new LoadFile();\r
                input_image     = file.Load_File("test.jpg");\r
-       \r
-               BlackandWhite bw_image = new BlackandWhite();\r
-       output_image = bw_image.Black_and_White(input_image);\r
+\r
        }\r
 \r
        /**\r
@@ -41,7 +40,9 @@ public class TestColor {
 \r
        @Test\r
        public void testBlackandWhite() {\r
-               \r
+               BlackandWhite bw_image = new BlackandWhite();\r
+       output_image = bw_image.Black_and_White(input_image);\r
+       \r
                try {\r
         \r
                 width = output_image.getWidth();\r
@@ -65,5 +66,30 @@ public class TestColor {
              } catch (Exception e) {}\r
                \r
        }\r
-\r
+       @Test\r
+       public void testGray() {\r
+               GrayScale g_image = new GrayScale();\r
+       output_image_gray = g_image.Gray_Scale(input_image);\r
+               try {\r
+        \r
+                width = output_image_gray.getWidth();\r
+                height = output_image_gray.getHeight();\r
+                \r
+                for(int i=0; i<height; i++){\r
+                \r
+                   for(int j=0; j<width; j++){\r
+                   \r
+                      Color c = new Color(output_image_gray.getRGB(j, i));\r
+                      \r
+                      int red = (int)c.getRed();\r
+                      int green = (int)c.getGreen();\r
+                      int blue = (int)c.getBlue();\r
+                    \r
+                      assertTrue((red==green)&&(red==blue));\r
+                  \r
+                   }\r
+                }  \r
+             } catch (Exception e) {}\r
+               \r
+       }\r
 }\r