1 2# Rmetrics is free software; you can redistribute it and/or 3# modify it under the terms of the GNU Library General Public 4# License as published by the Free Software Foundation; either 5# version 2 of the License, or (at your option) any later version. 6# 7# Rmetrics is distributed in the hope that it will be useful, 8# but WITHOUT ANY WARRANTY; without even the implied warranty of 9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10# GNU Library General Public License for more details. 11# 12# You should have received a copy of the GNU Library General 13# Public License along with this library; if not, write to the 14# Free Foundation, Inc., 59 Temple Place, Suite 330, Boston, 15# MA 02111-1307 USA 16 17 18################################################################################ 19 20 21test.time = 22function() 23{ 24 # Generate nivariate daily random sequence 25 set.seed(4711) 26 data = round(rnorm(12), 2) 27 charvec = timeCalendar(2006) 28 uTS = timeSeries(data, charvec, units = "uTS") 29 uTS 30 31 # Get Positions: 32 POS = time(uTS) 33 POS 34 checkIdentical(charvec, POS) 35 36 # Return Value: 37 return() 38} 39 40 41# ------------------------------------------------------------------------------ 42 43 44"test.time<-" = 45function() 46{ 47 # Generate nivariate daily random sequence 48 set.seed(4711) 49 data = round(rnorm(12), 2) 50 charvec = timeCalendar(2006) 51 uTS = timeSeries(data, charvec, units = "uTS") 52 uTS 53 54 # Add one Day to Positions: 55 POS = time(uTS) 56 time(uTS) <- POS + 24*3600 57 uTS 58 59 # Return Value: 60 return() 61} 62 63 64# ------------------------------------------------------------------------------ 65 66 67test.timeSeriesOrdering = 68function() 69{ 70 # sample.timeSeries - Resamples a 'timeSeries' object in time 71 # sort.timeSeries - Sorts reverts a 'timeSeries' object in time 72 # rev.timeSeries - Reverts a 'timeSeries' object in time 73 # start.timeSeries - Extracts start date of a 'timeSeries' object 74 # end.timeSeries - Extracts end date of a 'timeSeries' object 75 76 # Generate univariate monthly random sequence: 77 set.seed(4711) 78 data = cbind(1:12, round(rnorm(12), 2)) 79 positions = timeCalendar(2006) 80 uTS = timeSeries(data, positions) 81 uTS 82 83 # Sample/Sort: 84 target = uTS 85 target 86 # current = sort(sample(uTS)) 87 # current 88 # checkIdentical(target, current) 89 90 # Revert: 91 target = uTS 92 target 93 current = rev(rev(uTS)) 94 current 95 checkTrue(!sum(target - current)) 96 97 # Start/End date of Series: 98 start(uTS) 99 end(uTS) 100 101 # Return Value: 102 return() 103} 104 105 106################################################################################ 107 108