Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agricolamz committed Jul 14, 2024
1 parent b03cf52 commit c29f6d7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
7 changes: 4 additions & 3 deletions R/df_to_tier.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#' no output.
#' @examples
#' time_start <- c(0.00000000, 0.01246583, 0.24781914, 0.39552363, 0.51157715)
#' time_end <- c(0.01246583, 0.24781914, 0.39552363, 0.51157715, 0.6526757369614512)
#' time_end <- c(0.01246583, 0.24781914, 0.39552363, 0.51157715, 0.65267574)
#' content <- c("", "T", "E", "S", "T")
#' df_to_tier(my_df <- data.frame(id = 1:5, time_start, time_end, content),
#' df_to_tier(data.frame(id = 1:5, time_start, time_end, content),
#' system.file("extdata", "test.TextGrid",
#' package = "phonfieldwork"
#' ),
Expand All @@ -37,6 +37,8 @@ df_to_tier <- function(df, textgrid, tier_name = "", overwrite = TRUE) {
))
}

df <- df[which(names(df) %in% c("time_start", "time_end", "content"))]

tg <- read_textgrid(textgrid)

n_tiers <- as.numeric(gsub("\\D", "", tg[7]))
Expand All @@ -58,7 +60,6 @@ df_to_tier <- function(df, textgrid, tier_name = "", overwrite = TRUE) {
})
}


if("time_end" %in% names(df)){
if(df$time_end[nrow(df)] != textgrid_duration){
df <- rbind(df,
Expand Down
4 changes: 2 additions & 2 deletions man/concatenate_textgrids.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/df_to_tier.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions tests/testthat/test-df-to-tier.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
test_that("df_to_tier", {
time_start <- c(0.00000000, 0.01246583, 0.24781914, 0.39552363, 0.51157715)
time_end <- c(0.01246583, 0.24781914, 0.39552363, 0.51157715, 0.6526757369614512)
time_end <- c(0.01246583, 0.24781914, 0.39552363, 0.51157715, 0.65267574)
content <- c("", "T", "E", "S", "T")
my_df <- data.frame(id = 1:5, time_start, time_end, content)
tg <- df_to_tier(my_df,
system.file("extdata", "test.TextGrid", package = "phonfieldwork"),
overwrite = FALSE
)

cat(tg, sep = "\n")

readLines(system.file("extdata", "test.TextGrid", package = "phonfieldwork"))

expect_error(
Expand All @@ -24,5 +22,5 @@ test_that("df_to_tier", {
'"time_start" and "time_end"'
)
)
expect_length(tg, 104)
expect_length(tg, 108)
})

0 comments on commit c29f6d7

Please sign in to comment.