Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rental#amount

  • Loading branch information...
commit ee80c8a692dae75737a9cce3634c9a1dae1607f7 1 parent 7ce7de2
chen seng authored
6 .bundle/config
... ... @@ -1,3 +1,3 @@
1   ----
2   -BUNDLE_PATH: vendor
3   -BUNDLE_DISABLE_SHARED_GEMS: "1"
  1 +---
  2 +BUNDLE_PATH: vendor/
  3 +BUNDLE_DISABLE_SHARED_GEMS: '1'
2  .rvmrc
... ... @@ -1 +1 @@
1   -rvm use 1.9.2
  1 +rvm use 1.9.2@refactoring --create
4 lib/movie.rb
@@ -5,8 +5,10 @@ class Movie
5 5
6 6 attr_accessor :title, :price_code
7 7
8   - def initialize(title, price_code)
  8 + def initialize(title, price_code )
9 9 @title = title
10 10 @price_code = price_code
11 11 end
  12 +
  13 +
12 14 end
17 lib/rental.rb
@@ -5,4 +5,21 @@ def initialize(movie, days_rented)
5 5 @movie = movie
6 6 @days_rented = days_rented
7 7 end
  8 +
  9 + def amount()
  10 + this_amount = 0;
  11 + case movie.price_code
  12 + when Movie::REGULAR
  13 + this_amount += 2
  14 + this_amount += (days_rented - 2) * 1.5 if days_rented > 2
  15 + when Movie::NEW_RELEASE
  16 + this_amount += days_rented * 3
  17 + when Movie::CHILDRENS
  18 + this_amount += 1.5
  19 + this_amount += (days_rented - 3) * 1.5 if days_rented > 3
  20 + end
  21 + this_amount
  22 + end
  23 +
  24 +
8 25 end
3  refactoring/LICENSE
... ... @@ -0,0 +1,3 @@
  1 +== refactoring
  2 +
  3 +Put appropriate LICENSE for your project here.
3  refactoring/README
... ... @@ -0,0 +1,3 @@
  1 +== refactoring
  2 +
  3 +You should document your project here.
45 refactoring/Rakefile
... ... @@ -0,0 +1,45 @@
  1 +#
  2 +# To change this template, choose Tools | Templates
  3 +# and open the template in the editor.
  4 +
  5 +
  6 +require 'rubygems'
  7 +require 'rake'
  8 +require 'rake/clean'
  9 +require 'rake/gempackagetask'
  10 +require 'rake/rdoctask'
  11 +require 'rake/testtask'
  12 +
  13 +spec = Gem::Specification.new do |s|
  14 + s.name = 'refactoring'
  15 + s.version = '0.0.1'
  16 + s.has_rdoc = true
  17 + s.extra_rdoc_files = ['README', 'LICENSE']
  18 + s.summary = 'Your summary here'
  19 + s.description = s.summary
  20 + s.author = ''
  21 + s.email = ''
  22 + # s.executables = ['your_executable_here']
  23 + s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
  24 + s.require_path = "lib"
  25 + s.bindir = "bin"
  26 +end
  27 +
  28 +Rake::GemPackageTask.new(spec) do |p|
  29 + p.gem_spec = spec
  30 + p.need_tar = true
  31 + p.need_zip = true
  32 +end
  33 +
  34 +Rake::RDocTask.new do |rdoc|
  35 + files =['README', 'LICENSE', 'lib/**/*.rb']
  36 + rdoc.rdoc_files.add(files)
  37 + rdoc.main = "README" # page to start on
  38 + rdoc.title = "refactoring Docs"
  39 + rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
  40 + rdoc.options << '--line-numbers'
  41 +end
  42 +
  43 +Rake::TestTask.new do |t|
  44 + t.test_files = FileList['test/**/*.rb']
  45 +end
4 refactoring/lib/main.rb
... ... @@ -0,0 +1,4 @@
  1 +# To change this template, choose Tools | Templates
  2 +# and open the template in the editor.
  3 +
  4 +puts "Hello World"
