1
2context("Dimensionality selection")
3
4test_that("dimensionality selection works", {
5  library(igraph)
6  set.seed(42)
7
8  k <- graph.famous("zachary")
9  ev <- eigen(get.adjacency(k), only.values=TRUE)$values
10  kdim <- dim_select(ev)
11  expect_that(kdim, equals(4))
12
13  expect_that(dim_select(1:100), equals(50))
14
15  ## Some regression tests
16  expect_that(dim_select(runif(100)), equals(69))
17  expect_that(dim_select(runif(100)), equals(88))
18  expect_that(dim_select(runif(100)), equals(3))
19  expect_that(dim_select(runif(100)), equals(99))
20
21  ## Some more meaningful tests
22  x <- c(rnorm(50, mean=0, sd=1), rnorm(50, mean=5, sd=1))
23  expect_that(dim_select(x), equals(50))
24
25  x <- c(rnorm(10, mean=0, sd=1), rnorm(90, mean=2, sd=1))
26  expect_that(dim_select(x), equals(10))
27
28  x <- c(10, rnorm(99, mean=0, sd=1))
29  expect_that(dim_select(x), equals(1))
30
31  x <- c(rnorm(99, mean=0, sd=1), 10)
32  expect_that(dim_select(x), equals(99))
33})
34