> # CSC 121, Jan-Apr 2017, Small Assignment 2. > # > # Script with tests of the find_distances function. > > # Tests provided in the assignment hando .... [TRUNCATED] > map [,1] [,2] [,3] [,4] [1,] " " "X" " " " " [2,] "X" " " "X" " " [3,] "X" " " "X" " " [4,] " " " " " " " " [5,] " " " " " " " " > find_distances(map,c(1,4)) [,1] [,2] [,3] [,4] [1,] Inf Inf 1 0 [2,] Inf 7 Inf 1 [3,] Inf 6 Inf 2 [4,] 6 5 4 3 [5,] 7 6 5 4 > find_distances(map,c(3,2)) [,1] [,2] [,3] [,4] [1,] Inf Inf 7 6 [2,] Inf 1 Inf 5 [3,] Inf 0 Inf 4 [4,] 2 1 2 3 [5,] 3 2 3 4 > find_distances(map,c(2,3)) [,1] [,2] [,3] [,4] [1,] Inf Inf Inf Inf [2,] Inf Inf 0 Inf [3,] Inf Inf Inf Inf [4,] Inf Inf Inf Inf [5,] Inf Inf Inf Inf > # Some additional tests. > > # Try map above in top-left corner. > > find_distances(map,c(1,1)) [,1] [,2] [,3] [,4] [1,] 0 Inf Inf Inf [2,] Inf Inf Inf Inf [3,] Inf Inf Inf Inf [4,] Inf Inf Inf Inf [5,] Inf Inf Inf Inf > # Try maps with one row or one column. > > find_distances (matrix (c("X"," "," "," "," ","X"," "),nrow=1,ncol=7), c(1,3)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] Inf 1 0 1 2 Inf Inf > find_distances (matrix (c("X"," "," "," "," ","X"," "),nrow=7,ncol=1), c(3,1)) [,1] [1,] Inf [2,] 1 [3,] 0 [4,] 1 [5,] 2 [6,] Inf [7,] Inf > # Try a map with no obstacles, starting at an interior point, edge, and corner. > > find_distances (matrix (" ", nrow=5, ncol=6), c(2,3)) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 3 2 1 2 3 4 [2,] 2 1 0 1 2 3 [3,] 3 2 1 2 3 4 [4,] 4 3 2 3 4 5 [5,] 5 4 3 4 5 6 > find_distances (matrix (" ", nrow=5, ncol=6), c(3,6)) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 7 6 5 4 3 2 [2,] 6 5 4 3 2 1 [3,] 5 4 3 2 1 0 [4,] 6 5 4 3 2 1 [5,] 7 6 5 4 3 2 > find_distances (matrix (" ", nrow=5, ncol=6), c(5,6)) [,1] [,2] [,3] [,4] [,5] [,6] [1,] 9 8 7 6 5 4 [2,] 8 7 6 5 4 3 [3,] 7 6 5 4 3 2 [4,] 6 5 4 3 2 1 [5,] 5 4 3 2 1 0 > # Try a map with obstacles everywhere except the edges. > > map2 <- matrix ("X", nrow=7, ncol=9) > map2[1,] <- " " > map2[7,] <- " " > map2[,1] <- " " > map2[,9] <- " " > map2 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] " " " " " " " " " " " " " " " " " " [2,] " " "X" "X" "X" "X" "X" "X" "X" " " [3,] " " "X" "X" "X" "X" "X" "X" "X" " " [4,] " " "X" "X" "X" "X" "X" "X" "X" " " [5,] " " "X" "X" "X" "X" "X" "X" "X" " " [6,] " " "X" "X" "X" "X" "X" "X" "X" " " [7,] " " " " " " " " " " " " " " " " " " > find_distances(map2,c(1,2)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 1 0 1 2 3 4 5 6 7 [2,] 2 Inf Inf Inf Inf Inf Inf Inf 8 [3,] 3 Inf Inf Inf Inf Inf Inf Inf 9 [4,] 4 Inf Inf Inf Inf Inf Inf Inf 10 [5,] 5 Inf Inf Inf Inf Inf Inf Inf 11 [6,] 6 Inf Inf Inf Inf Inf Inf Inf 12 [7,] 7 8 9 10 11 12 13 14 13