added security type models, improved cashflow, bug- and layout fixes along the way
[smr.git] / gui / test / unit / smr_cashflowlog_test.rb
blob6427c7aa35b4c996e4931394ad1386705831ea26
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
7 # version.
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/>.
16 require 'test_helper'
18 module Smr  #:nodoc:
19     require 'cashflowlog'
21     class CashflowLogTest < ActiveSupport::TestCase
23         test 'cashflow at specific date' do
24             to_test = [
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}
30             ]
32             to_test.each do |t|
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]
38                 else
39                     assert_in_delta t[:total], cf.total, 0.0001, 'wrong cashflow total on %s ' % t[:at]
40                 end
41             end
42         end
44         test 'cashflow filtered at specific date' do
45             to_test = [
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},
53             ]
55             to_test.each do |t|
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]
61                 else
62                     assert_in_delta t[:total], cf.total, 0.0001, 'wrong cashflow total on %s ' % t[:at]
63                 end
64             end
65         end
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)
71             end
72         end
73     end
75 end # module