1
exercism fetch r secret-handshake

test_secret-handshake.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
source("./secret-handshake.R")
library(testthat)

test_that("wink for 1", {
  expect_equal(handshake(1), c("wink"))
})

test_that("double blink for 10", {
  expect_equal(handshake(2), c("double blink"))
})

test_that("close your eyes for 100", {
  expect_equal(handshake(4), c("close your eyes"))
})

test_that("jump for 1000", {
  expect_equal(handshake(8), c("jump"))
})

test_that("combine two actions", {
  expect_equal(handshake(3), c("wink", "double blink"))
})

test_that("reverse two actions", {
  expect_equal(handshake(19), c("double blink", "wink"))
})

test_that("reversing one action gives the same action", {
  expect_equal(handshake(24), c("jump"))
})

test_that("reversing no actions still gives no actions", {
  expect_equal(handshake(16), c())
})

test_that("all possible actions", {
  expect_equal(handshake(15), 
               c("wink", "double blink", "close your eyes", "jump"))
})

test_that("reverse all possible actions", {
  expect_equal(handshake(31), 
               c("jump", "close your eyes", "double blink", "wink"))
})

test_that("do nothing for zero", {
  expect_equal(handshake(0), c())
})

test_that("do nothing if lower 5 bits not set", {
  expect_equal(handshake(32), c())
})

message("All tests passed for exercise: secret-handshake")