-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGeometryTest.java
More file actions
84 lines (72 loc) · 2.39 KB
/
GeometryTest.java
File metadata and controls
84 lines (72 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.dtcc.exams.assessment.part4;
import com.dtcc.exams.part4.Geometry;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.Comparator;
public class GeometryTest {
@Test
public void areaTest1(){
int radius = 7;
int height = 2;
int width = 5;
Geometry g = new Geometry(height,width,radius);
int expected = 10;
int actual = g.getArea(height, width);
Assert.assertEquals("The rectangle area should be 10", expected, actual);
}
@Test
public void areaTest2(){
int radius = 7;
int height = 2;
int width = 5;
Geometry g = new Geometry(height,width,radius);
double expected = 153.86;
double actual = g.getArea(radius);
Assert.assertEquals("The Circle area should be 153.86", expected, actual, 0.001);
}
@Test
public void areaTest3(){
int radius = 21;
int height = 4;
int width = 8;
Geometry g = new Geometry(height,width,radius);
int expected = 32;
int actual = g.getArea(height, width);
Assert.assertEquals("The rectangle area should be 32", expected, actual);
}
@Test
public void areaTest4(){
int radius = 21;
int height = 4;
int width = 8;
Geometry g = new Geometry(height,width,radius);
double expected = 1384.74;
double actual = g.getArea(radius);
Assert.assertEquals("The Circle area should be 1384.74", expected, actual, 0.001);
}
@Test
public void implementedInterfaces(){
Geometry g = new Geometry();
String[] expected = {"Circle", "Rectangle"};
String[] actual = getIterfaceNames(g);
Assert.assertArrayEquals(expected, actual);
}
private String[] getIterfaceNames(Object o){
Class[] names = sortInterfaceArrayAlphabetically(o.getClass().getInterfaces());
String[] namesAsString = new String[names.length];
for (int x=0; x < names.length; x++){
namesAsString[x] = names[x].getName();
}
return namesAsString;
}
private Class[] sortInterfaceArrayAlphabetically(Class[] arr){
Arrays.sort(arr, new Comparator<Class>() {
@Override
public int compare(Class o1, Class o2) {
return o1.getName().compareTo(o2.getName());
}
});
return arr;
}
}