Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// TESTRER JUNIT CLASS
- import static org.junit.Assert.*;
- import org.junit.Test;
- public class tesrer {
- @Test
- public void test() {
- COMp22 gen = new COMp22();
- int[][] right = gen.checker();
- int[][] testMe = gen.doTest();
- for (int i = 0 ; i < gen.SIZE ; i++){
- for (int j = 0 ; j < gen.SIZE; j++){
- System.out.print(testMe[i][j]);
- assertEquals(right[i][j],testMe[i][j]);
- }
- System.out.println();
- }
- }
- }
- //// COMp226 MAIN CLASS
- import java.util.Random;
- public class COMp22 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- }
- public int SIZE = 11;
- public int[][] input = new int[SIZE][SIZE];
- public COMp22(){
- Random generator = new Random();
- for (int i = 0 ; i < SIZE ; i++){
- for (int j = 0 ; j < SIZE ; j++){
- input[i][j] = generator.nextInt(30);
- }
- }
- }
- int[][] doTest(){
- int[][] output = new int[SIZE][SIZE];
- // YOUR CODE HERE
- return output;
- }
- int[][] checker(){
- // Basic test
- int[][] output = new int[SIZE][SIZE];
- int i = 1;
- int j = 1;
- int hori = 0;
- int vert = 0;
- for (i = 1 ; i < SIZE - 1 ; i++){
- for (j = 1 ; j < SIZE - 1 ; j++){
- hori = -1 * (input[i-1][j-1] + input[i-1][j+1]) + -2 * input[i-1][j] + input[i+1][j-1] + 2 * input[i+1][j] + input[i+1][j+1];
- vert = -1 * (input[i-1][j-1] + input[i+1][j-1]) + -2 * input[i][j-1] + input[i-1][j+1] + 2 * input[i][j+1] + input[i+1][j+1];
- output[i][j] = (hori < 0 ? 0 - hori : hori) + (vert < 0 ? 0 - vert : vert);
- }
- }
- i = 0;
- for (i = 0 ; i < SIZE ; i++){
- output[0][i] = 0;
- output[i][0] = 0;
- output[SIZE-1][i] = 0;
- output[i][SIZE-1] = 0;
- }
- return output;
- }
- static void printArray(int[][] x){
- for (int i = 0 ; i < x.length ; i++){
- for (int j = 0 ; j < x.length ; j++){
- if (x[i][j] < 10){
- System.out.print(" " + x[i][j] + " " );
- } else {
- System.out.print(x[i][j] + " " );
- }
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment