From ef3ac41bc423bbf96a89b754c231f48191457e1c Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Tue, 26 Jul 2022 11:51:45 +0200 Subject: [PATCH] Updated unit tests to use C++ version (#198) --- .../testthat/test-smc_updated_new_item_rank.R | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/tests/testthat/test-smc_updated_new_item_rank.R b/tests/testthat/test-smc_updated_new_item_rank.R index 6bb2dd87..ea7e589a 100644 --- a/tests/testthat/test-smc_updated_new_item_rank.R +++ b/tests/testthat/test-smc_updated_new_item_rank.R @@ -90,13 +90,14 @@ smc_test_new_user_unif <- smc_mallows_new_users( # run smc updated rankings with alpha unknown Time2 <- dim(test_dataset)[3] set.seed(994) -smc_test_updated_partial_unif1 <- smc_mallows_new_item_rank_updated_alpha_fixed( +smc_test_updated_partial_unif1 <- smc_mallows_new_item_rank_updated_cpp( alpha = 2, n_items = n_items, R_obs = test_dataset, metric = metric, leap_size = leap_size, N = N, Time = Time2, logz_estimate = logz_estimate, mcmc_kernel_app = mcmc_kernel_app, aug_method = "random", rho_samples_init = smc_test_new_user_unif$rho_samples[, , Time + 1], - aug_rankings_init = smc_test_new_user_unif$augmented_rankings + aug_rankings_init = smc_test_new_user_unif$augmented_rankings, + alpha_fixed = TRUE ) test_that("Updated item rank output is OK", { expect_is(smc_test_updated_partial_unif1, "list") @@ -106,22 +107,10 @@ test_that("Updated item rank output is OK", { expect_equal(dim(smc_test_updated_partial_unif1$augmented_rankings), c(n_users, n_items, N)) }) -# TODO: get the CPP version to work like the R version -smc_test_updated_partial_unif1_cpp <- smc_mallows_new_item_rank_updated_cpp( - alpha = 2, n_items = n_items, - R_obs = test_dataset, metric = metric, leap_size = leap_size, - N = N, Time = Time2, logz_estimate = logz_estimate, - mcmc_kernel_app = mcmc_kernel_app, aug_method = "random", - rho_samples_init = smc_test_new_user_unif$rho_samples[, , Time + 1], - aug_rankings_init = smc_test_new_user_unif$augmented_rankings, - alpha_fixed = TRUE -) -print(identical(smc_test_updated_partial_unif1_cpp, smc_test_updated_partial_unif1)) - # run smc updated rankings with alpha unknown Time2 <- dim(test_dataset)[3] set.seed(994) -smc_test_updated_partial_unif2 <- smc_mallows_new_item_rank_updated( +smc_test_updated_partial_unif2 <- smc_mallows_new_item_rank_updated_cpp( n_items = n_items, R_obs = test_dataset, metric = metric, leap_size = leap_size, N = N, Time = Time2, logz_estimate = logz_estimate, @@ -159,13 +148,14 @@ smc_test_new_user_pseudo <- smc_mallows_new_users( ) set.seed(994) -smc_test_updated_partial_pseudo1 <- smc_mallows_new_item_rank_updated_alpha_fixed( +smc_test_updated_partial_pseudo1 <- smc_mallows_new_item_rank_updated_cpp( alpha = 2, n_items = n_items, R_obs = test_dataset, metric = metric, leap_size = leap_size, N = N, Time = Time2, logz_estimate = logz_estimate, mcmc_kernel_app = mcmc_kernel_app, aug_method = "pseudolikelihood", rho_samples_init = smc_test_new_user_pseudo$rho_samples[, , Time + 1], - aug_rankings_init = smc_test_new_user_pseudo$augmented_rankings + aug_rankings_init = smc_test_new_user_pseudo$augmented_rankings, + alpha_fixed = TRUE ) test_that("Updated item rank output is OK", { expect_is(smc_test_updated_partial_pseudo1, "list") @@ -176,7 +166,7 @@ test_that("Updated item rank output is OK", { }) set.seed(994) -smc_test_updated_partial_pseudo2 <- smc_mallows_new_item_rank_updated( +smc_test_updated_partial_pseudo2 <- smc_mallows_new_item_rank_updated_cpp( n_items = n_items, R_obs = test_dataset, metric = metric, leap_size = leap_size, N = N, Time = Time2, logz_estimate = logz_estimate, @@ -186,7 +176,6 @@ smc_test_updated_partial_pseudo2 <- smc_mallows_new_item_rank_updated( rho_samples_init = smc_test_new_user_unif$rho_samples[, , Time + 1], aug_rankings_init = smc_test_new_user_unif$augmented_rankings ) - test_that("Updated item rank output (variable alpha) is OK", { expect_is(smc_test_updated_partial_pseudo2, "list") expect_length(smc_test_updated_partial_pseudo2, 4)