1+ # These tests are auto-generated with test data from:
2+ # https://github.com/exercism/problem-specifications/tree/main/exercises/crypto-square/canonical-data.json
3+ # File last updated on 2026-08-05
4+
15source(" ./crypto-square.R" )
26library(testthat )
37
8+ test_that(" empty plaintext results in an empty ciphertext" , {
9+ expect_equal(ciphertext(" " ), " " )
10+ })
11+ test_that(" normalization results in empty plaintext" , {
12+ expect_equal(ciphertext(" ... --- ..." ), " " )
13+ })
414test_that(" Lowercase" , {
5- expect_equal(normalized_plaintext( " Hello " ), " hello " )
15+ expect_equal(ciphertext( " A " ), " a " )
616})
7-
817test_that(" Remove spaces" , {
9- expect_equal(normalized_plaintext( " Hi there " ), " hithere " )
18+ expect_equal(ciphertext( " b " ), " b " )
1019})
11-
1220test_that(" Remove punctuation" , {
13- expect_equal(normalized_plaintext(" @1, 2%, 3 Go!" ), " 123go" )
14- })
15-
16- test_that(" empty plaintext results in an empty rectangle" , {
17- expect_equal(plaintext_segments(" " ), " " )
18- })
19-
20- test_that(" 4 character plaintext results in an 2x2 rectangle" , {
21- expect_equal(plaintext_segments(" Ab Cd" ), c(" ab" , " cd" ))
22- })
23-
24- test_that(" 9 character plaintext results in an 3x3 rectangle" , {
25- expect_equal(plaintext_segments(" This is fun!" ), c(" thi" , " sis" , " fun" ))
26- })
27-
28- test_that(" 54 character plaintext results in an 8x7 rectangle" , {
29- expect_equal(
30- plaintext_segments(
31- " If man was meant to stay on the ground, god would have given us roots."
32- ),
33- c(
34- " ifmanwas" ,
35- " meanttos" ,
36- " tayonthe" ,
37- " groundgo" ,
38- " dwouldha" ,
39- " vegivenu" ,
40- " sroots"
41- )
42- )
43- })
44-
45- test_that(" empty plaintext results in an empty encode" , {
46- expect_equal(encoded(" " ), " " )
47- })
48-
49- test_that(" Non-empty plaintext results in the combined plaintext segments" , {
50- expect_equal(
51- encoded(
52- " If man was meant to stay on the ground, god would have given us roots."
53- ),
54- " imtgdvsfearwermayoogoanouuiontnnlvtwttddesaohghnsseoau"
55- )
56- })
57-
58- test_that(" empty plaintext results in an empty ciphertext" , {
59- expect_equal(ciphertext(" " ), " " )
21+ expect_equal(ciphertext(" @1,%!" ), " 1" )
6022})
61-
6223test_that(" 9 character plaintext results in 3 chunks of 3 characters" , {
6324 expect_equal(ciphertext(" This is fun!" ), " tsf hiu isn" )
6425})
65-
26+ test_that(" 8 character plaintext results in 3 chunks, the last one with a trailing space" , {
27+ expect_equal(ciphertext(" Chill out." ), " clu hlt io " )
28+ })
6629test_that(" 54 character plaintext results in 8 chunks, the last two with trailing spaces" , {
6730 expect_equal(
6831 ciphertext(
@@ -71,7 +34,3 @@ test_that("54 character plaintext results in 8 chunks, the last two with trailin
7134 " imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau "
7235 )
7336})
74-
75- test_that(" normalization results in empty plaintext" , {
76- expect_equal(ciphertext(" ... --- ..." ), " " )
77- })
0 commit comments