tests/testthat/test-knn.r

context('kNN integrity')


test_that('knn works the same as FNN', {
	skip_if_not_installed('FNN')
	
	e <- as.matrix(datasets::mtcars)
	
	r_destiny <- find_knn(e, 5L)
	r_fnn <- FNN::get.knn(e, 5L)
	
	dimnames(r_destiny$index) <- dimnames(r_destiny$dist) <- NULL
	expect_equal(r_destiny$dist, r_fnn$nn.dist)
})


test_that('knnx works the same as to FNN', {
	skip_if_not_installed('FNN')
	
	e <- as.matrix(datasets::mtcars)
	am <- factor(e[, 'am'], labels = c('automatic', 'manual'))
	
	r_destiny <- find_knn(e[am == 'manual', ], 5L, query = e[am == 'automatic', ])
	r_fnn <- FNN::get.knnx(e[am == 'manual', ], e[am == 'automatic', ], 5L)
	
	dimnames(r_destiny$index) <- dimnames(r_destiny$dist) <- NULL
	expect_equal(r_destiny$dist, r_fnn$nn.dist)
})

Try the knn.covertree package in your browser

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

knn.covertree documentation built on Oct. 30, 2019, 11:37 a.m.