organized code into Smr module
[smr.git] / gui / test / functional / smr_cashflowlog_test.rb
blob58934a47f621458ef0bf412b70b277195ba1c189
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'
20     
21     class CashflowLogTest < ActionController::TestCase
22     
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=>-35591.296},
29             ]
30     
31             to_test.each do |t|
32                 # startdate at January 1st 2001 means we ask for cashflows from "All Time"
33                 cf = CashflowLog.new(Time.new(2001,1,1), t[:at], 1)
34     
35                 if t[:total] == false then
36                     assert_nil cf.each.first, 'cashflow that should not be here %s' % t[:at]
37                 else
38                     assert_in_delta t[:total], cf.total, 0.0001, 'wrong cashflow total on %s ' % t[:at]
39                 end
40             end
41         end
42     
43         test 'cashflow filterd at specific date' do
44             to_test = [
45                 {:at=>Time.new(2003,5,23), :total=>false, :filter=>:dividend},
46                 {:at=>Time.new(2004,9,23), :total=>-15634.046, :filter=>:orders},
47                 {:at=>Time.new(2007,5,23), :total=>880.55, :filter=>:dividend},
48                 {:at=>Time.new(2008,1,1), :total=>109.42, :filter=>:provision},
49             ]
50     
51             to_test.each do |t|
52                 cf = CashflowLog.new(Time.new(2001,1,1), t[:at], 1)
53                 cf.set_filter(t[:filter])
54     
55                 if t[:total] == false then
56                     assert_nil cf.each.first, 'cashflow that should not be here on %s' % t[:at] 
57                 else
58                     assert_in_delta t[:total], cf.total, 0.0001, 'wrong cashflow total on %s ' % t[:at]
59                 end
60             end
61         end
62     
63         test 'unknown filter' do
64             cf = CashflowLog.new(Time.new(2001,1,1), Time.now, 1)
65             assert_raise RuntimeError do
66                 cf.set_filter(:this_filter_does_not_exist_and_never_will)
67             end
68         end
69     end
71 end # module