CS计算机代考程序代写 junit /**

/**
* These test cases are provided to assist your implementation.
* However, note that these test cases may not be used in actual marking.
* You are encouraged to write your own test case to test the correctness
* of your implementation.
*/
package Midterm.Q1;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

public class BinarySearchTest {
Element[][] testMatrix;
BinarySearch bs = new BinarySearch();

@Before
public void beforeTest(){
testMatrix = new Element[10][10];
int _key = 1;
for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ testMatrix[i][j] = new Element(_key,_key+1);
_key++;
// System.out.println(_key);
}
}
}

@Test(timeout=1000)
public void Test1(){
Element expected1 = new Element(1,2);
Element actual1 = bs.search(testMatrix,0,9,0,9,1);
assertEquals(expected1.key, actual1.key);
assertEquals(expected1.value, actual1.value);
}

@Test(timeout=1000)
public void Test2(){
Element expected2 = new Element(10,11);
Element actual2 = bs.search(testMatrix,0,9,0,9,10);
assertEquals(expected2.key, actual2.key);
assertEquals(expected2.value, actual2.value);
}

@Test(timeout=1000)
public void Test3(){
Element expected3 = new Element(32,33);
Element actual3 = bs.search(testMatrix,0,9,0,9,32);
assertEquals(expected3.key, actual3.key);
assertEquals(expected3.value, actual3.value);
}

@Test(timeout=1000)
public void Test4(){
Element expected4 = new Element(57,58);
Element actual4 = bs.search(testMatrix,0,9,0,9,57);
assertEquals(expected4.key, actual4.key);
assertEquals(expected4.value, actual4.value);
}

@Test(timeout=1000)
public void Test5(){
assertEquals(null, bs.search(testMatrix,0,9,0,9,101));
}

@Test(timeout=1000)
public void Test6(){
Element expected4 = new Element(45,46);
Element actual4 = bs.search(testMatrix,0,9,0,9,45);
assertEquals(expected4.key, actual4.key);
assertEquals(expected4.value, actual4.value);
}
}