forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.R
More file actions
34 lines (31 loc) · 840 Bytes
/
test.R
File metadata and controls
34 lines (31 loc) · 840 Bytes
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
## Function that tests the two functions of cachematrix.R
testAssignment <- function() {
## Prepare a matrix
data <- matrix(c(1 / 2, -1 / 4, -1, 3 / 4), nrow = 2, ncol = 2)
message("Data:")
print(data)
## test the first function
message("-- test makeCacheMatrix --")
cm <- makeCacheMatrix(NULL)
cmNames <- names(cm)
## get
message(cmNames[2])
print(cm[[2]]())
## set
message(cmNames[1])
cm[[1]](data)
print(cm[[2]]())
## getInverse
message(cmNames[4])
print(cm[[4]]())
## setInverse
message(cmNames[3])
cm[[3]](solve(data))
print(cm[[4]]())
## test the second function
message("-- test cacheSolve --")
data <- matrix(c(6, 2, 8, 4), nrow = 2, ncol = 2)
cm <- makeCacheMatrix(data)
print(cacheSolve(cm))
print(cacheSolve(cm))
}