- Section 1: Introduction
- Section 2: How to classify
- Section 3: What is a Line Segment
- Section 4: What is a Triangle
- Section 5: What is a Rectangle
- Section 6: What is the Other shape
This is to serve as documentation of the minimum test cases you should have if creating a new language. It details the expected behavior of each shape.
The way these test cases is written may unintentionally favor an Object Oriented paradigm. If you find that to be true, please understand it is not the intent of this document. Please report it to me, or fix it and submit a pull request.
This will verify that if "classify" is given no points then shape returned is a special case shape called "Empty".
This will verify that if a single point is given then a single point is returned.
Optionally, this can verify that it has the same value as the point given. However, if not done in this test then a separate test needs to be written to verify this. Different languages handle this differently so I leave it to the writer's discretion.
This will verify if given two different points a "Line Segment" is returned.
This will verify that given two points that are in the same location then the shape returned is a special condition shape called "Other".
Classify should classify four points where the first three are distinct and different points, but the first and last are the same as 'Triangle'
This will verify if given points that meet the following criteria that a "Triangle" is returned.
- There are four points.
- The shape is closed. (The first point and last point are in the same location.)
- Each of the first three points are different.
Note: This is the first time we are testing a "closed" shape. A closed shape is one where the first and last point are in the same location, thereby creating a line segment from the last logical point to the first.
This will verify that if we have an "open" shape, then the shape returned is the special case shape called "Other".
This will verify that if we have a closed shape that has one or more of the first three points duplicated that it will return the special case shape called "Other".
Classify should classify a closed shape with five points where the first four are distinct and every three points forms right angles as a 'Rectangle'
This will verify that if the points meet the following conditions a "Rectangle" is returned.
- There are five points.
- The points form a closed shape.
- The first four are distinct and different.
- Every two adjoining line segments form a 90 degree angle.
This test will verify that if given an open shape composed of five distinct and different points that the special case shape called "Other" is returned.
This test will verify that if give a closed shape with five points, but the first four have duplication in the location then it will return the special case shape "Other".
Classify should classify five points that form a closed shape, but do not form right angles as 'Other'
This will verify that if given a shape where the adjoining legs do not form right angle even when it is a closed shape of five points that the special case shape "Other" is returned.
Note: A line segment should only be constructable from the "Classify" method/function. The test cases should not be able to construct it directly.
This will verify that the line segment returned from the classification process gives access to the points that define it.
This will verify that a line segment will have access to the correct length based on the points that were given.
Note: Length is determined by the absolute value of the following formula:
√((x₁ - x₂)² + (y₁ - y₂)²)
This will verify that a line segment will have access to the correct slope based on the points that were given.
Note: The slope is determined by the following formula:
(y₂ - y₁)/(x₂ - x₁)
This will verify that a line that is straight on the x value will have an undefined slope.
Note: A triangle should only be constructable from the "Classify" method/function. The test cases should not be able to construct it directly.
This will verify that a triangle returned from the classification process will grant access to the first three distinct points that were given to the process.
This will verify that the Triangle will grant access to three line segments forming its sides. The Sides will have the names:
- Side A
- Side B
- Side C
This will verify that the Triangle will have the expected angles such that:
- "Angle A" is opposite "Side A"
- "Angle B" is opposite "Side B"
- "Angle C" is opposite "Side C"
- All angles add up to 180 degrees.
- The degrees of each angle is correctly calculated.
Note: The angle in degrees can be calculated using the following formula:
A = length of Side A
B = length of Side B
C = length of Side C
∠A = ACOS((B² + C² - A²) / (2BC))(180/π)
∠B = ACOS((A² + C² - B²) / (2AC))(180/π)
∠C = ACOS((A² + B² - C²) / (2AB))(180/π)
This will verify that a Triangle will grant access to its area which is correctly calculated.
Note: The area of a triangle can be calculated using Heron's Formula. (Thanks to omnicalculator).
A = length of Side A
B = length of Side B
C = length of Side C
area = ¼√((A + B + C)(-A + B + C)(A - B + C)(A + B - C))
This will verify that the Triangle will grant access to its perimeter which will be equal to the sum of its three side lengths.
Note: A rectangle should only be constructable from the "Classify" method/function. The test cases should not be able to construct it directly.
This will verify that the Rectangle returned from the classification process will grant access to the distinct points form the collection used by the classification process.
This will verify that a Rectangle will grant access to the four line segments that form its sides. Such that:
- Side A - First line segment formed from the first two points provided.
- Side B - Second line segment formed from the second and third points provided.
- Side C - Third line segment formed from the third and fourth point provided.
- Side D - Fourth line segment formed from the fourth and first/fifth point provided.
This will verify that the rectangle will grant access to its area and its area is calculated correctly.
Note: the area of a Rectangle can be calculated using this formula:
(hight)(width)
This will verify that the rectangle will grant access to its perimeter and its perimeter is the same as the sum of its side lengths.
Note: The other shape should only be constructable from the "Classify" method/function. The test cases should not be able to construct it directly.
This will verify that the Other shape returned from the classification process contains all points used by the classification process in classifying it as other.
This will verify that the Other shape will grant access to knowing if the shape is closed or open such that:
- A closed shape is one where the first and last point are in the same location.
This will verify that the Other shape will grant access to knowing if the shape is open or closed such that:
- A closed shape is one where the first and last point are in the same location.
This will verify that the Other shape will grant access to its length and its length will be the sum of all lines segments constructed from its points.