tests/testthat/test_normalization_for_negative_values_data.R

context("Normalization for negative values data")
library(ERTMon)

numberOfEntities <- 10
nIntervals <- 5

testData <-
  ERTMonSimpleTestData( numberOfEntities = numberOfEntities, numberOfVariables = 5, 
                        timeInterval = 900, numberOfTimeCells = 40, randomStartTimesQ = TRUE, 
                        variableFunction = "Random", 
                        exportDirectoryName = NULL )

testData$ComputationSpecification <-
  testData$ComputationSpecification %>% 
  dplyr::filter( Aggregation.function != "Range" )

testData$ComputationSpecification$Aggregation.interval.length <- 3*900
testData$ComputationSpecification$Max.history.length <- nIntervals * testData$ComputationSpecification$Aggregation.interval.length
testData$ComputationSpecification$Normalization.scope <- "Variable"
testData$ComputationSpecification$Normalization.function <- "MaxAbs"

testData$EventRecords$Value <- (-10) * testData$EventRecords$Value

ertmon0 <-
  ERTMonUnit() %>%
  ERTMonSetEventRecords( testData$EventRecords ) %>%
  ERTMonSetEntityAttributes( testData$EntityAttr ) %>%
  ERTMonSetComputationSpecification( testData$ComputationSpecification ) %>% 
  ERTMonProcessEventRecords( alignmentSpec = "MinTime" )

qDF <- ertmon0 %>% ERTMonTakeTrasformedData()

test_that("Expected test data properties", {
  expect_equal( mean( testData$ComputationSpecification$Aggregation.function %in% c("Max", "Mean", "Min") ), 1 )
  expect_equal( mean( testData$EventRecords$Value <= 0 ), 1 )
}) 

test_that("Max under 1", {
  expect_equal( mean( qDF$AValue >= -1 ), 1 )
  expect_equal( mean( abs(qDF$AValue) <= 1 ), 1 )
}) 
antononcube/ERTMon-R documentation built on Oct. 14, 2021, 2:27 p.m.