From 28821433125ff4f1d24a84f614841cb8ba356a18 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Sun, 1 Nov 2020 19:22:44 -0600 Subject: [PATCH] [R-package] fix learning-to-rank tests on Solaris (fixes #3513) --- .../tests/testthat/test_learning_to_rank.R | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/R-package/tests/testthat/test_learning_to_rank.R b/R-package/tests/testthat/test_learning_to_rank.R index 0d6303139500..7cf0d25372ab 100644 --- a/R-package/tests/testthat/test_learning_to_rank.R +++ b/R-package/tests/testthat/test_learning_to_rank.R @@ -116,19 +116,51 @@ test_that("learning-to-rank with lgb.cv() works as expected", { # first and last value of each metric should be as expected ndcg1_values <- c(0.675, 0.725, 0.65, 0.725, 0.75, 0.725, 0.75, 0.725, 0.75, 0.75) - expect_true(all(abs(unlist(eval_results[["ndcg@1"]][["eval"]]) - ndcg1_values) < TOLERANCE)) + #expect_true(all(abs(unlist(eval_results[["ndcg@1"]][["eval"]]) - ndcg1_values) < TOLERANCE)) + + expect_equal(eval_results[["ndcg@1"]][["eval"]][[1L]], ndcg1_values[[1L]]) + expect_equal(eval_results[["ndcg@1"]][["eval"]][[2L]], ndcg1_values[[2L]]) + expect_equal(eval_results[["ndcg@1"]][["eval"]][[3L]], ndcg1_values[[3L]]) + expect_equal(eval_results[["ndcg@1"]][["eval"]][[4L]], ndcg1_values[[4L]]) + expect_equal(eval_results[["ndcg@1"]][["eval"]][[5L]], ndcg1_values[[5L]]) + expect_equal(eval_results[["ndcg@1"]][["eval"]][[6L]], ndcg1_values[[6L]]) + expect_equal(eval_results[["ndcg@1"]][["eval"]][[7L]], ndcg1_values[[7L]]) + expect_equal(eval_results[["ndcg@1"]][["eval"]][[8L]], ndcg1_values[[8L]]) + expect_equal(eval_results[["ndcg@1"]][["eval"]][[9L]], ndcg1_values[[9L]]) + expect_equal(eval_results[["ndcg@1"]][["eval"]][[10L]], ndcg1_values[[10L]]) ndcg2_values <- c( 0.6556574, 0.6669721, 0.6306574, 0.6476294, 0.6629581, 0.6476294, 0.6629581, 0.6379581, 0.7113147, 0.6823008 ) - expect_true(all(abs(unlist(eval_results[["ndcg@2"]][["eval"]]) - ndcg2_values) < TOLERANCE)) + #expect_true(all(abs(unlist(eval_results[["ndcg@2"]][["eval"]]) - ndcg2_values) < TOLERANCE)) + + expect_equal(eval_results[["ndcg@2"]][["eval"]][[1L]], ndcg2_values[[1L]]) + expect_equal(eval_results[["ndcg@2"]][["eval"]][[2L]], ndcg2_values[[2L]]) + expect_equal(eval_results[["ndcg@2"]][["eval"]][[3L]], ndcg2_values[[3L]]) + expect_equal(eval_results[["ndcg@2"]][["eval"]][[4L]], ndcg2_values[[4L]]) + expect_equal(eval_results[["ndcg@2"]][["eval"]][[5L]], ndcg2_values[[5L]]) + expect_equal(eval_results[["ndcg@2"]][["eval"]][[6L]], ndcg2_values[[6L]]) + expect_equal(eval_results[["ndcg@2"]][["eval"]][[7L]], ndcg2_values[[7L]]) + expect_equal(eval_results[["ndcg@2"]][["eval"]][[8L]], ndcg2_values[[8L]]) + expect_equal(eval_results[["ndcg@2"]][["eval"]][[9L]], ndcg2_values[[9L]]) + expect_equal(eval_results[["ndcg@2"]][["eval"]][[10L]], ndcg2_values[[10L]]) ndcg3_values <- c( 0.6484639, 0.6571238, 0.6469279, 0.6540516, 0.6481857, 0.6481857, 0.6481857, 0.6466496, 0.7027939, 0.6629898 ) - expect_true(all(abs(unlist(eval_results[["ndcg@3"]][["eval"]]) - ndcg3_values) < TOLERANCE)) + #expect_true(all(abs(unlist(eval_results[["ndcg@3"]][["eval"]]) - ndcg3_values) < TOLERANCE)) + expect_equal(eval_results[["ndcg@3"]][["eval"]][[1L]], ndcg3_values[[1L]]) + expect_equal(eval_results[["ndcg@3"]][["eval"]][[2L]], ndcg3_values[[2L]]) + expect_equal(eval_results[["ndcg@3"]][["eval"]][[3L]], ndcg3_values[[3L]]) + expect_equal(eval_results[["ndcg@3"]][["eval"]][[4L]], ndcg3_values[[4L]]) + expect_equal(eval_results[["ndcg@3"]][["eval"]][[5L]], ndcg3_values[[5L]]) + expect_equal(eval_results[["ndcg@3"]][["eval"]][[6L]], ndcg3_values[[6L]]) + expect_equal(eval_results[["ndcg@3"]][["eval"]][[7L]], ndcg3_values[[7L]]) + expect_equal(eval_results[["ndcg@3"]][["eval"]][[8L]], ndcg3_values[[8L]]) + expect_equal(eval_results[["ndcg@3"]][["eval"]][[9L]], ndcg3_values[[9L]]) + expect_equal(eval_results[["ndcg@3"]][["eval"]][[10L]], ndcg3_values[[10L]]) # check details of each booster for (bst in cv_bst$boosters) {