Commit 2ece5f47 authored by Stephen Bennett's avatar Stephen Bennett

Merge branch 'refactor_puzzle_one' into 'master'

Refactor puzzle one

This merge request contains changes to the coding puzzle following feedback from @tpage. The following changes have been made:

+ Renamed the packages to be clearer
+ Added unit tests with the correct answers for the first 3 questions
+ Updated the instructions to make implementation requirements clearer

There's no unit test for the 4th part of the test as it is left to the user to define success. 

@tpage  - Can you check the answers I've put in the tests against yours to make sure we have the same values.

See merge request !2
parents 22526689 34c14bc9
...@@ -33,8 +33,15 @@ The `MovieRepository` class provides a method for reading the JSON document (whi ...@@ -33,8 +33,15 @@ The `MovieRepository` class provides a method for reading the JSON document (whi
The `App` class shows usage of the `MovieRepository` class. The `App` class shows usage of the `MovieRepository` class.
### Question One ### Question One
`FilmStats` is a stub class for the first part of your challenge. Feel free to modify this class, or its contents as part of solving the first problem.
`QuestionOne` is a stub class for the first part of your challenge. Feel free to modify this class, or its contents as part of solving the first problem. To help you out with answering these questions, you may find the following information about the data useful:
+ Numeric values which are unknown are either stored as 0 or -1
+ String values which are unknown are either the empty string or `null`
+ The data set contains duplicate movie titles. We're not bothered if your results filter out these duplicates or not
Tests (with the correct answers) are provided in `FilmStatsTest`.
### Question Two ### Question Two
......
This diff is collapsed.
package org.alfresco.questionone; package org.alfresco.filmstats;
import org.alfresco.MovieRepository;
import org.alfresco.model.DirectorAndLeadingActorPair; import org.alfresco.model.DirectorAndLeadingActorPair;
import org.alfresco.model.Film; import org.alfresco.model.Film;
...@@ -10,7 +11,13 @@ import static java.util.Collections.emptyList; ...@@ -10,7 +11,13 @@ import static java.util.Collections.emptyList;
/** /**
* Please complete your code for question one here. * Please complete your code for question one here.
*/ */
public class QuestionOne { public class FilmStats {
private final MovieRepository movieRepository;
public FilmStats(MovieRepository movieRepository) {
this.movieRepository = movieRepository;
}
public List<Film> top10HighestGrossingFilms() { public List<Film> top10HighestGrossingFilms() {
return emptyList(); return emptyList();
......
package org.alfresco.filmstats;
import org.alfresco.MovieRepository;
import org.alfresco.model.Film;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.List;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
/**
* These are the answers for puzzle one. Complete the code in FilmStats.java to make these tests pass.
*/
public class FilmStatsTest {
private final MovieRepository movieRepository;
public FilmStatsTest() throws FileNotFoundException {
this.movieRepository = new MovieRepository(new FileReader("movie-data.json"));
}
@Test
public void shouldReturnTop10HighestGrossingFilms() {
FilmStats filmStats = new FilmStats(movieRepository);
List<Film> films = filmStats.top10HighestGrossingFilms();
assertThat(asListOfFilmNames(films)).containsExactly(
"Avatar",
"Titanic",
"Jurassic World",
"The Avengers",
"The Avengers",
"The Dark Knight",
"Star Wars: Episode I - The Phantom Menace",
"Star Wars: Episode IV - A New Hope",
"Avengers: Age of Ultron",
"The Dark Knight Rises"
);
}
@Test
public void shouldReturnTop10ValueForMoneyFilms() {
FilmStats filmStats = new FilmStats(movieRepository);
List<Film> films = filmStats.top10ValueForMoneyFilms();
assertThat(asListOfFilmNames(films)).containsExactly(
"Paranormal Activity",
"Tarnation",
"The Blair Witch Project",
"The Brothers McMullen",
"The Texas Chain Saw Massacre",
"The Texas Chain Saw Massacre",
"El Mariachi",
"The Gallows",
"Super Size Me",
"Halloween"
);
}
@Test
public void shouldReturnActorWhoHasAppearedInTheMostFilms() {
FilmStats filmStats = new FilmStats(movieRepository);
String actor = filmStats.actorWhoHasAppearedInTheMostFilms();
assertThat(actor).isEqualTo("Robert De Niro");
}
private List<String> asListOfFilmNames(List<Film> films) {
return films.stream().map(Film::getMovieTitle).collect(toList());
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment