Untitled
unknown
plain_text
5 years ago
3.3 kB
7
Indexable
@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(1) @Graded(description="constructor", marks=8)
public void testVideoAnalytics() {
assertEquals("El Clasico", simple.title);
assertEquals("Installing Eclipse", nullHistory.title);
assertEquals("Headphones Review", emptyHistory.title);
assertEquals("Practical exam walkthrough", longHistory.title);
assertNotNull(simple.views);
assertNotNull(emptyHistory.views);
assertNotNull(longHistory.views);
assertNull(nullHistory.views);
assertNotEquals(a, simple.views, "you are making reference copy, you need to make instance copy. watch week 4 lecture.");
assertNotEquals(c, emptyHistory.views);
assertNotEquals(d, longHistory.views);
currentMethodName = new Throwable().getStackTrace()[0].getMethodName();
}
@Test @Order(2) @Graded(description="getHistoryLength", marks=4)
public void testGetHistoryLength() {
assertEquals(6, simple.getHistoryLength());
assertEquals(0, nullHistory.getHistoryLength());
assertEquals(0, emptyHistory.getHistoryLength());
assertEquals(28, longHistory.getHistoryLength());
currentMethodName = new Throwable().getStackTrace()[0].getMethodName();
}
@Test @Order(3) @Graded(description="getTotalViews", marks=8)
public void testGetTotalViews() {
assertEquals(275, simple.getTotalViews());
assertEquals(0, nullHistory.getTotalViews());
assertEquals(0, emptyHistory.getTotalViews());
assertEquals(2005, longHistory.getTotalViews());
currentMethodName = new Throwable().getStackTrace()[0].getMethodName();
}
@Test @Order(4) @Graded(description="indexOfLeastViews", marks=8)
public void testIndexOfLeastViews() {
assertEquals(5, simple.indexOfLeastViews());
assertEquals(null, nullHistory.indexOfLeastViews());
assertEquals(null, emptyHistory.indexOfLeastViews());
assertEquals(10, longHistory.indexOfLeastViews());
currentMethodName = new Throwable().getStackTrace()[0].getMethodName();
}
@Test @Order(5) @Graded(description="highestViewCount", marks=8)
public void testHighestViewCount() {
assertEquals(90, simple.highestViewCount());
assertEquals(0, nullHistory.highestViewCount());
assertEquals(0, emptyHistory.highestViewCount());
assertEquals(180, longHistory.highestViewCount());
currentMethodName = new Throwable().getStackTrace()[0].getMethodName();
}Editor is loading...