library(s2dverification)
#library(multiApply)
source('/home/Earth/aho/aho-testtest/s2dv/test-compare/Trend/Trend_old.R')
source('/home/Earth/aho/aho-testtest/s2dv/test-compare/Trend/Trend_new.R')
#source('/home/Earth/aho/s2dverification/R/Trend.R')

#test1
  dat <- array(c(1:100) + rnorm(100), dim = c(5, 4, 5))
  res1 <- Trend_new(dat)$trend
  res2 <- Trend_old(dat)$trend

  print("Test 1: ")
  print(all.equal(res1[,1:4,], res2, check.attributes = FALSE))

#test2
  dat <- array(c(1:200) + rnorm(200), dim = c(5, 4, 5, 2))
  res1 <- Trend_new(dat, pldegree = 1, conf = FALSE)$trend
  res2 <- Trend_old(dat, conf = FALSE)$trend

  print("Test 2: ")
  print(all.equal(res1[,1:2,,], res2, check.attributes = FALSE))

#test3
  dat <- array(c(1:200) + rnorm(200), dim = c(5, 4, 5, 2))
  res1 <- Trend_new(dat, posTR = 4, conf = FALSE)$trend
  res2 <- Trend_old(dat, posTR = 4, conf = FALSE)$trend

  print("Test 3: ")
  print(all.equal(res1[,,,1:2], res2, check.attributes = FALSE))

#test4
  dat <- array(c(1:200) + rnorm(200), dim = c(5, 4, 5, 2))
  res1 <- Trend_new(dat, interval = 2)$trend #, conf = FALSE)
  res2 <- Trend_old(dat, interval = 2)$trend #, conf = FALSE)

  print("Test 4: ")
  print(all.equal(res1[,1:4,,], res2, check.attributes = FALSE))

#test5
  res1 <- Trend_new(dat, interval = 2)$detrend
  res2 <- Trend_old(dat, interval = 2)$detrend
  print("Test 5: ")
  print(all.equal(res1, res2, check.attributes = FALSE))

print('All tests pass!')