18 refactoring/nbproject/private/rake-d.txt
... ... @@ -0,0 +1,18 @@
  1 +clean=Remove any temporary products.
  2 +clobber=Remove any generated file.
  3 +clobber_package=Remove package products
  4 +clobber_rdoc=Remove rdoc products
  5 +doc=
  6 +doc/rdoc=
  7 +doc/rdoc/index.html=
  8 +gem=Build the gem file refactoring-0.0.1.gem
  9 +package=Build all the packages
  10 +pkg=
  11 +pkg/refactoring-0.0.1=
  12 +pkg/refactoring-0.0.1.gem=
  13 +pkg/refactoring-0.0.1.tgz=
  14 +pkg/refactoring-0.0.1.zip=
  15 +rdoc=Build the rdoc HTML Files
  16 +repackage=Force a rebuild of the package files
  17 +rerdoc=Force a rebuild of the RDOC files
  18 +test=Run tests
6 refactoring/nbproject/project.properties
... ... @@ -0,0 +1,6 @@
  1 +main.file=main.rb
  2 +platform.active=Ruby_2
  3 +source.encoding=UTF-8
  4 +spec.src.dir=spec
  5 +src.dir=lib
  6 +test.src.dir=test
16 refactoring/nbproject/project.xml
... ... @@ -0,0 +1,16 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://www.netbeans.org/ns/project/1">
  3 + <type>org.netbeans.modules.ruby.rubyproject</type>
  4 + <configuration>
  5 + <data xmlns="http://www.netbeans.org/ns/ruby-project/1">
  6 + <name>refactoring</name>
  7 + <source-roots>
  8 + <root id="src.dir"/>
  9 + </source-roots>
  10 + <test-roots>
  11 + <root id="test.src.dir"/>
  12 + <root id="spec.src.dir"/>
  13 + </test-roots>
  14 + </data>
  15 + </configuration>
  16 +</project>
13 spec/movie_spec.rb
... ... @@ -0,0 +1,13 @@
  1 +require 'spec_helper'
  2 +
  3 +describe Movie do
  4 + before(:each) do
  5 + day_rented = 3
  6 + @movie = Movie.new()
  7 + @rental = Rental.new(@movie, day_rented);
  8 + end
  9 +
  10 + describe "amount" do
  11 + it "should return 3.5 wih "
  12 + end
  13 +end
45 spec/rental_spec.rb
... ... @@ -0,0 +1,45 @@
  1 +require "spec_helper"
  2 +describe Rental do
  3 +
  4 +
  5 + describe "amount" do
  6 +
  7 + describe "REGULAR type" do
  8 + it "should return 3.5 for day_rented > 2 " do
  9 + movie = Movie.new("Avatar 3d", Movie::REGULAR)
  10 + rental = Rental.new(movie , 3)
  11 + rental.amount().should eq(3.5)
  12 + end
  13 +
  14 + it "should return for day_rented <= 2 " do
  15 + movie = Movie.new("Avatar 3d", Movie::REGULAR)
  16 + rental = Rental.new(movie , 2)
  17 + rental.amount().should eq(2)
  18 + end
  19 + end
  20 +
  21 + it "should return for 9 NEW_RELEASE type " do
  22 + movie = Movie.new("Avatar 3d", Movie::NEW_RELEASE)
  23 + rental = Rental.new(movie, 3)
  24 + rental.amount().should eq(9)
  25 + end
  26 +
  27 + describe "movie type of CHILDRENS" do
  28 + it "should return for day_rented > 3 " do
  29 + movie = Movie.new("Avatar 3d", Movie::CHILDRENS )
  30 + rental = Rental.new(movie, 4)
  31 + rental.amount().should eq(3)
  32 + end
  33 +
  34 + it "should return for day_rented <= 3 " do
  35 + movie = Movie.new("Avatar 3d", Movie::CHILDRENS )
  36 + rental = Rental.new(movie, 3)
  37 + rental.amount().should eq(1.5)
  38 + end
  39 + end
  40 +
  41 +
  42 +
  43 + end
  44 +
  45 +end

0 comments on commit ee80c8a

Please sign in to comment.
Something went wrong with that request. Please try again.