-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marko Lalovic
committed
Mar 27, 2024
1 parent
b3257a1
commit a634f6b
Showing
4 changed files
with
120 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
name: test-coverage | ||
|
||
jobs: | ||
test-coverage: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
use-public-rspm: true | ||
|
||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
extra-packages: any::covr | ||
needs: coverage | ||
|
||
- name: Test coverage | ||
run: | | ||
covr::codecov( | ||
quiet = FALSE, | ||
clean = FALSE, | ||
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") | ||
) | ||
shell: Rscript {0} | ||
|
||
- name: Show testthat output | ||
if: always() | ||
run: | | ||
## -------------------------------------------------------------------- | ||
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true | ||
shell: bash | ||
|
||
- name: Upload test results | ||
if: failure() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-test-failures | ||
path: ${{ runner.temp }}/package |
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,46 @@ | ||
library("testthat") | ||
library("responsesR") | ||
context("Testing helper functions") | ||
|
||
test_that("prop_table gives the correct result", { | ||
data <- rep(c(1,2,3,4), each=2) | ||
prob_tab <- get_prop_table(data, K=4) | ||
correct_prob_tab <- rep(0.25, 4) | ||
names(correct_prob_tab) <- 1:4 | ||
expect_that( identical(prob_tab, correct_prob_tab), equals(TRUE) ) | ||
}) | ||
|
||
test_that("pad_levels gives the correct result", { | ||
pk <- rep(0.25, 4) | ||
names(pk) <- 1:4 | ||
padded_pk <- pad_levels(pk = pk, K = 5) | ||
|
||
correct_pk <- c(rep(0.25, 4), 0) | ||
names(correct_pk) <- 1:5 | ||
expect_that( identical(padded_pk, correct_pk), equals(TRUE) ) | ||
}) | ||
|
||
test_that("percentify gives the correct result", { | ||
xbreaks <- seq(from = 0, to = 1, length.out = 6) | ||
xlabs <- sapply(xbreaks, percentify) | ||
correct_xlabs <- c("0%", "20%", "40%", "60%", "80%", "100%") | ||
expect_that( identical(xlabs, correct_xlabs), equals(TRUE) ) | ||
}) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|