summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@serenitascapital.com>2016-03-08 14:50:37 -0500
committerGuillaume Horel <guillaume.horel@serenitascapital.com>2016-03-08 14:50:37 -0500
commita9f43bc6ec805c93a36189b90bbdf0f9dbb17813 (patch)
treee35e7767632c3f8f5355eeae11a36c3256636bb5 /tests
parent8e57746d75a9e65436db6e8b589fc553c4a4989b (diff)
downloadlossdistrib-a9f43bc6ec805c93a36189b90bbdf0f9dbb17813.tar.gz
start using testthat for testing
Diffstat (limited to 'tests')
-rw-r--r--tests/testthat.R4
-rw-r--r--tests/testthat/test_lossdistrib.R26
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/testthat.R b/tests/testthat.R
new file mode 100644
index 0000000..48ccaaf
--- /dev/null
+++ b/tests/testthat.R
@@ -0,0 +1,4 @@
+library(testthat)
+library(lossdistrib)
+
+test_check("lossdistrib")
diff --git a/tests/testthat/test_lossdistrib.R b/tests/testthat/test_lossdistrib.R
new file mode 100644
index 0000000..074cbf2
--- /dev/null
+++ b/tests/testthat/test_lossdistrib.R
@@ -0,0 +1,26 @@
+library(lossdistrib)
+p <- runif(1000)
+S <- runif(1000)
+issuer.weights <- rep(1/1000,1000)
+
+run1 <- system.time(for(i in 1:1000){
+ lossdistC(p, issuer.weights, S, 301)
+})
+cat("simple lossdist", run1["elapsed"], "\n")
+
+S <- matrix(runif(1000*500), 1000, 500)
+rho <- rep(0.45, 1000)
+temp <- GHquad(500)
+Z <- temp$Z
+w <- temp$w
+
+test <- lossdistCZ(p, issuer.weights, S, 301, FALSE, rho, Z)
+p <- matrix(runif(100*25), 100, 25)
+issuer.weights <- rep(1/100, 100)
+S <- runif(100)
+
+cat("I'm here")
+rho <- rep(0.45, 100)
+test <- BClossdistC(p, issuer.weights, 1-S, rho, temp$Z, temp$w)
+# the blas function should be roughly twice as fast
+cat("blas lossdist", run2["elapsed"], "\n")