Permalink
Browse files

Rental#amount

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

0 comments on commit ee80c8a

Please sign in to comment.