update tesing file
authorgit <wangtsaichang@gmail.com>
Wed, 28 Jun 2017 23:44:51 +0000 (01:44 +0200)
committergit <wangtsaichang@gmail.com>
Wed, 28 Jun 2017 23:44:51 +0000 (01:44 +0200)
Conversion_CYC/TestColor.java [new file with mode: 0644]

diff --git a/Conversion_CYC/TestColor.java b/Conversion_CYC/TestColor.java
new file mode 100644 (file)
index 0000000..8a6e7d0
--- /dev/null
@@ -0,0 +1,69 @@
+import static org.junit.Assert.*;
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * 
+ */
+
+/**
+ * @author chingyichang
+ *
+ */
+public class TestColor {
+
+       BufferedImage  input_image;
+       BufferedImage  output_image;
+       BufferedImage  image;
+       int width;
+       int height;
+       
+       @Before
+       public void setUp() throws Exception {
+               LoadFile file = new LoadFile();
+               input_image     = file.Load_File("test.jpg");
+       
+               BlackandWhite bw_image = new BlackandWhite();
+       output_image = bw_image.Black_and_White(input_image);
+       }
+
+       /**
+        * @throws java.lang.Exception
+        */
+       @After
+       public void tearDown() throws Exception {
+       }
+
+       @Test
+       public void testBlackandWhite() {
+               
+               try {
+        
+                width = output_image.getWidth();
+                height = output_image.getHeight();
+                
+                for(int i=0; i<height; i++){
+                
+                   for(int j=0; j<width; j++){
+                   
+                      Color c = new Color(output_image.getRGB(j, i));
+                      
+                      int red = (int)c.getRed();
+                      int green = (int)c.getGreen();
+                      int blue = (int)c.getBlue();
+                      int average = (red+green+blue) / 3;
+                  
+                      assertTrue(average==0||average==255);
+                  
+                   }
+                }  
+             } catch (Exception e) {}
+               
+       }
+
+}