Untitled
unknown
plain_text
5 years ago
2.2 kB
14
Indexable
/**
*
* @return an array representing the number of views as a percentage
* of total views.
* for example, if views = {10, 70, 20, 90}, the total views are 190.
* 10 is 5.26% of 190
* 70 is 36.84% of 190
* 20 is 10.52% of 190
* 90 is 47.36% of 190
* Don't worry about the EXACT value. The test checks if each value is
* within 0.01 of the value expected
* return null if views is null and empty array if views is an empty array
*/
public double[] viewsInPercentage() {
return null; //to be completed
}
// test case//
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class VideoAnalyticsTest {
VideoAnalytics simple, nullHistory, emptyHistory, longHistory;
int[] a;
int[] b;
int[] c;
int[] d;
public static int score = 0;
public static String result = "";
public static String currentMethodName = null;
ArrayList<String> methodsPassed = new ArrayList<String>();
@BeforeEach
public void setUp() throws Exception {
currentMethodName = null;
a = new int[] {10,70,20,90,80,5};
simple = new VideoAnalytics("El Clasico", a);
b = null;
nullHistory = new VideoAnalytics("Installing Eclipse", b);
c = new int[0]; //empty array
emptyHistory = new VideoAnalytics("Headphones Review", c);
d = new int[] {10,10,20,10,20,30,10,20,30,40,5,40,50,60,80,70,70,80,90,100,110,120,130,140,150,160,170,180};
longHistory = new VideoAnalytics("Practical exam walkthrough", d);
}
@Test @Order(6) @Graded(description="viewsInPercentage", marks=8)
public void testViewsInPercentage() {
assertNull(nullHistory.viewsInPercentage());
assertNotNull(emptyHistory.viewsInPercentage());
assertEquals(0, emptyHistory.viewsInPercentage().length);
for(int i=0; i < simple.views.length; i++) {
assertEquals(simple.views[i] * 100.0 / simple.getTotalViews(), simple.viewsInPercentage()[i], 0.01);
}
for(int i=0; i < longHistory.views.length; i++) {
assertEquals(longHistory.views[i] * 100.0 / longHistory.getTotalViews(), longHistory.viewsInPercentage()[i], 0.01);
}
currentMethodName = new Throwable().getStackTrace()[0].getMethodName();
}Editor is loading...