Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
UBC-DSCI
GitHub Repository: UBC-DSCI/dsci-100-assets
Path: blob/master/2020-fall/materials/worksheet_01/tests_worksheet_01.R
2051 views
1
library(testthat)
2
library(digest)
3
4
test_3.2 <- function(){
5
test_that('seconds_in_a_minute should exist and have the value of how many seconds are in a minute.', {
6
expect_equal(digest(seconds_in_a_minute), '4bdb128c943f718f5b8f347bb4b7641b') # we hid the answer to the test here so you can't see it, but we can still run the test
7
})
8
test_that('seconds_in_a_hour should exist and have the value of how many seconds are in a hour.', {
9
expect_equal(digest(seconds_in_an_hour), 'a69521e1dbffd4cd8f6ed869a4eba073') # we hid the answer to the test here so you can't see it, but we can still run the test
10
})
11
print("Success!")
12
}
13
14
test_4.0 <- function(){
15
test_that('Solution is incorrect', {
16
expect_equal(digest(title), 'c76933115bc8095b2140c11556800725') # we hid the answer to the test here so you can't see it, but we can still run the test
17
})
18
print("Success!")
19
}
20
21
test_4.1 <- function(){
22
test_that('Solution is incorrect', {
23
expect_equal(digest(smallest), 'db8e490a925a60e62212cefc7674ca02') # we hid the answer to the test here so you can't see it, but we can still run the test
24
})
25
print("Success!")
26
}
27
28
test_5.1 <- function(){
29
test_that('Solution is incorrect, the rvest package needs to be loaded', {
30
expect_that("package:rvest" %in% search() , is_true())
31
})
32
print("Success!")
33
}
34
35
test_6.1 <- function(){
36
test_that('Solution is incorrect', {
37
expect_equal(digest(answer6.1), '75f1160e72554f4270c809f041c7a776') # we hid the answer to the test here so you can't see it, but we can still run the test
38
})
39
print("Success!")
40
}
41
42
test_7.0.1 <- function(){
43
test_that('Solution is incorrect', {
44
expect_equal(digest(answer7.0.1), '3a5505c06543876fe45598b5e5e5195d') # we hid the answer to the test here so you can't see it, but we can still run the test
45
})
46
print("Success!")
47
}
48
49
test_7.0.2 <- function(){
50
test_that('Solution is incorrect', {
51
expect_equal(digest(answer7.0.2), '05ca18b596514af73f6880309a21b5dd') # we hid the answer to the test here so you can't see it, but we can still run the test
52
})
53
print("Success!")
54
}
55
56
test_7.0.3 <- function(){
57
test_that('Solution is incorrect', {
58
expect_equal(digest(answer7.0.3), '475bf9280aab63a82af60791302736f6') # we hid the answer to the test here so you can't see it, but we can still run the test
59
})
60
print("Success!")
61
}
62
63
test_7.1.1 <- function(){
64
test_that('Did not create an object named marathon_small', {
65
expect_true(exists("marathon_small"))
66
})
67
test_that('marathon_small should be a data frame', {
68
expect_true('data.frame' %in% class(marathon_small))
69
})
70
test_that('marathon_small does not contain the correct data', {
71
expect_equal(dim(marathon_small), c(1833, 5))
72
expect_equal(digest(round(sum(marathon_small$age))), "01d0e3ad4837c2290949b408787f5f3e")
73
expect_equal(colnames(marathon_small), c("age", "bmi", "km5_time_seconds", "km10_time_seconds", "sex"))
74
})
75
print("Success!")
76
}
77
78
test_7.1.2 <- function(){
79
test_that('Solution is incorrect', {
80
expect_equal(digest(answer7.1.2), '3a5505c06543876fe45598b5e5e5195d') # we hid the answer to the test here so you can't see it, but we can still run the test
81
})
82
print("Success!")
83
}
84
85
test_7.2.1 <- function(){
86
test_that('Solution is incorrect.', {
87
expect_equal(digest(number_rows), '58fac55045cec17cd9f4006f4b5ab349') # we hid the answer to the test here so you can't see it, but we can still run the test
88
})
89
print("Success!")
90
}
91
92
test_7.3.1 <- function(){
93
test_that('marathon_filtered has the incorrect number of rows', {
94
expect_equal(digest(nrow(marathon_filtered)), 'd9509be2b148230926a2df0f355c16b2') # we hid the answer to the test here so you can't see it, but we can still run the test
95
})
96
test_that('marathon_filtered has the incorrect number of column', {
97
expect_equal(digest(ncol(marathon_filtered)), 'dd4ad37ee474732a009111e3456e7ed7') # we hid the answer to the test here so you can't see it, but we can still run the test
98
})
99
test_that('marathon_filtered bmi column contains the incorrect values', {
100
expect_equal(colnames(marathon_filtered), c("age", "bmi", "km5_time_seconds", "km10_time_seconds", "sex"))
101
expect_equal(digest(round(as.numeric(sum(marathon_filtered$bmi)))), '8d5e20de34549cf5d90abc665abdd883') # we hid the answer to the test here so you can't see it, but we can still run the test
102
})
103
print("Success!")
104
}
105
106
test_7.4.1 <- function(){
107
test_that('marathon_male has the incorrect number of rows', {
108
expect_equal(digest(nrow(marathon_male)), 'd9509be2b148230926a2df0f355c16b2') # we hid the answer to the test here so you can't see it, but we can still run the test
109
})
110
test_that('marathon_male has the incorrect number of columns', {
111
expect_equal(digest(ncol(marathon_male)), 'c01f179e4b57ab8bd9de309e6d576c48') # we hid the answer to the test here so you can't see it, but we can still run the test
112
})
113
test_that('marathon_male bmi and/or km10_time_seconds column(s) contains the incorrect values', {
114
expect_equal(digest(round(sum(as.numeric(marathon_male$bmi)))), '8d5e20de34549cf5d90abc665abdd883') # we hid the answer to the test here so you can't see it, but we can still run the test
115
expect_equal(digest(round(sum(as.numeric(marathon_male$km10_time_seconds), na.rm = TRUE))), '94a8a4aca7bf6c04261303c3aff557da') # we hid the answer to the test here so you can't see it, but we can still run the test
116
})
117
print("Success!")
118
}
119
120
test_7.4.2 <- function(){
121
test_that('Solution is incorrect', {
122
expect_match(digest(answer7.4.2), "a9cf135185e7fe4ae642c8dcb228cd2d")
123
})
124
print("Success!")
125
}
126
127
test_7.4.3 <- function(){
128
test_that('Solution is incorrect', {
129
expect_match(digest(answer7.4.3), "edf7faf67d063030eba4ec85c6f7cc55")
130
})
131
print("Success!")
132
}
133
134
test_7.5.1 <- function(){
135
test_that('marathon_minutes has the incorrect number of rows', {
136
expect_equal(digest(nrow(marathon_minutes)), 'd9509be2b148230926a2df0f355c16b2') # we hid the answer to the test here so you can't see it, but we can still run the test
137
})
138
test_that('marathon_minutes has the incorrect number of columns', {
139
expect_equal(digest(ncol(marathon_minutes)), '11946e7a3ed5e1776e81c0f0ecd383d0') # we hid the answer to the test here so you can't see it, but we can still run the test
140
})
141
test_that('km10_time_minutes column does not exist contains incorrect values', {
142
expect_equal(digest(round(sum(as.numeric(marathon_minutes$km10_time_minutes), na.rm = TRUE))), 'baab288fe3905d65ebe40bd578a14723') # we hid the answer to the test here so you can't see it, but we can still run the test
143
})
144
print("Success!")
145
}
146
147
test_7.6.1 <- function(){
148
test_that('Solution is incorrect', {
149
expect_match(digest(answer7.6.1), '3a5505c06543876fe45598b5e5e5195d')
150
})
151
print("Success!")
152
}
153