corpus

Finished
55
66export class Triangle {
77 /**
8 * @param {...number} sides
8 * Creates a Triangle instance with the given side lengths.
9 * @param {...number} sides - The lengths of the three sides of the triangle.
910 */
1011 constructor(...sides) {
11 throw new Error('Remove this line and implement the function');
12 // Edge Case: Incorrect number of sides provided
13 if (sides.length !== 3) {
14 throw new Error('Triangle must have exactly 3 sides');
15 }
16
17 this.sides = sides;
1218 }
1319
1420 /**
15 * @returns {boolean}
21 * Checks if the triangle is equilateral (all sides equal).
22 * @returns {boolean} True if the triangle is equilateral, false otherwise.
23 * Handled Edge Cases: Invalid triangles (sides <= 0 or violate triangle inequality)
1624 */
1725 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
26 // Edge Case: Invalid triangle
27 if (!this._isValidTriangle()) {
28 return false;
29 }
30
31 const [a, b, c] = this.sides;
32 return a === b && b === c;
1933 }
2034
2135 /**
22 * @returns {boolean}
36 * Checks if the triangle is isosceles (at least two sides equal).
37 * @returns {boolean} True if the triangle is isosceles, false otherwise.
38 * Handled Edge Cases: Invalid triangles (sides <= 0 or violate triangle inequality)
2339 */
2440 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
41 // Edge Case: Invalid triangle
42 if (!this._isValidTriangle()) {
43 return false;
44 }
45
46 const [a, b, c] = this.sides;
47 return a === b || b === c || a === c;
2648 }
2749
2850 /**
29 * @returns {boolean}
51 * Checks if the triangle is scalene (all sides different).
52 * @returns {boolean} True if the triangle is scalene, false otherwise.
53 * Handled Edge Cases: Invalid triangles (sides <= 0 or violate triangle inequality)
3054 */
3155 get isScalene() {
32 throw new Error('Remove this line and implement the function');
56 // Edge Case: Invalid triangle
57 if (!this._isValidTriangle()) {
58 return false;
59 }
60
61 const [a, b, c] = this.sides;
62 return a !== b && b !== c && a !== c;
63 }
64
65 /**
66 * Validates if the sides form a valid triangle.
67 * @private
68 * @returns {boolean} True if valid triangle, false otherwise.
69 * Handled Edge Cases: Sides with zero/negative length, sides violating triangle inequality
70 */
71 _isValidTriangle() {
72 const [a, b, c] = this.sides;
73
74 // Edge Case: Any side has zero or negative length
75 if (a <= 0 || b <= 0 || c <= 0) {
76 return false;
77 }
78
79 // Edge Case: Violation of triangle inequality
80 if (a + b < c || b + c < a || a + c < b) {
81 return false;
82 }
83
84 return true;
3385 }
3486}
Test NameStatus
all sides are equal
Pass
any side is unequal
Pass
no sides are equal
Pass
all zero sides is not a triangle
Pass
sides may be floats
Pass
last two sides are equal
Pass
first two sides are equal
Pass
first and last sides are equal
Pass
equilateral triangles are also isosceles
Pass
no sides are equal
Pass
first triangle inequality violation
Pass
second triangle inequality violation
Pass
third triangle inequality violation
Pass
sides may be floats
Pass
no sides are equal
Pass
all sides are equal
Pass
first and second sides are equal
Pass
first and third sides are equal
Pass
second and third sides are equal
Pass
may not violate triangle inequality
Pass
sides may be floats
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.