[Eventstudies-commits] r79 - pkg/tests
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jul 16 07:35:48 CEST 2013
Author: chiraganand
Date: 2013-07-16 07:35:46 +0200 (Tue, 16 Jul 2013)
New Revision: 79
Added:
pkg/tests/unit_tests.R
Modified:
pkg/tests/test_eventstudy.R
pkg/tests/test_inr_inference.R
Log:
Created test functions for existing tests, added unit testing code using RUnit.
Modified: pkg/tests/test_eventstudy.R
===================================================================
--- pkg/tests/test_eventstudy.R 2013-07-16 05:33:30 UTC (rev 78)
+++ pkg/tests/test_eventstudy.R 2013-07-16 05:35:46 UTC (rev 79)
@@ -1,5 +1,6 @@
library(eventstudies)
+test.eventstudy <- function() {
# An example dataset, with 3 firms --
p <- structure(c(33.16, 34.0967, 35.3683, 34.46, 34.17, 35.89, 36.19,
37.1317, 36.7033, 37.7933, 37.8533, 285.325, 292.6,
@@ -42,7 +43,7 @@
# But when we go to width=2, column 1 and 3 drop off because they have
# only 1 obs before & after the event date respectively.
a <- phys2eventtime(p, eventslist,width=2)
-all.equal(a, structure(list(z.e = structure(c(NA, NA, NA, NA, 285.325,
+test.result <- all.equal(a, structure(list(z.e = structure(c(NA, NA, NA, NA, 285.325,
292.6, 290.025, 286.2, 290.075, 295.05,
289.325, 285.625, 293.7, 298.5, 289.05,
NA, NA, NA, NA), index = -9:9, class =
@@ -51,3 +52,15 @@
"unitmissing", "wdatamissing",
"wrongspan"), class = "factor")), .Names
= c("z.e", "outcomes" )))
+s <- structure(list(z.e = structure(c(NA, NA, NA, NA, 285.325,
+ 292.6, 290.025, 286.2, 290.075, 295.05,
+ 289.325, 285.625, 293.7, 298.5, 289.05,
+ NA, NA, NA, NA), index = -9:9, class =
+ "zoo"), outcomes = structure(c(3L, 1L,
+ 3L, 4L, 4L, 2L), .Label = c("success",
+ "unitmissing", "wdatamissing",
+ "wrongspan"), class = "factor")), .Names
+ = c("z.e", "outcomes" ))
+
+checkTrue(isTRUE(test.result))
+}
Modified: pkg/tests/test_inr_inference.R
===================================================================
--- pkg/tests/test_inr_inference.R 2013-07-16 05:33:30 UTC (rev 78)
+++ pkg/tests/test_inr_inference.R 2013-07-16 05:35:46 UTC (rev 79)
@@ -1,22 +1,31 @@
library(eventstudies)
+
+test.inr.inference <- function() {
data(inr)
inr_returns <- diff(log(inr))[-1]
-eventslist<-data.frame(unit=rep("inr",10),
- when=as.Date(c(
- "2010-04-20","2010-07-02","2010-07-27",
- "2010-09-16","2010-11-02","2011-01-25",
- "2011-03-17","2011-05-03","2011-06-16",
- "2011-07-26")
+eventslist <- data.frame(unit=rep("inr",10),
+ when=as.Date(c(
+ "2010-04-20","2010-07-02","2010-07-27",
+ "2010-09-16","2010-11-02","2011-01-25",
+ "2011-03-17","2011-05-03","2011-06-16",
+ "2011-07-26")
+ )
)
- )
event_time_data <- phys2eventtime(inr_returns,eventslist,width=10)
w <- window(event_time_data$z.e,start=-10,end=10)
-all.equal(inference.Ecar(w)[,2],c(-.000015327,-.002526819,.0011990000,.001193535,.001846734,
- -.000105473,-.001659772,.001644518,-0.001325236,.001546369,
- -.000809734,-.001499191,-.000289414,-.000003273,-.000416662,
- -.001150000,-.000759748,.002306711,-.000487299,.001122457,
- .000635890))
+test.result <- all.equal(inference.Ecar(w)[,2],
+ c(-0.00215361156303362, -0.00040191670837042, 0.00171845148444985,
+ 0.00143799970419951, 0.00149260146357282, -0.00284892904228684,
+ 0.0013220811191847, -0.000634983205805195, 0.00115930378269389,
+ -0.000508755768685365, -0.00190621828611177, 0.000128303517790052,
+ -0.000547070723466092, 0.000463708708964017, -0.00108666428087325,
+ -0.00121321855159642, 0.00216769754166339, -0.000166340225607797,
+ 0.00117626759805196, 0.000207307545758795, 0.000602629204764948
+ ))
+
+checkTrue(isTRUE(test.result))
+}
Added: pkg/tests/unit_tests.R
===================================================================
--- pkg/tests/unit_tests.R (rev 0)
+++ pkg/tests/unit_tests.R 2013-07-16 05:35:46 UTC (rev 79)
@@ -0,0 +1,9 @@
+library(RUnit)
+
+testsuite <- defineTestSuite("Event Studies Test Suite",
+ dirs = ".",
+ testFileRegexp = "^test_.*\\.R$",
+ testFuncRegexp = "^.*$"
+ )
+
+testresult <- runTestSuite(testsuite)
More information about the Eventstudies-commits
mailing list