2 # This file is part of SMR.
4 # SMR is free software: you can redistribute it and/or modify it under the
5 # terms of the GNU General Public License as published by the Free Software
6 # Foundation, either version 3 of the License, or (at your option) any later
9 # SMR is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # SMR. If not, see <http://www.gnu.org/licenses/>.
21 class CashflowLogTest < ActiveSupport::TestCase
23 test 'cashflow at specific date' do
25 {:at=>Time.new(2001,6,7), :total=>false},
26 {:at=>Time.new(2003,5,23), :total=>-225.0},
27 {:at=>Time.new(2004,9,23), :total=>-15432.496},
28 {:at=>Time.new(2008,1,1), :total=>-4405.2959},
29 {:at=>Time.new(2015,3,1), :total=>-8927.4960}
33 # startdate of January 1st 2001 means we ask for cashflows from "All Time"
34 cf = CashflowLog.new(Time.new(2001,1,1), t[:at], 1)
36 if t[:total] == false then
37 assert_nil cf.each.first, 'cashflow that should not be here %s' % t[:at]
39 assert_in_delta t[:total], cf.total, 0.0001, 'wrong cashflow total on %s ' % t[:at]
44 test 'cashflow filtered at specific date' do
46 {:at=>Time.new(2003,5,23), :total=>false, :filter=>:dividend},
47 {:at=>Time.new(2004,9,23), :total=>-15634.046, :filter=>:orders},
48 {:at=>Time.new(2007,5,23), :total=>880.55, :filter=>:dividend},
49 {:at=>Time.new(2008,1,1), :total=>-24.47, :filter=>:provision},
50 {:at=>Time.new(2015,4,1), :total=>-44.32, :filter=>:provision},
51 {:at=>Time.new(2015,4,1), :total=>-35.57, :filter=>:courtage},
52 {:at=>Time.new(2015,4,1), :total=>-95.93, :filter=>:expense},
56 cf = CashflowLog.new(Time.new(2001,1,1), t[:at], 1)
57 cf.set_filter(t[:filter])
59 if t[:total] == false then
60 assert_nil cf.each.first, 'cashflow that should not be here on %s' % t[:at]
62 assert_in_delta t[:total], cf.total, 0.0001, 'wrong cashflow total on %s ' % t[:at]
67 test 'unknown filter' do
68 cf = CashflowLog.new(Time.new(2001,1,1), Time.now, 1)
69 assert_raise RuntimeError do
70 cf.set_filter(:this_filter_does_not_exist_and_never_will)