~cpp
/**
* @author Administrator
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
import junit.framework.*;
public class TestLoadBalancing extends TestCase{
public void testSetNGetData() {
LoadBalancing bal = new LoadBalancing(3);
int sData[] = {1,3,3};
int gData[];
bal.setData(sData);
gData = bal.getData();
for(int i=0; i<sData.length; i++)
assertEquals(sData[i], gData[i]);
}
public void testGetSumOfJob() {
LoadBalancing bal = new LoadBalancing(3);
int data[]={1,3,4};
bal.setData(data);
assertEquals(bal.getSumOfJob(), 8);
assertEquals(bal.getMaximumJob(), 4);
assertEquals(bal.getMinimumJob(), 1);
}
public void testCheckLeftRight() {
LoadBalancing bal = new LoadBalancing(10);
/*int data[]={1,2,3,4,5,6,7,8,9,10};
bal.setData(data);
assertEquals(bal.checkLeft(0), false);
assertEquals(bal.checkLeft(1), true);
assertEquals(bal.checkLeft(2), true);
assertEquals(bal.checkLeft(3), true);
assertEquals(bal.checkLeft(4), true);
assertEquals(bal.checkLeft(5), true);
assertEquals(bal.checkLeft(6), true);
assertEquals(bal.checkLeft(7), true);
assertEquals(bal.checkLeft(8), true);
assertEquals(bal.checkLeft(9), true);
assertEquals(bal.checkRight(0), false);
assertEquals(bal.checkRight(1), false);
assertEquals(bal.checkRight(2), false);
assertEquals(bal.checkRight(3), false);
assertEquals(bal.checkRight(4), false);
assertEquals(bal.checkRight(5), false);
assertEquals(bal.checkRight(6), false);
assertEquals(bal.checkRight(7), false);
assertEquals(bal.checkRight(8), false);
assertEquals(bal.checkRight(9), false);
int data_[] = {5,5,5,5,5,5,5,5,5,10};
bal.setData(data_);
assertEquals(bal.checkLeft(0), false);
assertEquals(bal.checkLeft(1), false);
assertEquals(bal.checkLeft(2), false);
assertEquals(bal.checkLeft(3), false);
assertEquals(bal.checkLeft(4), false);
assertEquals(bal.checkLeft(5), true);
assertEquals(bal.checkLeft(6), true);
assertEquals(bal.checkLeft(7), true);
assertEquals(bal.checkLeft(8), true);
assertEquals(bal.checkLeft(9), true);
assertEquals(bal.checkRight(0), false);
assertEquals(bal.checkRight(1), false);
assertEquals(bal.checkRight(2), false);
assertEquals(bal.checkRight(3), false);
assertEquals(bal.checkRight(4), false);
assertEquals(bal.checkRight(5), false);
assertEquals(bal.checkRight(6), false);
assertEquals(bal.checkRight(7), false);
assertEquals(bal.checkRight(8), false);
assertEquals(bal.checkRight(9), false);
int data__[] = {10,9,8,7,6,5,4,3,2,1};
bal.setData(data__);
assertEquals(bal.checkLeft(0), false);
assertEquals(bal.checkLeft(1), false);
assertEquals(bal.checkLeft(2), false);
assertEquals(bal.checkLeft(3), false);
assertEquals(bal.checkLeft(4), false);
assertEquals(bal.checkLeft(5), false);
assertEquals(bal.checkLeft(6), false);
assertEquals(bal.checkLeft(7), false);
assertEquals(bal.checkLeft(8), false);
assertEquals(bal.checkLeft(9), false);
assertEquals(bal.checkRight(0), true);
assertEquals(bal.checkRight(1), true);
assertEquals(bal.checkRight(2), true);
assertEquals(bal.checkRight(3), true);
assertEquals(bal.checkRight(4), true);
assertEquals(bal.checkRight(5), true);
assertEquals(bal.checkRight(6), true);
assertEquals(bal.checkRight(7), true);
assertEquals(bal.checkRight(8), true);
assertEquals(bal.checkRight(9), false);*/
bal = new LoadBalancing(10);
int data___[]={13,13,13,13,13,14,14,15,13,13};
bal.setData(data___);
//assertEquals(true, bal.checkRight(7));
//assertEquals(true, bal.checkLeft(7));
}
public void testLoadBalancing() {
LoadBalancing bal = new LoadBalancing(3);
int data[]={0,3,0};
bal.setData(data);
bal.loadBalance();
bal.printInfo();
bal = new LoadBalancing(10);
int data_[] = {1,2,3,4,5,6,7,8,9,10};
bal.setData(data_);
bal.loadBalance();
bal.printInfo();
bal = new LoadBalancing(10);
int data__[]={5,0,10,6,1,49,1,50,3,9};
assertEquals(10, data__.length);
bal.setData(data__);
bal.loadBalance();
bal.printInfo();
bal = new LoadBalancing(10);
int data___[]={13,13,13,13,13,13,13,13,15,14};
bal.setData(data___);
bal.loadBalance();
bal.printInfo();
bal = new LoadBalancing(10);
int data____[]={0,9,0,0,0,0,0,0,0,0};
bal.setData(data____);
bal.loadBalance();
bal.printInfo();
}
}