Skip to content

Instantly share code, notes, and snippets.

@jayeshcp
Last active September 22, 2015 11:53
Show Gist options
  • Save jayeshcp/d063e618bbf5b1f257b7 to your computer and use it in GitHub Desktop.
Save jayeshcp/d063e618bbf5b1f257b7 to your computer and use it in GitHub Desktop.
Basic jUnit Test Case
/**
* Sample class file for above unit tests
*/
public class QueryBoard {
int[] nums;
QueryBoard() {
nums = new int[10];
}
public void setNums(int min, int max, int step) {
for (int i = min; ( i < nums.length() && ( i <= max ) ); i++) {
nums[i] = i;
}
}
public int queryNums(int min, int max) {
int result = 0;
for (int i = min; ( i < nums.length() && ( i <= max ) ); i++) {
result += i;
}
return result;
}
}
import java.util.*;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Unit test suite
*/
public class QueryBoardTest {
/**
* Test case 1
*/
@Test
public void testRows() {
QueryBoard board = new QueryBoard();
for(int i = 0; i < QueryBoard.SIZE; i++) {
board.setNums(0, i, 10);
assertEquals(board.queryNums(0, i), 2560);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment