tests/testthat/test-stats_clusters.R

library(testthat)
#------------------------------------------------------
## Clustering on the Sphere
## 

# Test 1: Test for summary_stat
test_that("extract_stat test", {
   
   # dimension = 2
   dat<-rbind(matrix(rnorm(50),ncol=2), 
              matrix(rnorm(50,4),ncol=2), 
              matrix(rnorm(50,2),ncol=2))
   y <- rep(c(1,2,3),each=25)
   pkbd_res<- pkbc(dat, c(2,3))
   
   expect_error(stats_clusters(pkbd_res, 4), 
   "The provided pkbc object does not contain results for the requested
           number of clusters")
   res1 <- stats_clusters(pkbd_res, 3)
   expect_equal(length(res1), 2)
   
   # dimension = 3
   dat<-rbind(matrix(rnorm(60),ncol=3), 
              matrix(rnorm(60,4),ncol=3), 
              matrix(rnorm(60,2),ncol=3))
   y <- rep(c(1,2,3),each=20)
   pkbd_res<- pkbc(dat, c(2,3))
   
   res1 <- stats_clusters(pkbd_res, 2)
   res2 <- stats_clusters(pkbd_res, 3)
   expect_equal(length(res1), 3)
   expect_equal(length(res2), 3)
   
   # dimension = 4
   dat<-rbind(matrix(rnorm(60),ncol=4), 
              matrix(rnorm(60,4),ncol=4), 
              matrix(rnorm(60,2),ncol=4))
   y <- rep(c(1,2,3),each=15)
   pkbd_res<- pkbc(dat, c(2,3))
   
   res1 <- stats_clusters(pkbd_res, 2)
   res2 <- stats_clusters(pkbd_res, 3)
   expect_equal(length(res1), 4)
   expect_equal(length(res2), 4)
   
})

Try the QuadratiK package in your browser

Any scripts or data that you put into this service are public.

QuadratiK documentation built on Oct. 29, 2024, 5:08 p.m.