Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bblodfon committed Aug 7, 2024
1 parent 87d68d4 commit fa05f09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions tests/testthat/test_ensemble_fselect.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test_that("ensemble feature selection works", {
# default feature ranking
feature_ranking = efsr$feature_ranking()
expect_data_table(feature_ranking, nrows = length(task$feature_names))
expect_equal(names(feature_ranking), c("feature", "score", "norm_score"))
expect_equal(names(feature_ranking), c("feature", "score", "norm_score", "borda_score"))

# pareto_front
pf = efsr$pareto_front()
Expand Down Expand Up @@ -87,7 +87,7 @@ test_that("ensemble feature selection works without benchmark result", {
# default feature ranking
feature_ranking = efsr$feature_ranking()
expect_data_table(feature_ranking, nrows = length(task$feature_names))
expect_equal(names(feature_ranking), c("feature", "score", "norm_score"))
expect_equal(names(feature_ranking), c("feature", "score", "norm_score", "borda_score"))

# pareto_front
pf = efsr$pareto_front()
Expand Down Expand Up @@ -137,7 +137,7 @@ test_that("ensemble feature selection works with rfe", {
# default feature ranking
feature_ranking = efsr$feature_ranking()
expect_data_table(feature_ranking, nrows = length(task$feature_names))
expect_equal(names(feature_ranking), c("feature", "score", "norm_score"))
expect_equal(names(feature_ranking), c("feature", "score", "norm_score", "borda_score"))

# pareto_front
pf = efsr$pareto_front()
Expand Down
20 changes: 14 additions & 6 deletions tests/testthat/test_voting_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ w2_equal = rep(1, length(vot2))
test_that("approval voting", {
# large data
av = approval_voting(vot, cand, w)
expect_data_table(av, nrows = length(cand), ncols = 3)
expect_setequal(colnames(av), c("feature", "score", "norm_score"))
expect_data_table(av, nrows = length(cand), ncols = 4)
expect_setequal(colnames(av), c("feature", "score", "norm_score", "borda_score"))
expect_setequal(av$feature, cand) # all features are there
expect_true(all(av$score >= 0)) # positive scores
expect_true(all(av$norm_score >= 0 & av$norm_score <= 1)) # behave like probs
expect_equal(av$borda_score[1], 1)
expect_equal(av$borda_score[length(cand)], 0)

av_equalw = approval_voting(vot, cand, w_equal)
expect_data_table(av_equalw, nrows = length(cand), ncols = 3)
expect_data_table(av_equalw, nrows = length(cand), ncols = 4)
expect_true(all(av_equalw$score >= 0)) # positive scores
expect_true(all(av_equalw$norm_score >= 0 & av_equalw$norm_score <= 1)) # behave like probs
expect_equal(av_equalw$borda_score[1], 1)
expect_equal(av_equalw$borda_score[length(cand)], 0)
# using unequal weights, feature rankings should be different
expect_false(identical(av$feature, av_equalw$feature))

Expand All @@ -52,16 +56,20 @@ test_that("approval voting", {
test_that("satisfaction approval voting", {
# large data
sav = satisfaction_approval_voting(vot, cand, w)
expect_data_table(sav, nrows = length(cand), ncols = 3)
expect_setequal(colnames(sav), c("feature", "score", "norm_score"))
expect_data_table(sav, nrows = length(cand), ncols = 4)
expect_setequal(colnames(sav), c("feature", "score", "norm_score", "borda_score"))
expect_setequal(sav$feature, cand) # all features are there
expect_true(all(sav$score >= 0)) # positive scores
expect_true(all(sav$norm_score >= 0 & sav$norm_score <= 1)) # behave like probs
expect_equal(sav$borda_score[1], 1)
expect_equal(sav$borda_score[length(cand)], 0)

sav_equalw = satisfaction_approval_voting(vot, cand, w_equal)
expect_data_table(sav_equalw, nrows = length(cand), ncols = 3)
expect_data_table(sav_equalw, nrows = length(cand), ncols = 4)
expect_true(all(sav_equalw$score >= 0)) # positive scores
expect_true(all(sav_equalw$norm_score >= 0 & sav_equalw$norm_score <= 1)) # behave like probs
expect_equal(sav_equalw$borda_score[1], 1)
expect_equal(sav_equalw$borda_score[length(cand)], 0)
# using unequal weights, feature rankings should be different
expect_false(identical(sav$feature, sav_equalw$feature))

Expand Down

0 comments on commit fa05f09

Please sign in to comment.