Algorithms and OOD (CSC 207 2014F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [Learning Outcomes] [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Student-Curated Resources] [Java 8 API] [Java 8 Tutorials] [Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2014S (Rebelsky)] [CSC 207 2014F (Walker)] [CSC 207 2011S (Weinman)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
average before
writing the tests. But that's backwards. If you write the tests first,
and think about the corner cases, you'll be much more likely to
understand likely problems.Question: In the second half of the semester, you will do a project. There are three possibilities right now.
We'll do a quick discussion and then come back to the question immediately after break.
Issues
public interface Sorter
With only the "it's sorted" postcondition, the following algorithm meets the requirements
for (int i = 1; i < whatever.length; ++i)
whatever[i] = whatever[0];
public void assertSorted(T[] whatever, Comparator<T> order)
{
for (int j = 1; j < whatever.length; j++)
{
if (order.compare(T[j-1],T[j]) > 0)
fail("Order failed at position " + j);
} // for
} // assertSorted
public Comparator<Integer> normalIntComparator =
(x,y) -> (x.compareTo(y));
public Comparator<Integer> closerToZero =
(x,y) -> { if (Math.abs(x) < Math.abs(y))
return -1;
else if (Math.abs(x) == Math.abs(y))
return 0;
else
return 1;
}
@Test
public void testEmpty()
{
Integer[] empty = new Integer[0];
arraySort(empty, normalIntegerComparor);
assertSorted(empty, normalIntegerComparor);
} // testEmpty
@Test
public void testFoo()
{
Integer[] foo = new Integer[] { 11, 1, 2, 5, 0, -4, 6 } ;
arraySort(foo, normalIntegerComparator);
assertSorted(foo, normalIntegerComparator);
} // testFoo
@Test
public void testOne()
{
}
@Test
public void testTwo()
{
}
@Test
public void testThree()
{
}