Skip to content

Commit

Permalink
fix: tidy for hands that have fulou
Browse files Browse the repository at this point in the history
  • Loading branch information
paithiov909 committed Nov 10, 2024
1 parent bd4f632 commit 0a8cff7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 7 additions & 2 deletions R/paistr.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,13 @@ generics::tidy
#' @export
tidy.skksph_paistr <- function(x, ...) {
n_tiles <- vctrs::vec_data(x) |>
stringi::stri_replace_all_fixed(",", "") |> # treat any fulou as bingpai
skksph_tidy_impl()
purrr::map(~ {
stringi::stri_replace_all_regex(.x, "[\\-\\=\\+]", "") |>
stringi::stri_split_fixed(",") |>
unlist(use.names = FALSE) |>
skksph_tidy_impl() |>
purrr::reduce(`+`)
})
df <-
data.frame(
id = rep(seq_along(n_tiles), each = 38),
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/paistr.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{
"type": "integer",
"attributes": {},
"value": [0]
"value": [1]
},
{
"type": "integer",
Expand All @@ -39,7 +39,7 @@
"value": [1, 34]
}
},
"value": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]
"value": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0]
}
]
}
Expand Down Expand Up @@ -85,7 +85,7 @@
"value": ["factor"]
}
},
"value": [11, 13, 14, 15, 16, 32, 33, 34, 35, 36, 37]
"value": [11, 13, 14, 15, 16, 22, 23, 24, 32, 33, 34]
},
{
"type": "integer",
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-paistr.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ test_that("paistr works", {
})

test_that("calculate for paistr works", {
pai <- paistr("p0222345z234567")
pai <- paistr("p0222345z234,s1-23")
expect_snapshot_value(calculate(pai), style = "json2", cran = FALSE)
})

test_that("tidy for paistr works", {
pai <- paistr("p0222345z234567")
pai <- paistr("p0222345z234,s1-23")
expect_snapshot_value(tidy(pai), style = "json2", cran = FALSE)
})

0 comments on commit 0a8cff7

Please sign in to comment.