From e70fd64e45b75495610cbc0c231d0c82283c2042 Mon Sep 17 00:00:00 2001
From: arnaudlabourel <arnaud.labourel@univ-amu.fr>
Date: Fri, 17 Sep 2021 11:36:40 +0200
Subject: [PATCH] Ajout tests

---
 src/test/java/ByteGrayColorTest.java   | 22 ++++++++++++++++++++++
 src/test/java/MatrixGrayImageTest.java | 16 +++++++++-------
 2 files changed, 31 insertions(+), 7 deletions(-)
 create mode 100644 src/test/java/ByteGrayColorTest.java

diff --git a/src/test/java/ByteGrayColorTest.java b/src/test/java/ByteGrayColorTest.java
new file mode 100644
index 0000000..37039a5
--- /dev/null
+++ b/src/test/java/ByteGrayColorTest.java
@@ -0,0 +1,22 @@
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+
+public class ByteGrayColorTest {
+  @Test
+  public void testGetLuminosity_whenColorCreatedWithGrayLevel(){
+    ByteGrayColor black = new ByteGrayColor(0);
+    ByteGrayColor white = new ByteGrayColor(255);
+    assertThat(black.getLuminosity(), is(closeTo(0.,.0001)));
+    assertThat(white.getLuminosity(), is(closeTo(1.,.0001)));
+  }
+
+  @Test
+  public void testGetLuminosity_whenColorCreatedWithLuminosity(){
+    ByteGrayColor color1 = new ByteGrayColor(.25);
+    ByteGrayColor color2 = new ByteGrayColor(.75);
+    assertThat(color1.getLuminosity(), is(closeTo(.25,.0001)));
+    assertThat(color2.getLuminosity(), is(closeTo(.75,.0001)));
+  }
+}
diff --git a/src/test/java/MatrixGrayImageTest.java b/src/test/java/MatrixGrayImageTest.java
index f44a461..0aaa7f8 100644
--- a/src/test/java/MatrixGrayImageTest.java
+++ b/src/test/java/MatrixGrayImageTest.java
@@ -1,20 +1,22 @@
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+
 
 class MatrixGrayImageTest {
 
     @Test
     void getWidth() {
-        assertEquals(0, new MatrixGrayImage(0,0).getWidth());
-        assertEquals(10, new MatrixGrayImage(10,20).getWidth());
-        assertEquals(400, new MatrixGrayImage(400,300).getWidth());
+        assertThat(new MatrixGrayImage(0,0).getWidth(), is(equalTo(0)));
+        assertThat(new MatrixGrayImage(10,20).getWidth(), is(equalTo(10)));
+        assertThat(new MatrixGrayImage(400,300).getWidth(), is(equalTo(400)));
     }
 
     @Test
     void getHeight() {
-        assertEquals(0, new MatrixGrayImage(0,0).getHeight());
-        assertEquals(20, new MatrixGrayImage(10,20).getHeight());
-        assertEquals(300, new MatrixGrayImage(400,300).getHeight());
+        assertThat(new MatrixGrayImage(0,0).getWidth(), is(equalTo(0)));
+        assertThat(new MatrixGrayImage(10,20).getWidth(), is(equalTo(20)));
+        assertThat(new MatrixGrayImage(400,300).getWidth(), is(equalTo(300)));
     }
 }
\ No newline at end of file
-- 
GitLab