Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update tests to not copy across relevant dplyr code #101

Open
njtierney opened this issue Nov 5, 2024 · 0 comments
Open

update tests to not copy across relevant dplyr code #101

njtierney opened this issue Nov 5, 2024 · 0 comments

Comments

@njtierney
Copy link
Owner

Currently there are tests like

# compare this to the dplyr method ============================================

facility <- mutate(york, key = 1) |>
    rename(lat_facility = lat,
                  long_facility = long) |>
    # create an ID for each row
    mutate(facility_id = 1:n()) |>
    slice(1:100)

user <- mutate(york_crime, key = 1) |>
    rename(lat_user = lat,
                  long_user = long) |>
    mutate(user_id = 1:n()) |>
    slice(1:100)

my_dist_dplyr <- user |>
    left_join(facility,
                     by = "key",
              relationship = "many-to-many") |>
    mutate(distance = spherical_distance(lat1 = lat_user,
                                                long1 = long_user,
                                                lat2 = lat_facility,
                                                long2 = long_facility)) |>
    # drop key
    select(-key) |>
    select(user_id,
                  facility_id,
                  distance) |>
    spread(key = "facility_id",
                  value = "distance",
                  sep = "_") |>
    # drop the ID column (for proper comparison)
    select(-user_id) |>
    as.matrix()


test_that("cpp distance matrix produces same numeric result as using dplyr",{
    # I still need to make a method that gives the big matrix names
    expect_equal(my_dist_cpp,my_dist_dplyr)
})

Which involve hand copying relevant code over - this is not a very robust way to test the dplyr/underlying methods in the software

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant