package comp1110.exam;
import org.junit.Before;
import org.junit.FixMethodOrder;
Copyright By PowCoder代写 加微信 powcoder
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.runners.MethodSorters;
import java.util.Set;
import static org.junit.Assert.*;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Q3HollywoodTest {
public Timeout globalTimeout = Timeout.millis(1000);
Q3Hollywood library;
public void setup() {
library = new Q3Hollywood();
addInitialFilms();
public void testGetFilmCount() {
Q3Hollywood empty = new Q3Hollywood();
assertEquals(“getFilmCount() returned incorrect number of films for empty library”, 0, empty.getFilmCount());
assertEquals(“getFilmCount() returned incorrect number of films”, 11, library.getFilmCount());
addMoreFilms();
assertEquals(“getFilmCount() returned incorrect number of films”, 14, library.getFilmCount());
public void testGetFilmCountDuplicate() {
addInitialFilms();
assertEquals(“getFilmCount() returned incorrect number of films”, 11, library.getFilmCount());
addMoreFilms();
addMoreFilms();
assertEquals(“getFilmCount() returned incorrect number of films”, 14, library.getFilmCount());
public void testGetFilmCountDelete() {
Q3Hollywood empty = new Q3Hollywood();
final String NON_EXISTENT_ARTICLE = “Alien 5: Awakening”;
library.deleteFilm(NON_EXISTENT_ARTICLE);
assertEquals(“getFilmCount() returned incorrect number of films for empty library”, 0, empty.getFilmCount());
assertTrue(library.deleteFilm(names[0]));
assertFalse(library.deleteFilm(names[0]));
assertEquals(“getFilmCount() returned incorrect number of films”, 10, library.getFilmCount());
public void testGetFilmsDirectedBy() {
checkDirector(” “, Set.of());
checkDirector(” “, Set.of(“The Lost Boys”, “Flatliners”));
checkDirector(” “, Set.of(“Big”, “Thelma & Louise”));
checkDirector(” “, Set.of(“This Is Spinal Tap”, “A Few Good Men”));
addMoreFilms();
checkDirector(” “, Set.of(“Parenthood”));
checkDirector(” “, Set.of(“Big”, “A League of Their Own”, “Thelma & Louise”));
public void testGetFilmsDirectedByDuplicate() {
addMoreFilms();
addInitialFilms();
addMoreFilms();
checkDirector(” “, Set.of(“Big”, “A League of Their Own”, “Thelma & Louise”));
public void testGetFilmsDirectedByDelete() {
checkDirector(” “, Set.of(“Big”, “Thelma & Louise”));
library.deleteFilm(“Big”);
checkDirector(” “, Set.of(“Thelma & Louise”));
library.deleteFilm(“Big”);
checkDirector(” “, Set.of(“Thelma & Louise”));
checkDirector(” “, Set.of(“The Color Purple”));
library.deleteFilm(“The Color Purple”);
checkDirector(” “, Set.of());
private void checkDirector(String director, Set
assertEquals(“getFilmsDirectedBy(\”” + director + “\”) returned incorrect set”, expected, library.getFilmsDirectedBy(director));
public void testGetFilmsActorOnly() {
checkFilms(” “, Set.of(“The Color Purple”));
checkFilms(“Whoopi Goldberg”, Set.of(“The Color Purple”, “Ghost”));
checkFilms(” “, Set.of(“Big”, “Sleepless in Seattle”));
addMoreFilms();
checkFilms(” “, Set.of(“Big”, “Sleepless in Seattle”, “A League of Their Own”));
public void testGetFilmsDirectorOnly() {
checkFilms(” “, Set.of());
checkFilms(” “, Set.of(“The Lost Boys”, “Flatliners”));
checkFilms(” “, Set.of(“Big”, “Thelma & Louise”));
addMoreFilms();
checkFilms(” “, Set.of(“Parenthood”));
checkFilms(” “, Set.of(“Big”, “A League of Their Own”, “Thelma & Louise”));
public void testGetFilmsActorOrDirector() {
checkFilms(” “, Set.of(“This Is Spinal Tap”, “A Few Good Men”, “Sleepless in Seattle”));
addMoreFilms();
checkFilms(” “, Set.of(“This Is Spinal Tap”, “A Few Good Men”, “Sleepless in Seattle”, “When Harry Met Sally…”));
public void testGetFilmsDelete() {
checkFilms(” “, Set.of(“This Is Spinal Tap”, “A Few Good Men”, “Sleepless in Seattle”));
checkFilms(” “, Set.of(“A Few Good Men”));
checkFilms(“Demi Moore”, Set.of(“A Few Good Men”, “Ghost”));
library.deleteFilm(“A Few Good Men”);
checkFilms(” “, Set.of(“This Is Spinal Tap”, “Sleepless in Seattle”));
checkFilms(” “, Set.of());
checkFilms(“Demi Moore”, Set.of(“Ghost”));
public void testGetFilmsDuplicate() {
library.addFilm(names[6], years[6], directors[6], Set.of(actors[6]));
checkFilms(” “, Set.of(“Flatliners”, “The Lost Boys”));
checkFilms(” “, Set.of(“Flatliners”, “The Lost Boys”));
checkFilms(” “, Set.of(“Flatliners”, “Footloose”, “A Few Good Men”));
private void checkFilms(String person, Set
Set
assertEquals(“getFilms(\”” + person + “\”) returned incorrect set”, expected, result);
public void testAreCoStars() {
checkCoStars(” “, ” “, true);
checkCoStars(” “, ” “, false);
checkCoStars(” “, ” “, false);
checkCoStars(” “, ” “, false);
checkCoStars(” “, “Demi Moore”, true);
checkCoStars(” “, ” “, false);
checkCoStars(” “, ” “, true);
checkCoStars(” “, ” “, false);
checkCoStars(” “, ” “, false);
checkCoStars(” “, “Whoopi Goldberg”, false);
addMoreFilms();
checkCoStars(” “, ” “, true);
checkCoStars(” “, ” “, true);
checkCoStars(” “, “Whoopi Goldberg”, false);
public void testAreCoStarsDelete() {
addMoreFilms();
checkCoStars(” “, ” “, true);
checkCoStars(” “, ” “, true);
library.deleteFilm(“A League of Their Own”);
library.deleteFilm(“Footloose”);
checkCoStars(” “, ” “, false);
checkCoStars(” “, ” “, false);
private void checkCoStars(String person1, String person2, boolean expected) {
boolean result = library.areCoStars(person1, person2);
assertTrue(“areCoStars(\”” + person1 + “\”, \”” + person2 + “\”) returned ” + result + “, expected ” + expected, expected == result);
public void testGetFirstFilmYear() {
checkFilmYear(” “, 1984);
checkFilmYear(” “, 1988);
addMoreFilms();
checkFilmYear(” “, 1988);
public void testGetFirstFilmYearDelete() {
checkFilmYear(” “, 1984);
checkFilmYear(” “, 1988);
library.deleteFilm(“Big”);
checkFilmYear(” “, 1991);
private void checkFilmYear(String person, int expected) {
int result = library.getFirstFilmYear(person);
assertTrue(“getFirstFilmYear(\”” + person + “\”) returned ” + result + “, expected ” + expected, expected == result);
public void testGetNumActors() {
assertEquals(“getNumActors() returned incorrect value”, 24, library.getNumActors());
addMoreFilms();
assertEquals(“getNumActors() returned incorrect value”, 31, library.getNumActors());
public void testGetNumActorsDelete() {
library.deleteFilm(“Big”);
assertEquals(“getNumActors() returned incorrect value”, 23, library.getNumActors()); // –
addMoreFilms();
library.deleteFilm(“The Color Purple”);
assertEquals(“getNumActors() returned incorrect value”, 29, library.getNumActors()); // –
public void testGetMaxFilms() {
assertEquals(“getMaxFilms() returned incorrect value”, 3, library.getMaxFilms()); // or
addMoreFilms();
assertEquals(“getMaxFilms() returned incorrect value”, 4, library.getMaxFilms()); //
public void testGetMaxFilmsDuplicate() {
addInitialFilms();
assertEquals(“getMaxFilms() returned incorrect value”, 3, library.getMaxFilms()); // or
addMoreFilms();
addMoreFilms();
assertEquals(“getMaxFilms() returned incorrect value”, 4, library.getMaxFilms()); //
public void testGetMaxFilmsDelete() {
library.deleteFilm(“This Is Spinal Tap”);
library.deleteFilm(“Flatliners”);
assertEquals(“getMaxFilms() returned incorrect value”, 2, library.getMaxFilms());
addMoreFilms();
library.deleteFilm(“A Few Good Men”);
assertEquals(“getMaxFilms() returned incorrect value”, 3, library.getMaxFilms());
private void addInitialFilms() {
for (int i = 0; i < names.length; i++) {
library.addFilm(names[i], years[i], directors[i], Set.of(actors[i]));
private void addMoreFilms() {
library.addFilm("A League of Their Own", 1992, " ", Set.of(" ", " ", "Madonna", " ", " "));
library.addFilm("Parenthood", 1989, " ", Set.of(" ", " ", " ", " "));
library.addFilm("When Harry Met Sally...", 1989, " ", Set.of(" ", " ", " "));
String[] names = new String[]{
"Footloose",
"This Is Spinal Tap",
"The Color Purple",
"Thelma & Louise",
"The Lost Boys",
"Dirty Dancing",
"Flatliners",
"A Few Good Men",
"Sleepless in Seattle"};
int[] years = new int[]{
String[] directors = new String[]{
String[][] actors = new String[][]{
new String[]{" ", " ", " "},
new String[]{" ", " ", " "},
new String[]{" ", "Whoopi Goldberg"},
new String[]{" ", " ", " "},
new String[]{" ", " ", " ", " "},
new String[]{" ", " "},
new String[]{" ", " ", " "},
new String[]{" ", "Demi Moore", "Whoopi Goldberg"},
new String[]{" ", " "},
new String[]{" ", "Demi Moore", " ", " "},
new String[]{" ", " ", " ", " "},};
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com