Last active
September 22, 2015 11:53
-
-
Save jayeshcp/d063e618bbf5b1f257b7 to your computer and use it in GitHub Desktop.
Basic jUnit Test Case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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