Algorithms and OOD (CSC 207 2014S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
For your unit testing, the following is not a great test statement
for (int base = -100; base < 100; base++) { expected = 1; for (int power = 0; power < 10; power++) { assertEquals ("Testing", expected, SampleMethods.expt (base, power)); expected *= base; } // for each power } // for each base
If the test fails, you'll only see the "Testing" message. You'd probably prefer to see the base and power too.
assertEquals ("Testing " + base + "^" + power,
expected, SampleMethods.expt (base, power));
I'll admit that I often end up doing something like
int result = SampleMethods.expt (base, power);
if (result != expected)
{
fail ("For " + base + "^" + power + ", expected " +
expected + ", got " + result);
} // if we did not get the expected result.
Doesn't 100^10 overflow? You probably want to have a more sensible stopping condition (perhaps involving a while loop).
double version, you'll probably need to have a
"close enough" metric (see documentation).
assertEquals (message, expected, formula, ACCURACY)Are you okay with the seemingly inefficient looping (or recursive) solution
to isOdd?
Yes.
But smart programmers who think in C can probably find a more efficient solution.
Can we use a loop for oddSumTo?
Yes, but you shouldn't need one.
Context:
Design Issues:
Objects
Time
Incidents
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013-14 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.