Boundary values testing

Boundary testing values focuses on testing the boundary values of your program, like class invariants implemented using if statements, etc.

Example: class Student: A student has a name, which must be at least 2 characters long.

We must then test Student using the following test cases

Further reading http://extremesoftwaretesting.com/Techniques/BoundaryValues.html

LineSegment

In this exercise you must program a class LineSegment, which is basically two points x1 and x2, where x1 <= x2.
x1 and x2 should be of type int.

Inspiration?

Make one method and test it (with good coverage) before you start making the next method.
You can do test-first or test-after as you like, but you must test one method before you implement the next method

  1. Constructor LineSegment(int x1, int x2)
    must throw an appropriate exception, if x2 < x1     Test it!
  2. read-only properties X1 and X2.
  3. override the ToString() method.
    ReSharper (plug-in for Visual Studio) can help you to make the method. Type Alt + Insert, chose "Overriding members"
  4. boolean contains(int x)
    returns true if x1 <= x <= x2        Test it!
    Try to implement the method without using if statements.
  5. boolean contains(LineSegment anotherSegment)
    returns true if anotherSegment is "inside" this segment    Test it!
  6. boolean intersects(LineSegment anotherSegment)
    returns true if this segment overlaps anotherSegment    Test it!
  7. override boolean Equals(object obj) + implement the interface IEquatable<LineSegment>
    returns true if obj is equal to this segment.
    Resharper can help you make this. Type Alt + Insert, chose "Equality members"
  8. LineSegment intersection(LineSegment anotherSegment)
    Returns a new LineSegment, the intersection of this segment and anotherSegment. The result might be the empty segment in which case you must return null.

LineSegmentDouble

In this exercise you must program a class LineSegmentDouble. This is very similar to LineSegment, except that x1 and x2 are now double (not int).

In Visual Studio make a copy of the LineSegment class, rename it LineSegmentDouble, and adapt it to use double.

Do the same with the LineSegmentTest class.
In the test class you must use a special version of Assert.equals(expected, actual, delta), where delta is a very small number (like 0.00001).

Extra: Rectangle 2D

Now lets add another dimension: Make a class Rectangle (x1, x2, y1, y2)
The rectangle has to oppisite corners (x1, y1) and (x2, y2).

Similar methods as LineSegment - and testing!

Extra Extra: Box 3D

Add yet another dimension: Make a class Box(x1, x2, y1, y2, z1, z2)