Skip to content

Commit bd6259a

Browse files
committed
Adding some more examples for testing.
1 parent 7828761 commit bd6259a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test.R

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ide <- mat %*% inv
88

99
# Generate a random 2 x 2 matrix of integers from 1 to 10
1010
di <- 2
11-
mat <- matrix(sample(1:10, di * di), di, di)
11+
mat <- matrix(sample(1:10, di ^ 2), di, di)
1212
# Invert matrix
1313
inv <- solve(mat)
1414
# General identity matrix
@@ -24,3 +24,21 @@ cs <- cacheSolve(cm)
2424
is.null(cm$gets())
2525

2626
identical(inv, cacheSolve(cm))
27+
28+
# Test using large matrix so caching is evident
29+
lm <- matrix(runif(di ^ 2), di)
30+
cm <- makeCacheMatrix(lm)
31+
# Should take some time
32+
system.time(cs <- cacheSolve(cm))
33+
# Should be much faster
34+
system.time(cs <- cacheSolve(cm))
35+
identical(solve(lm), cs)
36+
37+
# Should produce proper identity matrix
38+
round(lm %*% cs, 4)
39+
40+
# Confirm
41+
42+
system.time(t1 <- cacheSolve(test))
43+
44+
system.time(t1 <- cacheSolve(test))

0 commit comments

Comments
 (0)