Guest User

Untitled

a guest
Jan 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. /// TESTRER JUNIT CLASS
  2.  
  3.  
  4. import static org.junit.Assert.*;
  5.  
  6. import org.junit.Test;
  7.  
  8.  
  9. public class tesrer {
  10.  
  11. @Test
  12. public void test() {
  13.  
  14. COMp22 gen = new COMp22();
  15.  
  16. int[][] right = gen.checker();
  17. int[][] testMe = gen.doTest();
  18.  
  19. for (int i = 0 ; i < gen.SIZE ; i++){
  20. for (int j = 0 ; j < gen.SIZE; j++){
  21. System.out.print(testMe[i][j]);
  22. assertEquals(right[i][j],testMe[i][j]);
  23. }
  24. System.out.println();
  25. }
  26.  
  27. }
  28.  
  29. }
  30. //// COMp226 MAIN CLASS
  31.  
  32.  
  33. import java.util.Random;
  34.  
  35.  
  36. public class COMp22 {
  37.  
  38. public static void main(String[] args) {
  39. // TODO Auto-generated method stub
  40.  
  41. }
  42.  
  43. public int SIZE = 11;
  44. public int[][] input = new int[SIZE][SIZE];
  45.  
  46.  
  47.  
  48. public COMp22(){
  49. Random generator = new Random();
  50. for (int i = 0 ; i < SIZE ; i++){
  51. for (int j = 0 ; j < SIZE ; j++){
  52. input[i][j] = generator.nextInt(30);
  53. }
  54. }
  55.  
  56. }
  57.  
  58.  
  59. int[][] doTest(){
  60. int[][] output = new int[SIZE][SIZE];
  61.  
  62. // YOUR CODE HERE
  63.  
  64. return output;
  65. }
  66.  
  67.  
  68. int[][] checker(){
  69. // Basic test
  70. int[][] output = new int[SIZE][SIZE];
  71. int i = 1;
  72. int j = 1;
  73. int hori = 0;
  74. int vert = 0;
  75. for (i = 1 ; i < SIZE - 1 ; i++){
  76. for (j = 1 ; j < SIZE - 1 ; j++){
  77. 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];
  78. 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];
  79. output[i][j] = (hori < 0 ? 0 - hori : hori) + (vert < 0 ? 0 - vert : vert);
  80. }
  81. }
  82. i = 0;
  83. for (i = 0 ; i < SIZE ; i++){
  84. output[0][i] = 0;
  85. output[i][0] = 0;
  86. output[SIZE-1][i] = 0;
  87. output[i][SIZE-1] = 0;
  88. }
  89. return output;
  90. }
  91.  
  92.  
  93. static void printArray(int[][] x){
  94. for (int i = 0 ; i < x.length ; i++){
  95. for (int j = 0 ; j < x.length ; j++){
  96. if (x[i][j] < 10){
  97. System.out.print(" " + x[i][j] + " " );
  98. } else {
  99. System.out.print(x[i][j] + " " );
  100. }
  101.  
  102. }
  103. System.out.println();
  104. }
  105. }
  106.  
  107. }
Add Comment
Please, Sign In to add comment