Commit d2b3dc7

mo khan <mo@mokhan.ca>
2013-11-07 04:26:42
complete searching specs.
1 parent 2a93f59
lib/movie_library.js
@@ -108,6 +108,27 @@ module.exports = MovieLibrary = (function(_super) {
     });
   };
 
+  MovieLibrary.prototype.find_movies_not_published_by_pixar = function() {
+    var _this = this;
+    return this.find_all(function(movie) {
+      return movie.studio !== Studio.Pixar;
+    });
+  };
+
+  MovieLibrary.prototype.find_movies_released_after_2004 = function() {
+    var _this = this;
+    return this.find_all(function(movie) {
+      return movie.year_published > 2004;
+    });
+  };
+
+  MovieLibrary.prototype.find_movies_released_between_1982_and_2003 = function() {
+    var _this = this;
+    return this.find_all(function(movie) {
+      return movie.year_published > 1982 && movie.year_published < 2003;
+    });
+  };
+
   return MovieLibrary;
 
 })(Module);
src/movie_library.coffee
@@ -53,3 +53,16 @@ module.exports = class MovieLibrary extends Module
   find_movies_by_pixar_or_disney: ->
     @find_all (movie) =>
       movie.studio == Studio.Pixar || movie.studio == Studio.Disney
+
+  find_movies_not_published_by_pixar: ->
+    @find_all (movie) =>
+      movie.studio != Studio.Pixar
+
+  find_movies_released_after_2004: ->
+    @find_all (movie) =>
+      movie.year_published > 2004
+
+  find_movies_released_between_1982_and_2003: ->
+    @find_all (movie) =>
+      movie.year_published > 1982 && movie.year_published < 2003
+
test/movie_library_spec.coffee
@@ -66,3 +66,27 @@ describe "MovieLibrary", ->
        results.should.include(@fantasia)
        results.should.include(@dumbo)
        results.should.include(@pinocchio)
+
+     it "finds all movies not published by pixar", ->
+       results = @sut.find_movies_not_published_by_pixar()
+       results.length.should.equal(6)
+       results.should.include(@fantasia)
+       results.should.include(@dumbo)
+       results.should.include(@pinocchio)
+       results.should.include(@shawshank_redemption)
+       results.should.include(@chasing_amy)
+       results.should.include(@man_on_fire)
+
+     it "finds all movies released after 2004", ->
+       results = @sut.find_movies_released_after_2004()
+       results.length.should.equal(2)
+       results.should.include(@up)
+       results.should.include(@cars)
+
+     it "finds all movies released between 1982 and 2003 - inclusive", ->
+       results = @sut.find_movies_released_between_1982_and_2003()
+       results.length.should.equal(4)
+       results.should.include(@shawshank_redemption)
+       results.should.include(@chasing_amy)
+       results.should.include(@toy_story)
+       results.should.include(@monsters_inc)