Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 09-07-09   #1 (permalink)
Overclocker
 
tenzo19's Avatar
 
intel ati

Join Date: Jul 2008
Location: Norcal, CA
Posts: 1,290

Rep: 79 tenzo19 is acknowledged by some
Unique Rep: 76
Trader Rating: 14
Default Writing test cases for a java program

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!

System: My System
CPU
Q6600 G0 @ 3.0GHz/1.17V
Motherboard
GA-P35-DS3L
Memory
A-DATA 2x2GB DDR2 800
Graphics Card
Sapphire 4870x2
Hard Drive
WD 640GB
Sound Card
X-Fi Titanium Fatal1ty Professional
Power Supply
OCZ 700W GamerXStream
Case
Rocketfish "Lian-Li"
CPU cooling
D-Tek FuZion V2
GPU cooling
Stock
OS
Windows Vista Ultimate x64
Monitor
2x AL1917W
tenzo19 is offline   Reply With Quote
Old 09-07-09   #2 (permalink)
Programmer
 
newbie1911's Avatar
 
Join Date: Jul 2008
Posts: 319

Rep: 19 newbie1911 Unknown
Unique Rep: 17
Trader Rating: 0
Default

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;
}
}
also im not sure but in c++ you need to add brackets if theres more than one line of code after for
__________________
90% of statistics are made up on the spot. including this one.

Last edited by newbie1911 : 09-07-09 at 07:44 AM
newbie1911 is offline   Reply With Quote
Old 09-07-09   #3 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Nov 2007
Location: Surrey, BC, Canada
Posts: 272

Rep: 14 serge2k Unknown
Unique Rep: 14
Trader Rating: 1
Default

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?
__________________
System: The Black Box
CPU
E6750
Motherboard
Asus P5N-E SLI
Memory
2GB DDR-2 800 MHz
Graphics Card
EVGA 8800 GTS 640
Hard Drive
2x250GB Seagate in Raid 0, 2x1TB WD Caviar Blacks
Sound Card
integrated
Power Supply
Antec Earthwatts 500W
Case
Antec Sonata 3
CPU cooling
Xigmatek HDT S1283
GPU cooling
stock
OS
Windows 7 Ultimate x64
Monitor
22" LG
serge2k is offline   Reply With Quote
Old 09-11-09   #4 (permalink)
AMD Overclocker
 
decompiled's Avatar
 
amd nvidia

Join Date: Feb 2006
Location: Redsox Nation
Posts: 705

Rep: 78 decompiled is acknowledged by some
Unique Rep: 68
Hardware Reviews: 9
Trader Rating: 0
Default

JUnit is your friend when it comes to testing in Java.

System: Slow Poke
CPU
AMD X2 4400
Motherboard
MSI K8N Diamond +
Memory
3gb TCC5
Graphics Card
eVGA 7900GS
Hard Drive
74gb Raptor + Raid 1 640's
Sound Card
Audigy SE
Power Supply
OCZ 600 ModXstream
Case
Antec 1200
CPU cooling
Stock AMD
GPU cooling
Stock eVGA
OS
Windows 7 FTW Edition
Monitor
Dell 1905FP
decompiled is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 05:54 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.12556 seconds with 8 queries