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
57 lines (41 loc) · 1.24 KB
/
test.R
File metadata and controls
57 lines (41 loc) · 1.24 KB
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
55
56
# This script tests the Programming Assignment 2 of the Coursera's R Programming course.
# R Programming
# Programming Assignment 2
# by Thiago Akio Nakamura
# akionakas@gmail.com
rm(list=ls())
source("cachematrix.R")
set.seed(100)
message(" ---- Initiating tests ----- ")
d <- 5;
M1 <- makeCacheMatrix()
message("Call: M1 <- makeCacheMatrix() -- Check")
print(M1)
M1$set(rnorm(10^2), nrow = d, ncol = d)
message("Call: M1$set(rnorm(10^2), nrow = d, ncol = d) -- Check")
print(M1$get())
message("Call: M1$get() -- Check")
M1$setInv(solve(M1$get()))
message("Call: M1$setInv(solve(M1$get())) -- Check")
print(M1$getInv())
message("Call: M1$getInv() -- Check")
message("All functions working.")
message("")
message(" ---- cacheSolve testing ---- ")
d <- 1000
msg <- paste("Matrix M2 size: ", d, " by ", d, ".")
message(msg)
M2 <- makeCacheMatrix(rnorm(d^2), nrow = d, ncol = d)
start.time <- Sys.time()
cacheSolve(M2)
message("Call: cacheSolve(M2) -- Check")
end.time <- Sys.time()
print("First Inversion")
print(end.time - start.time)
message("")
start.time <- Sys.time()
cacheSolve(M2)
message("Call: cacheSolve(M2) expected to recover cached value -- Check")
end.time <- Sys.time()
message("Second Inversion")
print(end.time - start.time)