Skip to content

Commit

Permalink
test: modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paithiov909 committed Nov 15, 2024
1 parent 9c8f697 commit 3ac450b
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 85 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shikakusphere
Title: Miscellaneous Functions for Japanese Mahjong
Version: 0.0.9
Version: 0.1.0
Authors@R: c(
person("Akiru", "Kato", , "paithiov909@gmail.com", role = c("aut", "cre")),
person("tomo", "hxx", role = "ctb",
Expand All @@ -24,7 +24,6 @@ Imports:
methods,
purrr,
Rcpp,
RcppSimdJson,
rlang,
stringi,
tibble,
Expand Down
13 changes: 8 additions & 5 deletions R/detect.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
#' @param negate A logical scalar.
#' @param suzhi A string scalar. Either "23", "34", "45", "56", "67", or "78".
#' @returns
#' * For `tile2suit` and `tile2rank`: a character vector.
#' * For `tile2rank` and `tile2suit`: a character vector
#' (an empty string for "_").
#' * For other functions: a logical vector.
NULL

#' @rdname detect
#' @export
tile2suit <- function(x) {
stringi::stri_sub(x, 1, 1)
tile2rank <- function(x) {
stringi::stri_sub(x, 2, 2)
}

#' @rdname detect
#' @export
tile2rank <- function(x) {
stringi::stri_sub(x, 2, 2)
tile2suit <- function(x) {
ret <- stringi::stri_sub(x, 1, 1)
ret[x == "_"] <- ""
ret
}

#' @rdname detect
Expand Down
9 changes: 5 additions & 4 deletions man/detect.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/paistr.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@
"levels": {
"type": "character",
"attributes": {},
"value": ["m0", "m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8", "m9", "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "z1", "z2", "z3", "z4", "z5", "z6", "z7"]
"value": ["_", "m0", "m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8", "m9", "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "z1", "z2", "z3", "z4", "z5", "z6", "z7"]
},
"class": {
"type": "character",
"attributes": {},
"value": ["factor"]
}
},
"value": [11, 13, 14, 15, 16, 22, 23, 24, 32, 33, 34]
"value": [12, 14, 15, 16, 17, 23, 24, 25, 33, 34, 35]
},
{
"type": "integer",
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"levels": {
"type": "character",
"attributes": {},
"value": ["m0", "m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8", "m9", "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "z1", "z2", "z3", "z4", "z5", "z6", "z7"]
"value": ["_", "m0", "m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8", "m9", "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9", "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9", "z1", "z2", "z3", "z4", "z5", "z6", "z7"]
}
},
"value": [11, 13, 13, 13, 14, 15, 16, 32, 33, 34, 35, 36, 37]
"value": [12, 14, 14, 14, 15, 16, 17, 33, 34, 35, 36, 37, 38]
}
]
}
Expand Down
88 changes: 88 additions & 0 deletions tests/testthat/test-detect.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
test_that("tile2rank and tile2suit return an empty for '_'", {
expect_equal(tile2rank("_"), "")
expect_equal(tile2suit("_"), "")
})

test_that("is_yaojiu works", {
pai <- int2tile()
expect_equal(
is_yaojiu(pai),
!c(
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
)
})

test_that("is_zhongzhang works", {
pai <- int2tile()
expect_equal(
is_zhongzhang(pai),
c(
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
)
})

test_that("is_suzhi works", {
pai <- int2tile()
expect_equal(
is_suzhi(pai, suzhi = "23"),
c(
FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
)
expect_equal(
is_suzhi(pai, suzhi = "34"),
c(
TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE,
TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE,
TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
)
expect_equal(
is_suzhi(pai, suzhi = "45"),
c(
FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
)
expect_equal(
is_suzhi(pai, suzhi = "56"),
c(
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
)
expect_equal(
is_suzhi(pai, suzhi = "67"),
c(
TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE,
TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE,
TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
)
expect_equal(
is_suzhi(pai, suzhi = "78"),
c(
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
)
})
83 changes: 13 additions & 70 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,86 +11,29 @@ test_that("lipai works", {
expect_equal(lipai(list(pai, NA, NULL)), c("m109p109s109z1267", "", ""))
})

test_that("is_yaojiu works", {
pai <- int2tile()
test_that("trans_tile works", {
expect_equal(
is_yaojiu(pai),
!c(
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
NA, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
)
})

test_that("is_zhongzhang works", {
pai <- int2tile()
expect_equal(
is_zhongzhang(pai),
c(
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE,
NA, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
)
})

test_that("is_suzhi works", {
pai <- int2tile()
expect_equal(
is_suzhi(pai, suzhi = "23"),
c(
FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
trans_tile(tiles[["cmajiang"]], from = "cmajiang", to = "mjai"),
tiles[["mjai"]]
)
expect_equal(
is_suzhi(pai, suzhi = "34"),
c(
TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE,
TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE,
TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
trans_tile(tiles[["cmajiang"]], from = "cmajiang", to = "tenhou_int"),
tiles[["tenhou_int"]]
)
expect_equal(
is_suzhi(pai, suzhi = "45"),
c(
FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
trans_tile(tiles[["mjai"]], from = "mjai", to = "cmajiang"),
tiles[["cmajiang"]]
)
expect_equal(
is_suzhi(pai, suzhi = "56"),
c(
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
trans_tile(tiles[["mjai"]], from = "mjai", to = "tenhou_int"),
tiles[["tenhou_int"]]
)
expect_equal(
is_suzhi(pai, suzhi = "67"),
c(
TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE,
TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE,
TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
trans_tile(tiles[["tenhou_int"]], from = "tenhou_int", to = "cmajiang"),
tiles[["cmajiang"]]
)
expect_equal(
is_suzhi(pai, suzhi = "78"),
c(
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
)
trans_tile(tiles[["tenhou_int"]], from = "tenhou_int", to = "mjai"),
tiles[["mjai"]]
)
})

0 comments on commit 3ac450b

Please sign in to comment.