-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_affine-cipher.R
36 lines (28 loc) · 1.1 KB
/
test_affine-cipher.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
source("./affine-cipher.R")
library(testthat)
# check encrypt() function
test_that("encrypt() returns correct string", {
expect_identical(encrypt("test", 5, 7), "ybty")
})
test_that("encrypt() accounts for whitespace", {
expect_identical(encrypt("te st ", 5, 7), "ybty")
})
test_that("encrypt() accounts for case-sensitivity", {
expect_identical(encrypt("TeST", 5, 7), "ybty")
})
test_that("encrypt() checks that a is coprime with m", {
expect_error(encrypt("jknkasd", 18, 13))
})
# check decrypt() function
test_that("decrypt() returns correct string", {
expect_identical(decrypt("ybty", 5, 7), "test")
expect_identical(decrypt("kqlfd jzvgy tpaet icdhm rtwly kqlon ubstx", 19, 13), "thequickbrownfoxjumpsoverthelazydog")
})
test_that("decrypt() accounts for whitespace", {
expect_identical(decrypt(" ybt y", 5, 7), "test")
expect_identical(decrypt("kqlfd jzvgy tpaet icdhm rtwly kqlon ubstx", 19, 13), "thequickbrownfoxjumpsoverthelazydog")
})
test_that("decrypt() checks that a is coprime with m", {
expect_error(decrypt("jknkasd", 18, 13))
})
message("All tests passed for exercise: affine-cipher")