Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion exercises/rotational-cipher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Create an implementation of the rotational cipher, also sometimes called the Cae

The Caesar cipher is a simple shift cipher that relies on
transposing all the letters in the alphabet using an integer key
between `0` and `26`. Using a key of `0` or `26` will always yield
(both positive or negative). Using the same key will always yield
the same output due to modular arithmetic. The letter is shifted
for as many values as the value of the key.

Expand All @@ -28,7 +28,9 @@ Ciphertext is written out in the same formatting as the input including spaces a
- ROT0 `c` gives `c`
- ROT26 `Cool` gives `Cool`
- ROT13 `The quick brown fox jumps over the lazy dog.` gives `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.`
- ROT39 `The quick brown fox jumps over the lazy dog.` gives `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.`
- ROT13 `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.` gives `The quick brown fox jumps over the lazy dog.`
- ROT-13 `Gur dhvpx oebja sbk whzcf bire gur ynml qbt.` gives `The quick brown fox jumps over the lazy dog.`

## Installation
See [this guide](https://exercism.io/tracks/r/installation) for instructions on how to setup your local R environment.
Expand Down
14 changes: 14 additions & 0 deletions exercises/rotational-cipher/test_rotational-cipher.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,18 @@ test_that("rotate all letters", {
"Gur dhvpx oebja sbk whzcf bire gur ynml qbt.")
})

test_that("rotate through the alphabet an arbitrary number of times", {
text <- "The quick brown fox jumps over the lazy dog."
key <- 13 + (123 * 26)
expect_equal(rotate(text, key),
"Gur dhvpx oebja sbk whzcf bire gur ynml qbt.")
})

test_that("rotate backwards", {
text <- "The quick brown fox jumps over the lazy dog."
key <- 13 - (123 * 26)
expect_equal(rotate(text, key),
"Gur dhvpx oebja sbk whzcf bire gur ynml qbt.")
})

message("All tests passed for exercise: rotational-cipher")