Skip to content

Commit 64f68e2

Browse files
committed
Expand the test coverage
Was trying to find the difference between <<- and <-
1 parent f7ca2e8 commit 64f68e2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cachematrix.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ makeCacheMatrix <- function(x = matrix()) {
2727
get <- function() cachedMatrix
2828

2929
# Setter function for the inverse
30+
# Only provided for API compatibility. Getting the inverse
31+
# will prime the cache
3032
setInverse <- function(inverse) cachedInverse <<- inverse
3133

3234
# Getter function for the inverse
@@ -83,4 +85,16 @@ test <- function() {
8385
print("Good, a's inverse is still correct and you should not see a cache miss")
8486
}
8587

88+
b.normal2 <- matrix(rnorm(9), 3, 3)
89+
b.cached$set(b.normal2)
90+
91+
if (identical(solve(b.normal2), cacheSolve(b.cached))) {
92+
print("Good, you can update (should have seen a cache miss)")
93+
}
94+
95+
if (identical(solve(b.normal2), cacheSolve(b.cached))) {
96+
print("Good...same thing but no cache miss")
97+
}
98+
99+
86100
}

0 commit comments

Comments
 (0)