/** * A class with a main method to test the results. * * DOESN'T include all tests executed by JACK! */ public class Main { /** * Runs some test cases against the media library. * * @param args Ignored. */ public static void main(String[] args) { // create items MediaItem longMovie = new Movie(241, "The Lord of the Rings", 5); MediaItem shortMovie = new Movie(109, "Deadpool", 42); MediaItem shortSeries = new Series(1230, "SpongeBob", 7); MediaItem longSeries = new Series(2930, "Breaking Bad", 4); // create media library MediaLibrary mediaLibrary = new MediaLibrary(4, 2000); mediaLibrary.addItem(shortSeries); mediaLibrary.addItem(longMovie); // toString - Aufgabe 1 System.out.println("Expected (Movie.toString()): Movie: The Lord of the Rings (5 241 min)"); System.out.println("Your code (Movie.toString()): " + longMovie.toString()); System.out.println(); System.out.println("Expected (Series.toString()): Series: SpongeBob (7 1230 min)"); System.out.println("Your code (Series.toString()): " + shortSeries.toString()); System.out.println(); // getWeight - Aufgabe 2 System.out.println("Expected (MediaLibrary.getDuration()): 1471"); System.out.print("Your code (MediaLibrary.getDuration()): "); if (mediaLibrary instanceof Lasting) { System.out.println(((Lasting) mediaLibrary).getDuration()); } else { System.out.println("Missing."); } System.out.println(); // addItem - Aufgabe 2 System.out.println("Testing MediaLibrary.addItem()"); boolean addLongMovieAgain = mediaLibrary.addItem(longMovie); if (addLongMovieAgain) { System.out.println("Failure: The long movie should not be added twice."); } else { System.out.println("Success: The long movie was not added again."); } boolean addLongSeries = mediaLibrary.addItem(longSeries); // add item (241 + 1230 + 2930) --> too long if (addLongSeries) { System.out.println("Failure: The long series should be too long to add."); } else { System.out.println("Success: The long series is too long to add."); } if (mediaLibrary.containsItem(longSeries)) { System.out.println("Failure: The long series should not be added."); } else { System.out.println("Success: The media library does not contain the long series."); } boolean addShortMovie = mediaLibrary.addItem(shortMovie); // add item --> should fit if (addShortMovie) { System.out.println("Success: The short movie was added."); } else { System.out.println("Failure: The short movie should fit into the media library."); } if (mediaLibrary.containsItem(shortMovie)) { System.out.println("Success: The media library contains the short movie."); } else { System.out.println("Failure: The media library does not contain the short movie."); } System.out.println(); // lastIndexOf - Aufgabe 2 System.out.println("Testing MediaLibrary.lastIndexOf()"); System.out.println("MediaLibrary.lastIndexOf(longMovie.getTitle(), 0) Expected: -1, Your code: " + mediaLibrary.lastIndexOf(longMovie.getTitle(), 0)); System.out.println("MediaLibrary.lastIndexOf(longMovie.getTitle(), 1) Expected: 1, Your code: " + mediaLibrary.lastIndexOf(longMovie.getTitle(), 1)); System.out.println("MediaLibrary.lastIndexOf(longMovie.getTitle(), 2) Expected: 1, Your code: " + mediaLibrary.lastIndexOf(longMovie.getTitle(), 2)); System.out.println("MediaLibrary.lastIndexOf(shortMovie.getTitle(), 2) Expected: 2, Your code: " + mediaLibrary.lastIndexOf(shortMovie.getTitle(), 2)); mediaLibrary.addItem(new Movie(100, "Deadpool", 42)); // add same title to check ordering System.out.println("MediaLibrary.lastIndexOf(shortMovie.getTitle(), 3) Expected: 3, Your code: " + mediaLibrary.lastIndexOf(shortMovie.getTitle(), 3)); } }