|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
Writing test cases for a java program
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
Overclocker
![]() |
I have homework due tomorrow for my Java class and I'm not quite sure how to do testing.
Here is the code I wrote: /** The sum of all integers, k, such that 1 <= k < N and * N is evenly divisible by k. */ static int factorSum (int N) { int sum; sum = 0; for (int k = 1; k < N; k += 1) if (N % k == 0) sum += k; return sum; } In another java file, there is private static boolean test_factorSum () { < fill in your code here > } How do I test the first java file with this second java file? I'm using emacs and gmake.
__________________
Need Windows 7 Ultimate or Office Ultimate 2007? Contact me for a discount!
|
|||||||||||||
|
|
|
|
|
#2 (permalink) |
|
Programmer
|
i know 0 java but it looks similar to c++. so if private static boolean test_factorSum () {
< fill in your code here > } is anything like main in c++ then you would need to insert your first code into the second one like this Code:
private static boolean test_factorSum () {
/** The sum of all integers, k, such that 1 <= k < N and
* N is evenly divisible by k. */
static int factorSum (int N) {
int sum;
sum = 0;
for (int k = 1; k < N; k += 1)
{ //not sure if these are needed in java
if (N % k == 0)
sum += k;
} //not sure if these are needed in java
return sum;
}
}
__________________
90% of statistics are made up on the spot. including this one.
Last edited by newbie1911 : 09-07-09 at 07:44 AM |
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
New to Overclock.net
|
FactorClassName.factorSum(N);
__________________inside of the test function. Remember to import the class file properly too. Is it part of the assignment to use different files?
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
AMD Overclocker
![]() |
JUnit is your friend when it comes to testing in Java.
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|