Merge pull request 'Adding Array Copy for matrix' (#33) from ArrayDeepCopy into master
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			Reviewed-on: #33 Reviewed-by: Mat_02 <diletomatteo@gmail.com>
This commit is contained in:
		
							
								
								
									
										13
									
								
								app/src/main/java/school_project/Utils/Array.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								app/src/main/java/school_project/Utils/Array.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
package school_project.Utils;
 | 
			
		||||
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
public class Array{
 | 
			
		||||
    public static boolean[][] MatrixCopyOf(boolean[][] o){
 | 
			
		||||
        boolean[][] ret =  new boolean[o.length][];
 | 
			
		||||
        for (int i = 0; i < o.length; i++){
 | 
			
		||||
            ret[i] = Arrays.copyOf(o[i], o[i].length);
 | 
			
		||||
        }
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										26
									
								
								app/src/test/java/school_project/Utils/ArrayTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								app/src/test/java/school_project/Utils/ArrayTest.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
			
		||||
package school_project.Utils;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
 | 
			
		||||
class ArrayTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    void matrixCopyOf() {
 | 
			
		||||
        boolean[][] a = new boolean[][] {
 | 
			
		||||
                {true, false, true},
 | 
			
		||||
                {false, false, false},
 | 
			
		||||
                {true, false, true},
 | 
			
		||||
        };
 | 
			
		||||
        boolean[][] b = new boolean[][] {
 | 
			
		||||
                {true, false, true},
 | 
			
		||||
                {false, false, false},
 | 
			
		||||
                {true, false, true},
 | 
			
		||||
        };
 | 
			
		||||
        boolean[][] c = Array.MatrixCopyOf(a);
 | 
			
		||||
        assertArrayEquals(a, c);
 | 
			
		||||
        a[1][1] = true;
 | 
			
		||||
        assertArrayEquals(b, c);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user