Skip to content

Commit

Permalink
[R-package] fix learning-to-rank tests on Solaris (fixes microsoft#3513)
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Nov 2, 2020
1 parent cf69591 commit 2882143
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions R-package/tests/testthat/test_learning_to_rank.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2882143

Please sign in to comment.