Files
Testate/WS2526/Testat 2b/Main.java
T

225 lines
10 KiB
Java

public class Main {
/**
* Die folgende main-Methode dient Ihnen zur Hilfe, um Ihre Lösungen zu testen.
* Beachten Sie bitte, dass in dieser Methode nicht alle Tests enthalten sind,
* sondern nur einige, die Ihnen helfen sollen, Ihre Lösungen zu überprüfen.
*/
public static void main(String[] args) {
System.out.println("Aufgabe 1: MediaLibrary");
System.out.println("");
// 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));
System.out.println("");
System.out.println("Aufgabe 2: Deque");
System.out.println("");
// create a deque
Deque deque = new Deque();
// add first item to the deque
deque.addFirst("Item 1");
// deque should now contain: ["Item 1"]
System.out.println(deque);
System.out.println("-> Should contain: [Item 1]");
// deque size should be 1
System.out.println("Deque size: " + deque.size());
System.out.println("-> Should be size 1");
// deque should not be empty
System.out.println("Is deque empty? " + deque.isEmpty());
System.out.println("-> Should be false");
// peek first should return "Item 1"
System.out.println("Peek first: " + deque.peekFirst());
System.out.println("-> Peek first should return 'Item 1'");
// peek last should return "Item 1"
System.out.println("Peek last: " + deque.peekLast());
System.out.println("-> Peek last should return 'Item 1'");
System.out.println("");
// add second item to the deque
deque.addFirst("Item 2");
// deque should now contain: ["Item 2", "Item 1"]
System.out.println(deque);
System.out.println("-> Should contain: [Item 2, Item 1]");
// deque size should be 2
System.out.println("Deque size: " + deque.size());
System.out.println("-> Should be size 2");
// deque should not be empty
System.out.println("Is deque empty? " + deque.isEmpty());
System.out.println("-> Should be false");
// peek first should return "Item 2"
System.out.println("Peek first: " + deque.peekFirst());
System.out.println("-> Peek first should return 'Item 2'");
// peek last should return "Item 1"
System.out.println("Peek last: " + deque.peekLast());
System.out.println("-> Peek last should return 'Item 1'");
System.out.println("");
// add third item to the deque
deque.addFirst("Item 3");
// deque should now contain: ["Item 3", "Item 2", "Item 1"]
System.out.println(deque);
System.out.println("-> Should contain: [Item 3, Item 2, Item 1]");
// deque size should be 3
System.out.println("Deque size: " + deque.size());
System.out.println("-> Should be size 3");
// deque should not be empty
System.out.println("Is deque empty? " + deque.isEmpty());
System.out.println("-> Should be false");
// peek first should return "Item 1"
System.out.println("Peek first: " + deque.peekFirst());
System.out.println("-> Peek first should return 'Item 1'");
// peek last should return "Item 3"
System.out.println("Peek last: " + deque.peekLast());
System.out.println("-> Peek last should return 'Item 3'");
System.out.println("");
// poll first should return "Item 3" and remove it from the deque
System.out.println("Poll first: " + deque.pollFirst());
System.out.println("-> Should return 'Item 3'");
// deque should now contain: ["Item 2", "Item 1"]
System.out.println(deque);
System.out.println("-> Should contain: [Item 2, Item 1]");
// deque size should be 2
System.out.println("Deque size: " + deque.size());
System.out.println("-> Should be size 2");
// deque should not be empty
System.out.println("Is deque empty? " + deque.isEmpty());
System.out.println("-> Should be false");
// peek first should return "Item 2"
System.out.println("Peek first: " + deque.peekFirst());
System.out.println("-> Peek first should return 'Item 2'");
// peek last should return "Item 1"
System.out.println("Peek last: " + deque.peekLast());
System.out.println("-> Peek last should return 'Item 1'");
System.out.println("");
// poll first should return "Item 2" and remove it from the deque
System.out.println("Poll first: " + deque.pollFirst());
System.out.println("-> Should return 'Item 2'");
// deque should now contain: ["Item 1"]
System.out.println(deque);
// deque size should be 1
System.out.println("Deque size: " + deque.size());
System.out.println("-> Should be size 1");
// deque should not be empty
System.out.println("Is deque empty? " + deque.isEmpty());
System.out.println("-> Should be false");
// peek first should return "Item 1"
System.out.println("Peek first: " + deque.peekFirst());
System.out.println("-> Peek first should return 'Item 1'");
// peek last should return "Item 1"
System.out.println("Peek last: " + deque.peekLast());
System.out.println("-> Peek last should return 'Item 1'");
System.out.println("");
// poll first should return "Item 1" and remove it from the deque
System.out.println("Poll first: " + deque.pollFirst());
System.out.println("-> Should return 'Item 1'");
// deque should now be empty
System.out.println(deque);
System.out.println("-> Should be empty");
// deque size should be 0
System.out.println("Deque size: " + deque.size());
System.out.println("-> Should be size 0");
// deque should be empty
System.out.println("Is deque empty? " + deque.isEmpty());
System.out.println("-> Should be true");
// peek first should return null
System.out.println("Peek first: " + deque.peekFirst());
System.out.println("-> Peek first should return null");
// peek last should return null
System.out.println("Peek last: " + deque.peekLast());
System.out.println("-> Peek last should return null");
System.out.println("");
// poll first should return null since the deque is empty
System.out.println("Poll first: " + deque.pollFirst());
System.out.println("-> Should return null since the deque is empty");
}
}