Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Lalovic committed Mar 27, 2024
1 parent b3257a1 commit a634f6b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 24 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
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
18 changes: 9 additions & 9 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ library(responsesR)
### Simulating survey data
The following sample code creates a simulated survey data. The hypothetical survey simulation is roughly based on the actual [comparative study](https://arxiv.org/abs/2201.12960) on teaching and learning R in a pair of introductory statistics labs.

Imagine a situation in which 10 participants from course A and 20 participants from course B have completed the survey. Suppose that the initial question was:
Consider a scenario where 10 participants who completed Course A and 20 participants who completed Course B have taken the survey. Let's assume the initial question was:

> "How would you rate your experience with the course?"
with four possible answers:

> Poor, Fair, Good, and Excellent.
Let's assume that the participants in course A were neutral regarding the question and participants in Course B had a more positive experience on average.
Let's suppose that participants in Course A had a neutral opinion regarding the question, while those in Course B, on average, had a more positive experience.

By choosing appropriate parameters for the latent distributions and setting number of categories `K = 4`, we can generate hypothetical responses (standard deviation `sd = 1` and skewness `gamma1 = 0`, by default):
```{r}
Expand Down Expand Up @@ -116,15 +116,15 @@ knitr::include_graphics("./figures/articles_courses_grouped_bar_chart-1.png")

Suppose that the survey also asked the participants to rate their skills on a 5-point Likert scale, ranging from 1 (very poor) to 5 (very good) in:

* programming,
* searching online,
* solving problems.
* Programming,
* Searching Online,
* Solving Problems.

The survey was completed by the participants both before and after taking the course for a pre and post-comparison. Suppose that participants' assessments of:

* programming skills on average increased,
* searching online stayed about the same,
* solving problems increased in course A, but decreased for participants in course B.
* Programming skills on average increased,
* Searching Online stayed about the same,
* Solving Problems increased in Course A, but decreased for participants in Course B.

Let's simulate the survey data for this scenario (number of categories is `K = 5` by default):
```{r}
Expand All @@ -139,7 +139,7 @@ pre_B <- get_responses(n = 20, mu = c(-1, 0, 1))
post_B <- get_responses(n = 20, mu = c(0, 0, 0)) # <-- decrease for skill 3
```

Pre- and post-survey responses to Likert-scale questions visualized using a grouped bar chart:
The grouped bar chart below displays the responses to Likert-scale questions before and after the survey:
<details>
<summary><b><a style="cursor: pointer;">Click here to expand </a></b> </summary>

Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ hypothetical survey simulation is roughly based on the actual
[comparative study](https://arxiv.org/abs/2201.12960) on teaching and
learning R in a pair of introductory statistics labs.

Imagine a situation in which 10 participants from course A and 20
participants from course B have completed the survey. Suppose that the
initial question was:
Consider a scenario where 10 participants who completed Course A and 20
participants who completed Course B have taken the survey. Let’s assume
the initial question was:

> “How would you rate your experience with the course?”
with four possible answers:

> Poor, Fair, Good, and Excellent.
Let’s assume that the participants in course A were neutral regarding
the question and participants in Course B had a more positive experience
on average.
Let’s suppose that participants in Course A had a neutral opinion
regarding the question, while those in Course B, on average, had a more
positive experience.

By choosing appropriate parameters for the latent distributions and
setting number of categories `K = 4`, we can generate hypothetical
Expand Down Expand Up @@ -133,18 +133,18 @@ Suppose that the survey also asked the participants to rate their skills
on a 5-point Likert scale, ranging from 1 (very poor) to 5 (very good)
in:

- programming,
- searching online,
- solving problems.
- Programming,
- Searching Online,
- Solving Problems.

The survey was completed by the participants both before and after
taking the course for a pre and post-comparison. Suppose that
participants’ assessments of:

- programming skills on average increased,
- searching online stayed about the same,
- solving problems increased in course A, but decreased for participants
in course B.
- Programming skills on average increased,
- Searching Online stayed about the same,
- Solving Problems increased in Course A, but decreased for participants
in Course B.

Let’s simulate the survey data for this scenario (number of categories
is `K = 5` by default):
Expand All @@ -161,8 +161,8 @@ pre_B <- get_responses(n = 20, mu = c(-1, 0, 1))
post_B <- get_responses(n = 20, mu = c(0, 0, 0)) # <-- decrease for skill 3
```

Pre- and post-survey responses to Likert-scale questions visualized
using a grouped bar chart:
The grouped bar chart below displays the responses to Likert-scale
questions before and after the survey:
<details>
<summary>
<b><a style="cursor: pointer;">Click here to expand </a></b>
Expand Down
46 changes: 46 additions & 0 deletions tests/helper_functions_testthat.R
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) )
})


















0 comments on commit a634f6b

Please sign in to comment.