Skip to content

Commit

Permalink
Merge pull request #11 from andyquinterom/add_tests
Browse files Browse the repository at this point in the history
Adds unit tests and better description
  • Loading branch information
andres-ixpantia authored Nov 20, 2023
2 parents b16e809 + d85c496 commit 8c6e474
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: orbweaver
Title: Fast and Efficient Graph Data Structures
Version: 0.1.0.9000
Version: 0.0.3
Authors@R:
c(person(given = "ixpantia, SRL",
role = "cph",
Expand All @@ -9,7 +9,7 @@ Authors@R:
person(given = "The authors of the dependency Rust crates",
role = c("ctb"),
comment = "see inst/AUTHORS file for details"))
Description: Orbweaver is an R packages that optimizes the processing of graph data structures.
Description: A set of optimized tools and abstractions for processing graph data structures.
URL: https://github.com/ixpantia/orbweaver
BugReports: https://github.com/ixpantia/orbweaver/issues
License: MIT + file LICENSE
Expand All @@ -18,3 +18,6 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Config/rextendr/version: 0.3.1
SystemRequirements: Cargo (Rust's package manager), rustc
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(orbweaver)

test_check("orbweaver")
23 changes: 23 additions & 0 deletions tests/testthat/test-as_graph.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
test_that("can convert from data.frame to acyclic graph", {
sample_data_frame <- data.frame(
parent = c("A", "B", "C", "C"),
child = c("B", "C", "D", "E")
)

sample_graph <- as_graph(sample_data_frame, type = "acyclic")

sample_graph |>
find_roots() |>
expect_equal(c("A"))

sample_graph |>
find_leaves("A") |>
sort() |>
expect_equal(sort(c("D", "E")))
})

test_that("cannot convert from unsupported type to acyclic graph", {
sample_data_frame <- 1L

expect_error(as_graph(sample_data_frame, type = "acyclic"))
})
22 changes: 22 additions & 0 deletions tests/testthat/test-find_least_common_parents.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
test_that("can find least common parents between selected nodes", {
graph <- data.frame(
parent = c("A", "B", "C", "C", "F"),
child = c("B", "C", "D", "E", "D")
) |>
as_graph(type = "acyclic")

graph |>
find_least_common_parents(c("D", "E")) |>
sort() |>
expect_equal(c("D", "E"))

graph |>
find_least_common_parents(c("C", "D", "E")) |>
expect_equal("C")

graph |>
find_least_common_parents(c("A", "B", "C", "D", "E", "F")) |>
sort() |>
expect_equal(c("A", "F"))

})
25 changes: 25 additions & 0 deletions tests/testthat/test-get_parents.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
test_that("can get parents", {
sample_data_frame <- data.frame(
parent = c("A", "B", "C", "C", "F"),
child = c("B", "C", "D", "E", "D")
)

sample_graph <- as_graph(sample_data_frame, type = "acyclic")

sample_graph |>
get_parents("C") |>
expect_equal("B")

sample_graph |>
get_parents("A") |>
expect_equal(character(0))

sample_graph |>
get_parents("D") |>
sort() |>
expect_equal(c("C", "F"))

sample_graph |>
get_parents("E") |>
expect_equal("C")
})

0 comments on commit 8c6e474

Please sign in to comment.