Skip to content
Snippets Groups Projects
Commit d921c4fb authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Ajouts tests supplémentaires

parent ba0648b8
No related branches found
No related tags found
No related merge requests found
...@@ -10,8 +10,15 @@ public class ByteGrayColor implements GrayColor { ...@@ -10,8 +10,15 @@ public class ByteGrayColor implements GrayColor {
private static final int MAXIMUM_GRAY_LEVEL = 255; private static final int MAXIMUM_GRAY_LEVEL = 255;
private static final int OPACITY = 1; private static final int OPACITY = 1;
// TODO : rajouter constantes publique BLACK et WHITE
private final int grayLevel; private final int grayLevel;
public ByteGrayColor(){
this.grayLevel = MINIMUM_GRAY_LEVEL;
}
public ByteGrayColor(int grayLevel) { public ByteGrayColor(int grayLevel) {
// TODO : Corriger l'initialisation de la propriété grayLevel de l'instance. // TODO : Corriger l'initialisation de la propriété grayLevel de l'instance.
this.grayLevel = 0; this.grayLevel = 0;
......
...@@ -18,4 +18,37 @@ public class ByteGrayColorTest { ...@@ -18,4 +18,37 @@ public class ByteGrayColorTest {
assertThat(color1.getLuminosity()).isCloseTo(.25, within(.01)); assertThat(color1.getLuminosity()).isCloseTo(.25, within(.01));
assertThat(color2.getLuminosity()).isCloseTo(.75, within(.01)); assertThat(color2.getLuminosity()).isCloseTo(.75, within(.01));
} }
@Test
public void testCompareTo_whenColorsCreatedWithGrayLevel(){
ByteGrayColor color1 = new ByteGrayColor(100);
ByteGrayColor color2 = new ByteGrayColor(100);
ByteGrayColor color3 = new ByteGrayColor(150);
assertThat(color1.compareTo(color3)).isNegative();
assertThat(color3.compareTo(color1)).isPositive();
assertThat(color1.compareTo(color3)).isEqualTo(-(color3.compareTo(color1)));
assertThat(color1.compareTo(color2)).isZero();
}
@Test
public void testCompareTo_whenColorsCreatedWithLuminosity(){
ByteGrayColor color1 = new ByteGrayColor(0.20);
ByteGrayColor color2 = new ByteGrayColor(0.20);
ByteGrayColor color3 = new ByteGrayColor(0.60);
assertThat(color1.compareTo(color3)).isNegative();
assertThat(color3.compareTo(color1)).isPositive();
assertThat(color1.compareTo(color3)).isEqualTo(-(color3.compareTo(color1)));
assertThat(color1.compareTo(color2)).isZero();
}
@Test
public void testCompareTo_whenColorsCreatedWithLuminosityAndGrayLevel(){
ByteGrayColor color1 = new ByteGrayColor(0.);
ByteGrayColor color2 = new ByteGrayColor(0);
ByteGrayColor color3 = new ByteGrayColor(100);
assertThat(color1.compareTo(color3)).isNegative();
assertThat(color3.compareTo(color1)).isPositive();
assertThat(color1.compareTo(color3)).isEqualTo(-(color3.compareTo(color1)));
assertThat(color1.compareTo(color2)).isZero();
}
} }
...@@ -5,16 +5,27 @@ import static org.assertj.core.api.Assertions.*; ...@@ -5,16 +5,27 @@ import static org.assertj.core.api.Assertions.*;
class MatrixGrayImageTest { class MatrixGrayImageTest {
@Test @Test
void getWidth() { void testGetWidth() {
assertThat(new MatrixGrayImage(0,0).getWidth()).isEqualTo(0); assertThat(new MatrixGrayImage(0,0).getWidth()).isEqualTo(0);
assertThat(new MatrixGrayImage(10,20).getWidth()).isEqualTo(10); assertThat(new MatrixGrayImage(10,20).getWidth()).isEqualTo(10);
assertThat(new MatrixGrayImage(400,300).getWidth()).isEqualTo(400); assertThat(new MatrixGrayImage(400,300).getWidth()).isEqualTo(400);
} }
@Test @Test
void getHeight() { void testGetHeight() {
assertThat(new MatrixGrayImage(0,0).getHeight()).isEqualTo(0); assertThat(new MatrixGrayImage(0,0).getHeight()).isEqualTo(0);
assertThat(new MatrixGrayImage(10,20).getHeight()).isEqualTo(20); assertThat(new MatrixGrayImage(10,20).getHeight()).isEqualTo(20);
assertThat(new MatrixGrayImage(400,300).getHeight()).isEqualTo(300); assertThat(new MatrixGrayImage(400,300).getHeight()).isEqualTo(300);
} }
@Test
void testGetPixel_whenPixelHasBeenSet() {
GrayColor grey1 = new ByteGrayColor(0.2);
GrayColor grey2 = new ByteGrayColor(0.8);
MatrixGrayImage image = new MatrixGrayImage(10, 10);
image.setPixel(grey1, 1, 1);
assertThat(image.getPixelGrayColor(1,1)).isEqualTo(grey1);
image.setPixel(grey2, 3, 9);
assertThat(image.getPixelGrayColor(3,9)).isEqualTo(grey2);
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment