From 840dbf0c3dab1342dce9cb8db2a53cef045f3c3c Mon Sep 17 00:00:00 2001 From: Tomasz Kuklis Date: Mon, 12 Dec 2011 12:56:45 +0100 Subject: [PATCH 01/11] support const loans --- lib/excel.rb | 35 +++++++++++++++++++++++ lib/monetico.rb | 1 + lib/monetico/loan.rb | 38 +++++++++++++++++++------ monetico.gemspec | 3 ++ spec/loan_spec.rb | 66 ++++++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 7 +++++ 6 files changed, 142 insertions(+), 8 deletions(-) create mode 100644 lib/excel.rb create mode 100644 spec/loan_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/lib/excel.rb b/lib/excel.rb new file mode 100644 index 0000000..1bf6758 --- /dev/null +++ b/lib/excel.rb @@ -0,0 +1,35 @@ +module Excel + def pmt(rate, nper, pv, fv=0, type=0) + ((-pv * pvif(rate, nper) - fv ) / ((1.0 + rate * type) * fvifa(rate, nper))) + end + + def ipmt(rate, per, nper, pv, fv=0, type=0) + p = pmt(rate, nper, pv, fv, 0); + ip = -(pv * pow1p(rate, per - 1) * rate + p * pow1pm1(rate, per - 1)) + (type == 0) ? ip : ip / (1 + rate) + end + + def ppmt(rate, per, nper, pv, fv=0, type=0) + p = pmt(rate, nper, pv, fv, type) + ip = ipmt(rate, per, nper, pv, fv, type) + p - ip + end + + protected + + def pow1pm1(x, y) + (x <= -1) ? ((1 + x) ** y) - 1 : Math.exp(y * Math.log(1.0 + x)) - 1 + end + + def pow1p(x, y) + (x.abs > 0.5) ? ((1 + x) ** y) : Math.exp(y * Math.log(1.0 + x)) + end + + def pvif(rate, nper) + pow1p(rate, nper) + end + + def fvifa(rate, nper) + (rate == 0) ? nper : pow1pm1(rate, nper) / rate + end +end diff --git a/lib/monetico.rb b/lib/monetico.rb index 04cbbc5..d3fa0f4 100644 --- a/lib/monetico.rb +++ b/lib/monetico.rb @@ -1,4 +1,5 @@ require "bigdecimal" +require 'excel' require "monetico/loan" require "monetico/version" diff --git a/lib/monetico/loan.rb b/lib/monetico/loan.rb index 8b26154..51190ef 100644 --- a/lib/monetico/loan.rb +++ b/lib/monetico/loan.rb @@ -1,5 +1,7 @@ module Monetico class Loan + include Excel + CADENCE = { monthly: 12, weekly: 52, @@ -28,30 +30,50 @@ def total_interests end def interests(idx) - (@amount - (idx - 1) * capital) * @interest_rate + if const? + interests_for_period(idx) + else + (@amount - (idx - 1) * capital) * @interest_rate + end end def payback(range) from = range.begin to = range.end - + + current_amount = 0.0 + if const? par = (1 + @interest_rate) ** @no_installments - + range.map do |n| - { no: n, interests: interests(n), amount: @amount * @interest_rate * par / (par - 1) } + current_amount += monthly_payment + { no: n, interests: interests(n), amount: monthly_payment, capital: capital_for_period(n), balance: @amount + total_interests - current_amount} end else range.map do |n| - { no: n, interests: interests(n), amount: capital + interests(n) } + amount = capital + interests(n) + current_amount += amount + { no: n, interests: interests(n), amount: amount, capita: capital, balance: @amount + total_interests - current_amount} end end end - + + def monthly_payment + pmt(@interest_rate, @no_installments, @amount).abs + end + + def interests_for_period(n) + ipmt(@interest_rate, n, @no_installments, @amount).abs + end + + def capital_for_period(n) + ppmt(@interest_rate, n, @no_installments, @amount).abs + end + def const? @kind == :const end private :const? - end -end \ No newline at end of file +end diff --git a/monetico.gemspec b/monetico.gemspec index 29c704c..3aba412 100644 --- a/monetico.gemspec +++ b/monetico.gemspec @@ -18,4 +18,7 @@ Gem::Specification.new do |gem| gem.name = "monetico" gem.require_paths = ["lib"] gem.version = Monetico::VERSION + + gem.add_development_dependency "rspec" + gem.add_development_dependency "rake" end diff --git a/spec/loan_spec.rb b/spec/loan_spec.rb new file mode 100644 index 0000000..32ebfec --- /dev/null +++ b/spec/loan_spec.rb @@ -0,0 +1,66 @@ +require "spec_helper" + +describe Monetico::Loan do + describe "const loan" do + before :all do + @loan = Monetico::Loan.new(200000.0, 0.065, 360, :monthly, :const) + end + + it "capital returns amount/no_installments" do + @loan.monthly_payment.to_f.round_down(2).abs.should == 1264.13 + end + + it "total_interests returns sum of interests" do + @loan.total_interests.to_f.round_down(2).should == 255088.98 + end + + it "monthly_capital(1) returns capital for first payment" do + @loan.capital_for_period(1).to_f.round_down(2).abs.should == 180.80 + end + + it "monthly_intersts(1) returns capital for first payment" do + @loan.interests_for_period(1).to_f.round_down(2).abs.should == 1083.33 + end + + it "monthly_capital(117) returns capital for first payment" do + @loan.capital_for_period(117).to_f.round_down(2).abs.should == 338.34 + end + + it "monthly_intersts(117) returns capital for first payment" do + @loan.interests_for_period(117).to_f.round_down(2).abs.should == 925.80 + end + + it "payback(1..360) returns payback table and last item balance should be 0.0" do + table = @loan.payback(1..360) + + table[359][:balance].to_f.round_down(2).should == 0.0 + end + + end + + describe "desc loan" do + before :all do + @loan = Monetico::Loan.new(200000.0, 0.065, 360, :monthly, :desc) + end + + it "capital returns amount/no_installments" do + @loan.capital.to_f.round_down(2).abs.should == 555.56 + end + + it "total_interests returns sum of interests" do + @loan.total_interests.to_f.round_down(2).should == 195541.67 + end + + it "interests(1) returns intersts for 1 payment" do + @loan.interests(1).to_f.round_down(2).should == 1083.33 + end + + it "payback(1..360) returns payback table and last item balance should be 0.0" do + table = @loan.payback(1..360) + + table[359][:balance].to_f.round_down(2).should == 0.0 + end + + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..b69ba9c --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,7 @@ +require "bundler" +Bundler.setup + +require "rspec" + +Dir[File.expand_path(File.dirname(__FILE__) + "/../lib/**/*.rb")].each { |f| require f } + From 275590413e284c3029d6160a19822943c30ed818 Mon Sep 17 00:00:00 2001 From: Tomasz Kuklis Date: Mon, 12 Dec 2011 13:44:42 +0100 Subject: [PATCH 02/11] fixed attribute name --- lib/monetico/loan.rb | 2 +- spec/loan_spec.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/monetico/loan.rb b/lib/monetico/loan.rb index 51190ef..5185c65 100644 --- a/lib/monetico/loan.rb +++ b/lib/monetico/loan.rb @@ -54,7 +54,7 @@ def payback(range) range.map do |n| amount = capital + interests(n) current_amount += amount - { no: n, interests: interests(n), amount: amount, capita: capital, balance: @amount + total_interests - current_amount} + { no: n, interests: interests(n), amount: amount, capital: capital, balance: @amount + total_interests - current_amount} end end end diff --git a/spec/loan_spec.rb b/spec/loan_spec.rb index 32ebfec..7111dce 100644 --- a/spec/loan_spec.rb +++ b/spec/loan_spec.rb @@ -59,8 +59,7 @@ table = @loan.payback(1..360) table[359][:balance].to_f.round_down(2).should == 0.0 - end - + end end end From 2d6fd5cb143534b377f7a3453769e34e4e59ade0 Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Fri, 10 Feb 2012 15:13:09 +0100 Subject: [PATCH 03/11] tests and bigdecimal compatibility --- .rvmrc | 6 ++-- Gemfile | 9 ++++++ Rakefile | 56 +++++++++++++++++++++++++++++++++++++- lib/monetico.rb | 18 ++++-------- lib/monetico/calculable.rb | 23 ++++++++++++++++ spec/monetico_spec.rb | 38 ++++++++++++++++++++++++++ spec/spec_helper.rb | 6 ++++ 7 files changed, 140 insertions(+), 16 deletions(-) create mode 100644 lib/monetico/calculable.rb create mode 100644 spec/monetico_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.rvmrc b/.rvmrc index ee3b09c..f357ddc 100644 --- a/.rvmrc +++ b/.rvmrc @@ -1,2 +1,4 @@ -rvm_gemset_create_on_use_flag=1 -rvm gemset use monetico +#rvm_gemset_create_on_use_flag=1 +#rvm gemset use monetico + +rvm use 1.9.3@monetico --create diff --git a/Gemfile b/Gemfile index 4a8b71e..1906b91 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,12 @@ source 'http://rubygems.org' # Specify your gem's dependencies in monetico.gemspec gemspec + +group :development, :test do + gem "rdoc" + gem "shoulda" + gem "bundler", "~> 1.0.0" + gem "rspec" + gem "jeweler" #, "~> 1.6.4" + gem "simplecov", ">= 0" +end diff --git a/Rakefile b/Rakefile index f57ae68..380d971 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,56 @@ +# encoding: utf-8 + #!/usr/bin/env rake -require "bundler/gem_tasks" +#require "bundler/gem_tasks" + +require 'rubygems' +require 'bundler' +begin + Bundler.setup(:default, :development) +rescue Bundler::BundlerError => e + $stderr.puts e.message + $stderr.puts "Run `bundle install` to install missing gems" + exit e.status_code +end +require 'rake' + +#require 'jeweler' +#Jeweler::Tasks.new do |gem| +# # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options +# gem.name = "gem name" +# gem.homepage = "http://github.com/zaiste/monetico" +# gem.license = "licence" +# gem.summary = %Q{summary} +# gem.description = %Q{desc} +# gem.email = "..." +# gem.authors = ["..."] +# # dependencies defined in Gemfile +# +# gem.files = FileList[ +# "[A-Z]*", "{bin,generators,lib,test}/**/*" +# ] +#end +#Jeweler::RubygemsDotOrgTasks.new + +require 'rspec/core' +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) do |spec| + spec.pattern = FileList['spec/**/*_spec.rb'] +end + +RSpec::Core::RakeTask.new(:rcov) do |spec| + spec.pattern = 'spec/**/*_spec.rb' + spec.rcov = true +end + +task :default => :spec + +require 'rake/rdoctask' +Rake::RDocTask.new do |rdoc| + version = File.exist?('VERSION') ? File.read('VERSION') : "" + + rdoc.rdoc_dir = 'rdoc' + rdoc.title = "simple_metar_parser #{version}" + rdoc.rdoc_files.include('README*') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/lib/monetico.rb b/lib/monetico.rb index 04cbbc5..3adabae 100644 --- a/lib/monetico.rb +++ b/lib/monetico.rb @@ -1,23 +1,15 @@ require "bigdecimal" +require "monetico/calculable" require "monetico/loan" require "monetico/version" class Float - def big; BigDecimal(self.to_s); end - - def round_to(x) - (self * 10**x).ceil.to_f / 10**x - end + include Monetico::Calculable +end - def round_down(x) - if self >= 0 - (self * 10**x).floor.to_f / 10**x - else - -((-self * 10**x).floor.to_f / 10**x) - end - end +class BigDecimal + include Monetico::Calculable end module Monetico - # Your code goes here... end diff --git a/lib/monetico/calculable.rb b/lib/monetico/calculable.rb new file mode 100644 index 0000000..d862259 --- /dev/null +++ b/lib/monetico/calculable.rb @@ -0,0 +1,23 @@ +module Monetico + module Calculable + DEF_PREC = 2 + + def big + BigDecimal(self.to_s); + end + + def round_to(x = DEF_PREC) + (self * 10**x).ceil.to_f / 10**x + end + + alias_method :round_up, :round_to + + def round_down(x = DEF_PREC) + if self >= 0 + (self * 10**x).floor.to_f / 10**x + else + -((-self * 10**x).floor.to_f / 10**x) + end + end + end +end \ No newline at end of file diff --git a/spec/monetico_spec.rb b/spec/monetico_spec.rb new file mode 100644 index 0000000..40554ea --- /dev/null +++ b/spec/monetico_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' +require 'rspec' + +describe Monetico do + before :each do + end + + it "should round up/down BigDecimal" do + b = BigDecimal.new('1.0155') + b.round_down(2).should == 1.01 + b.round_up(2).should == 1.02 + b.round_to(2).should == 1.02 + b.round_down.should == 1.01 + b.round_up.should == 1.02 + + b.round_down(1).should == 1.0 + b.round_up(1).should == 1.1 + + b.round_down(0).should == 1.0 + b.round_up(0).should == 2.0 + end + + it "should round up/down Float" do + b = 1.0155 + b.round_down(2).should == 1.01 + b.round_up(2).should == 1.02 + b.round_to(2).should == 1.02 + b.round_down.should == 1.01 + b.round_up.should == 1.02 + + b.round_down(1).should == 1.0 + b.round_up(1).should == 1.1 + + b.round_down(0).should == 1.0 + b.round_up(0).should == 2.0 + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..b375372 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,6 @@ +require "bundler" +Bundler.setup + +require "rspec" + +Dir[File.expand_path(File.dirname(__FILE__) + "/../lib/**/*.rb")].each { |f| require f } \ No newline at end of file From 69e2eba5d3cbfe541fd3ac9ec807bd6018479cc9 Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Wed, 15 Feb 2012 15:37:44 +0100 Subject: [PATCH 04/11] some changes --- lib/monetico.rb | 5 +++++ spec/loan_spec.rb | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 spec/loan_spec.rb diff --git a/lib/monetico.rb b/lib/monetico.rb index 3adabae..e6f2ad0 100644 --- a/lib/monetico.rb +++ b/lib/monetico.rb @@ -11,5 +11,10 @@ class BigDecimal include Monetico::Calculable end +class Fixnum + # usable for #big + include Monetico::Calculable +end + module Monetico end diff --git a/spec/loan_spec.rb b/spec/loan_spec.rb new file mode 100644 index 0000000..f6730cc --- /dev/null +++ b/spec/loan_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' +require 'rspec' + +describe Monetico::Loan do + before :each do + end + + it "should calculate loan" do + amount = 1000.0 + interest_rate = 0.2 + number_of_installments = 3 + cadence = :weekly + kind = :const + #kind = :desc + + loan_calc = Monetico::Loan.new(amount, interest_rate, number_of_installments, cadence, kind) + puts loan_calc.to_yaml + + loan_calc.payback(1..number_of_installments).each do |l| + #puts lo_nu.inspect + puts l[:amount].to_f + puts l[:interests].to_f + puts l[:capital].to_f + puts l[:balance].to_f + puts "*" + #payback_items.create( + # number: lo_nu[:no], + # pay_day: created_at + lo_nu[:no].send(period), + # interests: lo_nu[:interests], + # capital: lo_nu[:capital], + # balance: lo_nu[:balance] + #) + end + + end + +end From 1e5df9203de2b9a9ff63a716e77ffd84975a570a Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Wed, 15 Feb 2012 15:43:09 +0100 Subject: [PATCH 05/11] merging Tomek's changes --- lib/monetico.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/monetico.rb b/lib/monetico.rb index 3adabae..b86cedf 100644 --- a/lib/monetico.rb +++ b/lib/monetico.rb @@ -1,4 +1,5 @@ require "bigdecimal" +require "excel" require "monetico/calculable" require "monetico/loan" require "monetico/version" From eca0d139280c7be833d0be0cd41ba5e19d6698a3 Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Thu, 16 Feb 2012 17:37:02 +0100 Subject: [PATCH 06/11] fixing and roonding (in progress) --- lib/monetico.rb | 1 + lib/monetico/calculable.rb | 2 + lib/monetico/loan.rb | 30 ++++++++++++- lib/monetico/money_array.rb | 47 ++++++++++++++++++++ spec/loan_spec.rb | 86 +++++++++++++++++++++---------------- spec/money_round_spec.rb | 55 ++++++++++++++++++++++++ 6 files changed, 182 insertions(+), 39 deletions(-) create mode 100644 lib/monetico/money_array.rb create mode 100644 spec/money_round_spec.rb diff --git a/lib/monetico.rb b/lib/monetico.rb index 1d9b8fb..24e19c5 100644 --- a/lib/monetico.rb +++ b/lib/monetico.rb @@ -1,5 +1,6 @@ require "bigdecimal" require "excel" +require "monetico/money_array" require "monetico/calculable" require "monetico/loan" require "monetico/version" diff --git a/lib/monetico/calculable.rb b/lib/monetico/calculable.rb index d862259..2ae9eb2 100644 --- a/lib/monetico/calculable.rb +++ b/lib/monetico/calculable.rb @@ -6,6 +6,8 @@ def big BigDecimal(self.to_s); end + alias_method :to_big, :big + def round_to(x = DEF_PREC) (self * 10**x).ceil.to_f / 10**x end diff --git a/lib/monetico/loan.rb b/lib/monetico/loan.rb index 5185c65..e16067f 100644 --- a/lib/monetico/loan.rb +++ b/lib/monetico/loan.rb @@ -46,18 +46,44 @@ def payback(range) if const? par = (1 + @interest_rate) ** @no_installments - range.map do |n| + res = range.map do |n| current_amount += monthly_payment { no: n, interests: interests(n), amount: monthly_payment, capital: capital_for_period(n), balance: @amount + total_interests - current_amount} end + + res = round_calculation(res) + return res else - range.map do |n| + res = range.map do |n| amount = capital + interests(n) current_amount += amount { no: n, interests: interests(n), amount: amount, capital: capital, balance: @amount + total_interests - current_amount} end + + res = round_calculation(res) + return res end end + + # all payback items for all + def payback_all + payback(1..@no_installments) + end + + def round_calculation(res) + [:interests, :amount, :capital, :balance].each do |k| + tmp = MoneyArray.factory( res.collect{|r| r[k]} ) + tmp = tmp.money_round + + puts tmp.to_yaml + + res.each_with_index do |r,i| + r[k] = tmp[i] + end + + end + return res + end def monthly_payment pmt(@interest_rate, @no_installments, @amount).abs diff --git a/lib/monetico/money_array.rb b/lib/monetico/money_array.rb new file mode 100644 index 0000000..e221e9d --- /dev/null +++ b/lib/monetico/money_array.rb @@ -0,0 +1,47 @@ +module Monetico + class MoneyArray < Array + def money_round + return self.class.money_round(self) + end + + def array_sum + self.inject(nil) { |sum, x| sum ? sum+x : x } + end + + def self.factory(_from) + obj = self.new + _from.each do |f| + obj << f + end + return obj + end + + # round series of values to achieve proper sum + def self.money_round(a) + sum = a.array_sum + rest = 0.0 + result = MoneyArray.new + + a.each do |b| + rounded = ((b * 100).round / 100.0) + real = b + + # compensation + if rest >= 1.0 + rounded -= 1.0 + rest -= 1.0 + elsif rest <= -1.0 + rounded -= -1.0 + rest -= -1.0 + end + + result << rounded.to_big + rest += real - rounded + end + + # puts "rest #{rest}" + return result + + end + end +end \ No newline at end of file diff --git a/spec/loan_spec.rb b/spec/loan_spec.rb index 82889ec..09501df 100644 --- a/spec/loan_spec.rb +++ b/spec/loan_spec.rb @@ -1,42 +1,53 @@ require "spec_helper" describe Monetico::Loan do - #describe "const loan" do - # before :all do - # @loan = Monetico::Loan.new(200000.0, 0.065, 360, :monthly, :const) - # end - # - # it "capital returns amount/no_installments" do - # @loan.monthly_payment.to_f.round_down(2).abs.should == 1264.13 - # end - # - # it "total_interests returns sum of interests" do - # @loan.total_interests.to_f.round_down(2).should == 255088.98 - # end - # - # it "monthly_capital(1) returns capital for first payment" do - # @loan.capital_for_period(1).to_f.round_down(2).abs.should == 180.80 - # end - # - # it "monthly_intersts(1) returns capital for first payment" do - # @loan.interests_for_period(1).to_f.round_down(2).abs.should == 1083.33 - # end - # - # it "monthly_capital(117) returns capital for first payment" do - # @loan.capital_for_period(117).to_f.round_down(2).abs.should == 338.34 - # end - # - # it "monthly_intersts(117) returns capital for first payment" do - # @loan.interests_for_period(117).to_f.round_down(2).abs.should == 925.80 - # end - # - # it "payback(1..360) returns payback table and last item balance should be 0.0" do - # table = @loan.payback(1..360) - # - # table[359][:balance].to_f.round_down(2).should == 0.0 - # end - # - #end + describe "const loan" do + before :all do + # tests were updated using + # http://www.money.pl/banki/kalkulatory/kredytowy/ + @loan = Monetico::Loan.new(200000.0, 0.065, 360, :monthly, :const) + end + + it "first monthly_payment" do + @loan.monthly_payment.to_f.round_down(2).abs.should == 1264.14 + @loan.monthly_payment.to_f.round_down.abs.should == 1264.14 + end + + it "total_interests returns sum of interests" do + @loan.total_interests.to_f.round_down(2).should == 255088.98 + end + + it "monthly_capital(1) returns capital for first payment" do + @loan.capital_for_period(1).to_f.round_down(2).abs.should == 180.80 + end + + it "monthly_interests(1) returns capital for first payment" do + @loan.interests_for_period(1).to_f.round_down(2).abs.should == 1083.33 + end + + it "monthly_capital(117) returns capital for payment" do + @loan.capital_for_period(117).to_f.round_down(2).abs.should == 338.34 + end + + it "monthly_intersts(117) returns capital for payment" do + @loan.interests_for_period(117).to_f.round_down(2).abs.should == 925.80 + end + + it "monthly_capital(231) returns capital for payment" do + @loan.capital_for_period(231).to_f.round_down(2).abs.should == 626.33 + end + + it "monthly_intersts(231) returns capital for payment" do + @loan.interests_for_period(231).to_f.round_down(2).abs.should == 637.81 + end + + #it "payback(1..360) returns payback table and last item balance should be 0.0" do + # table = @loan.payback(1..360) + # + # table[359][:balance].to_f.round_down(2).should == 0.0 + #end + + end #describe "desc loan" do # before :all do @@ -67,7 +78,8 @@ amount = 1000.0 interest_rate = 0.2 number_of_installments = 3 - cadence = :weekly + #cadence = :weekly + cadence = :monthly kind = :const #kind = :desc diff --git a/spec/money_round_spec.rb b/spec/money_round_spec.rb new file mode 100644 index 0000000..f61c572 --- /dev/null +++ b/spec/money_round_spec.rb @@ -0,0 +1,55 @@ +require "spec_helper" + +describe Monetico::MoneyArray do + describe "round simple array" do + before :all do + end + + it "should round simple array" do + ma = Monetico::MoneyArray.new + ma << 10.001 + ma << 9.999 + puts ma.class + + ma.money_round.each do |m| + # precision check + rest = (m * 100.00) % 1 + puts "#{m} - rest #{rest}" + end + + end + + it "should round simple loan results" do + #344.50566129375136 + #16.666666666666668 + #327.8389946270847 + #689.0113225874981 + #* + #344.50566129375136 + #11.20268342288194 + #333.3029778708694 + #344.5056612937467 + #* + #344.50566129375136 + #5.647633791700789 + #338.85802750205056 + + ma = Monetico::MoneyArray.new + # also testes using floats + ma << BigDecimal.new("327.8389946270847") + ma << BigDecimal.new("333.3029778708694") + ma << BigDecimal.new("338.85802750205056") + + puts ma.array_sum + + ma.money_round.each do |m| + # precision check + rest = (m * 100.00) % 1 + puts "#{m} - rest #{rest}" + end + + end + + end +end + From 173be9af54ec9f848e75e168157cd988d7e30e78 Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Fri, 17 Feb 2012 10:41:08 +0100 Subject: [PATCH 07/11] fixing and rounding (in progress) --- lib/monetico/loan.rb | 26 +++++++++++++++++++++----- lib/monetico/money_array.rb | 10 +++++++++- spec/loan_spec.rb | 28 ++++++++++++++-------------- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/lib/monetico/loan.rb b/lib/monetico/loan.rb index e16067f..1478069 100644 --- a/lib/monetico/loan.rb +++ b/lib/monetico/loan.rb @@ -84,18 +84,34 @@ def round_calculation(res) end return res end - - def monthly_payment + + # not rounded + def monthly_payment_float pmt(@interest_rate, @no_installments, @amount).abs end - - def interests_for_period(n) + + # rounded + def monthly_payment + MoneyArray.money_round_value(monthly_payment_float) + end + + # not rounded + def interests_for_period_float(n) ipmt(@interest_rate, n, @no_installments, @amount).abs end + + # rounded + def interests_for_period(n) + MoneyArray.money_round_value(interests_for_period_float(n)) + end - def capital_for_period(n) + def capital_for_period_float(n) ppmt(@interest_rate, n, @no_installments, @amount).abs end + + def capital_for_period(n) + MoneyArray.money_round_value(capital_for_period_float(n)) + end def const? @kind == :const diff --git a/lib/monetico/money_array.rb b/lib/monetico/money_array.rb index e221e9d..8b10ea0 100644 --- a/lib/monetico/money_array.rb +++ b/lib/monetico/money_array.rb @@ -16,6 +16,14 @@ def self.factory(_from) return obj end + # round up currency value + def self.money_round_value(v) + return ((v * 100).round / 100.0).to_big + # TODO delete it + #return ((v * 100).floor / 100.0) + #return ((v * 100).ceil / 100.0) + end + # round series of values to achieve proper sum def self.money_round(a) sum = a.array_sum @@ -23,7 +31,7 @@ def self.money_round(a) result = MoneyArray.new a.each do |b| - rounded = ((b * 100).round / 100.0) + rounded = money_round_value(b) real = b # compensation diff --git a/spec/loan_spec.rb b/spec/loan_spec.rb index 09501df..25e7a6e 100644 --- a/spec/loan_spec.rb +++ b/spec/loan_spec.rb @@ -9,42 +9,42 @@ end it "first monthly_payment" do - @loan.monthly_payment.to_f.round_down(2).abs.should == 1264.14 - @loan.monthly_payment.to_f.round_down.abs.should == 1264.14 + @loan.monthly_payment.to_f.should == 1264.14 + @loan.monthly_payment.to_f.should == 1264.14 end it "total_interests returns sum of interests" do - @loan.total_interests.to_f.round_down(2).should == 255088.98 + @loan.total_interests.to_f.should == 255088.98 end it "monthly_capital(1) returns capital for first payment" do - @loan.capital_for_period(1).to_f.round_down(2).abs.should == 180.80 + @loan.capital_for_period(1).to_f.abs.should == 180.80 end it "monthly_interests(1) returns capital for first payment" do - @loan.interests_for_period(1).to_f.round_down(2).abs.should == 1083.33 + @loan.interests_for_period(1).to_f.abs.should == 1083.33 end it "monthly_capital(117) returns capital for payment" do - @loan.capital_for_period(117).to_f.round_down(2).abs.should == 338.34 + @loan.capital_for_period(117).to_f.abs.should == 338.34 end it "monthly_intersts(117) returns capital for payment" do - @loan.interests_for_period(117).to_f.round_down(2).abs.should == 925.80 + @loan.interests_for_period(117).to_f.abs.should == 925.80 end it "monthly_capital(231) returns capital for payment" do - @loan.capital_for_period(231).to_f.round_down(2).abs.should == 626.33 + @loan.capital_for_period(231).to_f.abs.should == 626.33 end it "monthly_intersts(231) returns capital for payment" do - @loan.interests_for_period(231).to_f.round_down(2).abs.should == 637.81 + @loan.interests_for_period(231).to_f.abs.should == 637.81 end #it "payback(1..360) returns payback table and last item balance should be 0.0" do # table = @loan.payback(1..360) # - # table[359][:balance].to_f.round_down(2).should == 0.0 + # table[359][:balance].to_f.should == 0.0 #end end @@ -55,21 +55,21 @@ # end # # it "capital returns amount/no_installments" do - # @loan.capital.to_f.round_down(2).abs.should == 555.56 + # @loan.capital.to_f.abs.should == 555.56 # end # # it "total_interests returns sum of interests" do - # @loan.total_interests.to_f.round_down(2).should == 195541.67 + # @loan.total_interests.to_f.should == 195541.67 # end # # it "interests(1) returns intersts for 1 payment" do - # @loan.interests(1).to_f.round_down(2).should == 1083.33 + # @loan.interests(1).to_f.should == 1083.33 # end # # it "payback(1..360) returns payback table and last item balance should be 0.0" do # table = @loan.payback(1..360) # - # table[359][:balance].to_f.round_down(2).should == 0.0 + # table[359][:balance].to_f.should == 0.0 # end # #end From 4d74ed6201dd56b408d64e31abaed1313b45a2d9 Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Mon, 20 Feb 2012 13:14:05 +0100 Subject: [PATCH 08/11] fixing and rounding, optimization, added method amount for loan - amount of money to pay off, huge refactoring --- lib/monetico/loan.rb | 252 +++++++++++++++++++++++++++--------- lib/monetico/money_array.rb | 1 - spec/loan_spec.rb | 128 ++++++++++-------- 3 files changed, 262 insertions(+), 119 deletions(-) diff --git a/lib/monetico/loan.rb b/lib/monetico/loan.rb index 1478069..6476414 100644 --- a/lib/monetico/loan.rb +++ b/lib/monetico/loan.rb @@ -1,83 +1,208 @@ module Monetico class Loan include Excel - + CADENCE = { monthly: 12, weekly: 52, } - def initialize(amount, interest_rate, no_installments, cadence=:monthly, kind=:desc) + # methods + # - rounded + # - float, used in internal calculations + # - calculate for the first time, float + + def initialize(amount, interest_rate, no_installments, cadence = :monthly, kind = :desc) @amount = amount.big - @interest_rate = interest_rate.big / CADENCE[cadence] + @interest_rate = interest_rate.big / CADENCE[cadence] @no_installments = no_installments @kind = kind end - def capital + private + + # Capital - amount / number of installments + def capital + round capital_real + end + + public :capital + + def capital_real + @capital = calculate_capital if @capital.nil? + @capital + end + + def calculate_capital @amount / @no_installments end + # Total amount of interests def total_interests + round total_interests_real + end + + public :total_interests + + def total_interests_real + @total_interests = calculate_total_interests if @total_interests.nil? + @total_interests + end + + def calculate_total_interests if const? par = (1 + @interest_rate) ** @no_installments - payback_amount = @amount * @interest_rate * par / (par - 1) - - payback_amount * @no_installments - @amount + payback_amount = @amount * @interest_rate * par / (par - 1) + payback_amount * @no_installments - @amount else - 0.5.big * @interest_rate * @no_installments * (@amount + capital) + 0.5.big * @interest_rate * @no_installments * (@amount + capital_real) end end + # Interests for period/installment def interests(idx) + round interests_real(idx) + end + + public :interests + + def interests_real(idx) + @interests = Array.new if @interests.nil? + @interests[idx] = calculate_interests(idx) if @interests[idx].nil? + @interests[idx] + end + + # little refactoring + alias_method :interests_for_period, :interests + + def calculate_interests(idx) if const? - interests_for_period(idx) + ipmt(@interest_rate, idx, @no_installments, @amount).abs else - (@amount - (idx - 1) * capital) * @interest_rate + (@amount - (idx - 1) * capital_real) * @interest_rate end end - def payback(range) - from = range.begin - to = range.end - + # Monthly payment + def monthly_payment + round monthly_payment_real + end + + public :monthly_payment + + def monthly_payment_real + @monthly_payment = calculate_monthly_payment if @monthly_payment_float.nil? + @monthly_payment + end + + def calculate_monthly_payment + pmt(@interest_rate, @no_installments, @amount).abs + end + + # Capital for period + def capital_for_period(idx) + round capital_for_period_real(idx) + end + + public :capital_for_period + + def capital_for_period_real(idx) + # only for desc + return capital_real if not const? + + # only for const + @capitals = Array.new if @capitals.nil? + @capitals[idx] = calculate_capital_for_period(idx) if @capitals[idx].nil? + @capitals[idx] + end + + def calculate_capital_for_period(idx) + ppmt(@interest_rate, idx, @no_installments, @amount).abs + end + + # Amount for period + def amounts(idx) + capital_for_period(idx) + interests(idx) + end + + public :amounts + + def const? + @kind == :const + end + + public 'const?' + + # round money value + def round(v) + MoneyArray.money_round_value(v) + end + + # Loan debug + def to_s + s = "Loan\n" + table = payback_all + table.each_with_index do |t, i| + s += "#{t[:no]}: #{t[:amount].to_f};\t#{t[:balance].to_f};\t#{t[:capital].to_f};\t#{t[:interests].to_f}\n" + end + return s + end + + public :to_s + + # Paybacks items + # all payback items for all + def calculate_payback + from = 1 + to = @no_installments + range = (from..to) + current_amount = 0.0 - + if const? par = (1 + @interest_rate) ** @no_installments - + res = range.map do |n| - current_amount += monthly_payment - { no: n, interests: interests(n), amount: monthly_payment, capital: capital_for_period(n), balance: @amount + total_interests - current_amount} + current_amount += monthly_payment_real + { no: n, interests: interests(n), amount: monthly_payment_real, capital: capital_for_period(n), balance: @amount + total_interests_real - current_amount } end - - res = round_calculation(res) - return res else res = range.map do |n| - amount = capital + interests(n) + amount = capital_real + interests(n) current_amount += amount - { no: n, interests: interests(n), amount: amount, capital: capital, balance: @amount + total_interests - current_amount} + { no: n, interests: interests(n), amount: amount, capital: capital_real, balance: @amount + total_interests_real - current_amount } end - - res = round_calculation(res) - return res - end + end + @paybacks = res + @paybacks_round = round_paybacks(res) + end + + def payback_real(range) + calculate_payback if @paybacks.nil? + @paybacks[range] + end + + def payback(range) + calculate_payback if @paybacks.nil? + @paybacks_round[range] end - # all payback items for all def payback_all - payback(1..@no_installments) + calculate_payback if @paybacks.nil? + @paybacks_round end - def round_calculation(res) + public :payback_all + + public :payback + + + def round_paybacks(res) [:interests, :amount, :capital, :balance].each do |k| - tmp = MoneyArray.factory( res.collect{|r| r[k]} ) + tmp = MoneyArray.factory(res.collect { |r| r[k] }) tmp = tmp.money_round - puts tmp.to_yaml - - res.each_with_index do |r,i| + res.each_with_index do |r, i| r[k] = tmp[i] end @@ -85,37 +210,36 @@ def round_calculation(res) return res end - # not rounded - def monthly_payment_float - pmt(@interest_rate, @no_installments, @amount).abs - end + # temporary + + #def capital_real + # r(@amount / @no_installments) + #end + + #def total_interests_real_float + # if const? + # par = (1 + @interest_rate) ** @no_installments + # payback_amount = @amount * @interest_rate * par / (par - 1) + # res = payback_amount * @no_installments - @amount + # else + # res = 0.5.big * @interest_rate * @no_installments * (@amount + capital_real) + # end + # res + #end + + #def total_interests_real + # r(total_interests_float) + #end + + #def interests_real(idx) + # if const? + # res = interests_for_period(idx) + # else + # res = (@amount - (idx - 1) * capital_real) * @interest_rate + # end + # r(res) + #end - # rounded - def monthly_payment - MoneyArray.money_round_value(monthly_payment_float) - end - # not rounded - def interests_for_period_float(n) - ipmt(@interest_rate, n, @no_installments, @amount).abs - end - - # rounded - def interests_for_period(n) - MoneyArray.money_round_value(interests_for_period_float(n)) - end - - def capital_for_period_float(n) - ppmt(@interest_rate, n, @no_installments, @amount).abs - end - - def capital_for_period(n) - MoneyArray.money_round_value(capital_for_period_float(n)) - end - - def const? - @kind == :const - end - private :const? end end diff --git a/lib/monetico/money_array.rb b/lib/monetico/money_array.rb index 8b10ea0..44258df 100644 --- a/lib/monetico/money_array.rb +++ b/lib/monetico/money_array.rb @@ -47,7 +47,6 @@ def self.money_round(a) rest += real - rounded end - # puts "rest #{rest}" return result end diff --git a/spec/loan_spec.rb b/spec/loan_spec.rb index 25e7a6e..e0dae10 100644 --- a/spec/loan_spec.rb +++ b/spec/loan_spec.rb @@ -41,67 +41,87 @@ @loan.interests_for_period(231).to_f.abs.should == 637.81 end - #it "payback(1..360) returns payback table and last item balance should be 0.0" do - # table = @loan.payback(1..360) - # - # table[359][:balance].to_f.should == 0.0 - #end + # TODO + it "payback_all returns payback table and last item balance should be 0.0" do + #table = @loan.payback(1..360) # 1 or 0 should be the first payback item? + table = @loan.payback_all + + #table.size.should == 360 + + table[0][:capital].to_f.abs.should == 180.80 + table[0][:interests].to_f.abs.should == 1083.33 + #table[0][:amount].to_f.abs.should == 180.80 + #table[0][:balance].to_f.abs.should == 180.80 + + + #table.last[:capital].to_f.abs.should == 180.80 + #table.last[:interests].to_f.abs.should == 1083.33 + #table.last[:amount].to_f.abs.should == 180.80 + table.last[:balance].to_f.should == 0.0 + end end - #describe "desc loan" do - # before :all do - # @loan = Monetico::Loan.new(200000.0, 0.065, 360, :monthly, :desc) - # end - # - # it "capital returns amount/no_installments" do - # @loan.capital.to_f.abs.should == 555.56 - # end - # - # it "total_interests returns sum of interests" do - # @loan.total_interests.to_f.should == 195541.67 - # end - # - # it "interests(1) returns intersts for 1 payment" do - # @loan.interests(1).to_f.should == 1083.33 - # end + describe "desc loan" do + before :all do + @loan = Monetico::Loan.new(200000.0, 0.065, 360, :monthly, :desc) + end + + it "capital returns amount/no_installments" do + @loan.capital.to_f.abs.should == 555.56 + end + + it "total_interests returns sum of interests" do + @loan.total_interests.to_f.should == 195541.67 + end + + it "interests(1) returns intersts for 1 payment" do + @loan.interests(1).to_f.should == 1083.33 + end + + it "amount(1) returns amount for 1 payment" do + @loan.amounts(1).to_f.should == 1638.89 + end + + it "payback_all returns payback table and last item balance should be 0.0" do + table = @loan.payback_all + table[359][:balance].to_f.should == 0.0 + end + + it "can return debug string using to_s" do + @loan.to_s.should be_kind_of(String) + end + + end + + #it "should calculate loan" do + # amount = 1000.0 + # interest_rate = 0.2 + # number_of_installments = 3 + # #cadence = :weekly + # cadence = :monthly + # kind = :const + # #kind = :desc # - # it "payback(1..360) returns payback table and last item balance should be 0.0" do - # table = @loan.payback(1..360) + # loan_calc = Monetico::Loan.new(amount, interest_rate, number_of_installments, cadence, kind) + # puts loan_calc.to_yaml # - # table[359][:balance].to_f.should == 0.0 + # loan_calc.payback(1..number_of_installments).each do |l| + # #puts lo_nu.inspect + # puts l[:amount].to_f + # puts l[:interests].to_f + # puts l[:capital].to_f + # puts l[:balance].to_f + # puts "*" + # #payback_items.create( + # # number: lo_nu[:no], + # # pay_day: created_at + lo_nu[:no].send(period), + # # interests: lo_nu[:interests], + # # capital: lo_nu[:capital], + # # balance: lo_nu[:balance] + # #) # end - # #end - it "should calculate loan" do - amount = 1000.0 - interest_rate = 0.2 - number_of_installments = 3 - #cadence = :weekly - cadence = :monthly - kind = :const - #kind = :desc - - loan_calc = Monetico::Loan.new(amount, interest_rate, number_of_installments, cadence, kind) - puts loan_calc.to_yaml - - loan_calc.payback(1..number_of_installments).each do |l| - #puts lo_nu.inspect - puts l[:amount].to_f - puts l[:interests].to_f - puts l[:capital].to_f - puts l[:balance].to_f - puts "*" - #payback_items.create( - # number: lo_nu[:no], - # pay_day: created_at + lo_nu[:no].send(period), - # interests: lo_nu[:interests], - # capital: lo_nu[:capital], - # balance: lo_nu[:balance] - #) - end - end - end From 52dbf8ef2ebb9030a6b26de5e9370942e3896d87 Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Mon, 20 Feb 2012 14:05:23 +0100 Subject: [PATCH 09/11] cleaning --- .gitignore | 1 + lib/monetico/money_array.rb | 1 + monetico.gemspec | 4 ++++ spec/loan_spec.rb | 8 ++++++++ spec/money_round_spec.rb | 11 ++++++----- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d87d4be..12ff7e0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .bundle .config .yardoc +Gemfile Gemfile.lock InstalledFiles _yardoc diff --git a/lib/monetico/money_array.rb b/lib/monetico/money_array.rb index 44258df..878f504 100644 --- a/lib/monetico/money_array.rb +++ b/lib/monetico/money_array.rb @@ -1,5 +1,6 @@ module Monetico class MoneyArray < Array + # round money values to proper precision, ... def money_round return self.class.money_round(self) end diff --git a/monetico.gemspec b/monetico.gemspec index 3aba412..86014d7 100644 --- a/monetico.gemspec +++ b/monetico.gemspec @@ -21,4 +21,8 @@ Gem::Specification.new do |gem| gem.add_development_dependency "rspec" gem.add_development_dependency "rake" + + gem.add_development_dependency "rdoc" + gem.add_development_dependency "shoulda" + gem.add_development_dependency "simplecov" end diff --git a/spec/loan_spec.rb b/spec/loan_spec.rb index e0dae10..f05f937 100644 --- a/spec/loan_spec.rb +++ b/spec/loan_spec.rb @@ -83,6 +83,14 @@ @loan.amounts(1).to_f.should == 1638.89 end + it "interests(123) returns intersts for 1 payment" do + @loan.interests(123).to_f.should == 716.20 + end + + it "amount(123) returns amount for 1 payment" do + @loan.amounts(123).to_f.should == 1271.76 + end + it "payback_all returns payback table and last item balance should be 0.0" do table = @loan.payback_all table[359][:balance].to_f.should == 0.0 diff --git a/spec/money_round_spec.rb b/spec/money_round_spec.rb index f61c572..0137fcf 100644 --- a/spec/money_round_spec.rb +++ b/spec/money_round_spec.rb @@ -9,12 +9,12 @@ ma = Monetico::MoneyArray.new ma << 10.001 ma << 9.999 - puts ma.class ma.money_round.each do |m| # precision check rest = (m * 100.00) % 1 - puts "#{m} - rest #{rest}" + #puts "#{m} - rest #{rest}" + rest.should == 0.0 end end @@ -40,14 +40,15 @@ ma << BigDecimal.new("333.3029778708694") ma << BigDecimal.new("338.85802750205056") - puts ma.array_sum - ma.money_round.each do |m| # precision check rest = (m * 100.00) % 1 - puts "#{m} - rest #{rest}" + #puts "#{m} - rest #{rest}" + rest.should == 0.0 end + # sum after rounding + ma.money_round.array_sum.should == 1000.0 end end From d05e153ee6a01ae7cea736d48ce784edc301c04c Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Mon, 20 Feb 2012 14:11:09 +0100 Subject: [PATCH 10/11] cleaning --- .rvmrc | 5 ++--- Rakefile | 20 +------------------- lib/monetico/loan.rb | 30 ------------------------------ spec/loan_spec.rb | 29 ----------------------------- spec/money_round_spec.rb | 14 -------------- 5 files changed, 3 insertions(+), 95 deletions(-) diff --git a/.rvmrc b/.rvmrc index f357ddc..ca9e207 100644 --- a/.rvmrc +++ b/.rvmrc @@ -1,4 +1,3 @@ -#rvm_gemset_create_on_use_flag=1 -#rvm gemset use monetico - +rvm_gemset_create_on_use_flag=1 +rvm gemset use monetico rvm use 1.9.3@monetico --create diff --git a/Rakefile b/Rakefile index 380d971..0d17dde 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ # encoding: utf-8 #!/usr/bin/env rake -#require "bundler/gem_tasks" +require "bundler/gem_tasks" require 'rubygems' require 'bundler' @@ -14,24 +14,6 @@ rescue Bundler::BundlerError => e end require 'rake' -#require 'jeweler' -#Jeweler::Tasks.new do |gem| -# # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options -# gem.name = "gem name" -# gem.homepage = "http://github.com/zaiste/monetico" -# gem.license = "licence" -# gem.summary = %Q{summary} -# gem.description = %Q{desc} -# gem.email = "..." -# gem.authors = ["..."] -# # dependencies defined in Gemfile -# -# gem.files = FileList[ -# "[A-Z]*", "{bin,generators,lib,test}/**/*" -# ] -#end -#Jeweler::RubygemsDotOrgTasks.new - require 'rspec/core' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |spec| diff --git a/lib/monetico/loan.rb b/lib/monetico/loan.rb index 6476414..2c3778f 100644 --- a/lib/monetico/loan.rb +++ b/lib/monetico/loan.rb @@ -210,36 +210,6 @@ def round_paybacks(res) return res end - # temporary - - #def capital_real - # r(@amount / @no_installments) - #end - - #def total_interests_real_float - # if const? - # par = (1 + @interest_rate) ** @no_installments - # payback_amount = @amount * @interest_rate * par / (par - 1) - # res = payback_amount * @no_installments - @amount - # else - # res = 0.5.big * @interest_rate * @no_installments * (@amount + capital_real) - # end - # res - #end - - #def total_interests_real - # r(total_interests_float) - #end - - #def interests_real(idx) - # if const? - # res = interests_for_period(idx) - # else - # res = (@amount - (idx - 1) * capital_real) * @interest_rate - # end - # r(res) - #end - end end diff --git a/spec/loan_spec.rb b/spec/loan_spec.rb index f05f937..13d0adf 100644 --- a/spec/loan_spec.rb +++ b/spec/loan_spec.rb @@ -102,34 +102,5 @@ end - #it "should calculate loan" do - # amount = 1000.0 - # interest_rate = 0.2 - # number_of_installments = 3 - # #cadence = :weekly - # cadence = :monthly - # kind = :const - # #kind = :desc - # - # loan_calc = Monetico::Loan.new(amount, interest_rate, number_of_installments, cadence, kind) - # puts loan_calc.to_yaml - # - # loan_calc.payback(1..number_of_installments).each do |l| - # #puts lo_nu.inspect - # puts l[:amount].to_f - # puts l[:interests].to_f - # puts l[:capital].to_f - # puts l[:balance].to_f - # puts "*" - # #payback_items.create( - # # number: lo_nu[:no], - # # pay_day: created_at + lo_nu[:no].send(period), - # # interests: lo_nu[:interests], - # # capital: lo_nu[:capital], - # # balance: lo_nu[:balance] - # #) - # end - #end - end diff --git a/spec/money_round_spec.rb b/spec/money_round_spec.rb index 0137fcf..902ebfa 100644 --- a/spec/money_round_spec.rb +++ b/spec/money_round_spec.rb @@ -20,20 +20,6 @@ end it "should round simple loan results" do - #344.50566129375136 - #16.666666666666668 - #327.8389946270847 - #689.0113225874981 - #* - #344.50566129375136 - #11.20268342288194 - #333.3029778708694 - #344.5056612937467 - #* - #344.50566129375136 - #5.647633791700789 - #338.85802750205056 - ma = Monetico::MoneyArray.new # also testes using floats ma << BigDecimal.new("327.8389946270847") From 4d600e9172aa2da60ea179b37175eecf26d52160 Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Mon, 20 Feb 2012 14:12:14 +0100 Subject: [PATCH 11/11] cleaning --- .gitignore | 1 - Gemfile | 6 ------ 2 files changed, 7 deletions(-) diff --git a/.gitignore b/.gitignore index 12ff7e0..d87d4be 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ .bundle .config .yardoc -Gemfile Gemfile.lock InstalledFiles _yardoc diff --git a/Gemfile b/Gemfile index 1906b91..b6cc049 100644 --- a/Gemfile +++ b/Gemfile @@ -4,10 +4,4 @@ source 'http://rubygems.org' gemspec group :development, :test do - gem "rdoc" - gem "shoulda" - gem "bundler", "~> 1.0.0" - gem "rspec" - gem "jeweler" #, "~> 1.6.4" - gem "simplecov", ">= 0" end