-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A complete overhaul of unit-tests 🔨 (#22)
* [UNIT-TEST] Consolidated Setup 🔨 * All refererence function are now called from the setup script. * All (unweighted) classification functions are now called from the setup script. * [UNIT-TEST] S3 methods for classification 🔨 * All S3 methods are now tested seperately for weighted and unweighted classifcation. The tests are for balanced and imbalanced classification. * [UNIT-TEST] Completely Rewritten (See message) 🔨 * To account for edge cases, corner cases and whatever type of cases there exists ALL unit tests have been rewritten to capture these errors. * The specificity function have been rewritten, as the {scikit-learn} implementation is misbehaving.
- Loading branch information
Showing
43 changed files
with
2,971 additions
and
981 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# objective: Test that Accuracy | ||
# implemented in {SLmetrics} is aligned with | ||
# target functions. | ||
|
||
testthat::test_that( | ||
desc = "Test `accuracy()`-function", code = { | ||
|
||
# 0) construct Balanced Accuracy | ||
# wrapper | ||
wrapped_accuracy <- function( | ||
actual, | ||
predicted, | ||
w = NULL) { | ||
if (is.null(w)) { | ||
accuracy( | ||
actual = actual, | ||
predicted = predicted | ||
) | ||
} else { | ||
weighted.accuracy( | ||
actual = actual, | ||
predicted = predicted, | ||
w = w | ||
) | ||
} | ||
} | ||
|
||
for (balanced in c(FALSE, TRUE)) { | ||
|
||
# 1) generate class | ||
# values | ||
actual <- create_factor(balanced = balanced) | ||
predicted <- create_factor(balanced = balanced) | ||
w <- runif(n = length(actual)) | ||
|
||
for (weighted in c(TRUE, FALSE)) { | ||
|
||
# 2.1) generate sensible | ||
# label information | ||
info <- paste( | ||
"Balanced = ", balanced, | ||
"Weighted = ", weighted | ||
) | ||
|
||
# 2.2) generate score | ||
# from {slmetrics} | ||
score <- wrapped_accuracy( | ||
actual = actual, | ||
predicted = predicted, | ||
w = if (weighted) w else NULL | ||
) | ||
|
||
# 2.3) test that the values | ||
# are sensible the values | ||
# can be NA | ||
testthat::expect_true(is.numeric(score), info = info) | ||
testthat::expect_true(length(score) == 1, info = info) | ||
|
||
# 2.4) test that the values | ||
# are equal to target value | ||
|
||
# 2.4.1) calculate py_score | ||
py_score <- py_accuracy( | ||
actual = actual, | ||
predicted = predicted, | ||
w = if (weighted) w else NULL | ||
) | ||
|
||
# 2.4.2) test for equality | ||
testthat::expect_true( | ||
object = set_equal( | ||
current = score, | ||
target = py_score | ||
), | ||
info = info | ||
) | ||
|
||
} | ||
|
||
} | ||
} | ||
) |
Oops, something went wrong.