Skip to content

Commit

Permalink
Merge pull request #2 from sigmafelix/sigmafelix-patch-1
Browse files Browse the repository at this point in the history
more tests
  • Loading branch information
sigmafelix authored Jan 8, 2024
2 parents 5c31e32 + bc32188 commit e8a2e6e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 64 deletions.
62 changes: 0 additions & 62 deletions .github/workflow/codecov.yml

This file was deleted.

File renamed without changes.
55 changes: 55 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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 }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} # Add this line

steps:
- uses: actions/checkout@v3

- 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(Sys.getenv("RUNNER_TEMP"), "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@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package

- name: Upload coverage to Codecov # Add this step
run: |
Rscript -e "covr::codecov(token = Sys.getenv('CODECOV_TOKEN'))"
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
LinkingTo: Rcpp, RcppArmadillo
Imports: Rcpp, sf, dplyr, nngeo, spdep, testthat (>= 3.0.0), covr, ggplot2
Imports: Rcpp, sf, dplyr, nngeo, spdep, testthat (>= 3.0.0), covr, ggplot2, withr
33 changes: 32 additions & 1 deletion tests/testthat/test_speedmat.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,35 @@ testthat::test_that(
download.file(downloadlink, target_fullname, "libcurl")
testthat::expect_true(file.exists(target_fullname))
}
)
)


testthat::test_that("distJSD", {
library(sf)
ncpath <- system.file("gpkg/nc.gpkg", package = "sf")
nc <- sf::read_sf(ncpath)
ncn <- nc[, 9:14]
ncn <- sf::st_drop_geometry(ncn)
ncn <- as.matrix(ncn) + 1L

jsd_ncn <- distJSD(ncn)
testthat::expect_equal(jsd_ncn[1, 1], 0L, tolerance = 1e-8)
testthat::expect_equal(jsd_ncn[2, 1], 218.7963, tolerance = 7e-5)

})


testthat::test_that("distJSD2", {
library(sf)
ncpath <- system.file("gpkg/nc.gpkg", package = "sf")
nc <- sf::read_sf(ncpath)
ncn <- nc[, 9:14]
ncn <- sf::st_drop_geometry(ncn)
ncn <- as.matrix(ncn) + 1L

jsd_ncn <- distJSD2(ncn[1:3, ], ncn[60:67, ])
testthat::expect_equal(dim(jsd_ncn), c(3, 8))
testthat::expect_equal(jsd_ncn[1, 5], 3415.587, tolerance = 1e-3)
testthat::expect_equal(jsd_ncn[3, 7], 687.8441, tolerance = 1e-4)

})

0 comments on commit e8a2e6e

Please sign in to comment.