agent

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 triangle's sides.
10 * @throws {Error} If the number of sides is not exactly three.
911 */
1012 constructor(...sides) {
11 throw new Error('Remove this line and implement the function');
13 // Edge Case: Incorrect number of sides provided
14 if (sides.length !== 3) {
15 throw new Error('A triangle must have exactly three sides');
16 }
17
18 this.sides = sides;
1219 }
1320
1421 /**
15 * @returns {boolean}
22 * Checks if the sides form a valid triangle.
23 * A valid triangle must have all sides with length > 0,
24 * and the sum of any two sides must be greater than or equal to the third side.
25 * @returns {boolean} True if the sides form a valid triangle, false otherwise.
26 * @private
27 */
28 _isValidTriangle() {
29 const [a, b, c] = this.sides;
30
31 // Edge Case: Any side has length <= 0
32 if (a <= 0 || b <= 0 || c <= 0) {
33 return false;
34 }
35
36 // Edge Case: Triangle inequality violation
37 if (a + b < c || b + c < a || a + c < b) {
38 return false;
39 }
40
41 return true;
42 }
43
44 /**
45 * Determines if the triangle is equilateral (all sides equal).
46 * @returns {boolean} True if the triangle is equilateral, false otherwise.
1647 */
1748 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
49 // Edge Case: Invalid triangle
50 if (!this._isValidTriangle()) {
51 return false;
52 }
53
54 const [a, b, c] = this.sides;
55
56 // Edge Case: All sides are equal
57 return a === b && b === c;
1958 }
2059
2160 /**
22 * @returns {boolean}
61 * Determines if the triangle is isosceles (at least two sides equal).
62 * @returns {boolean} True if the triangle is isosceles, false otherwise.
2363 */
2464 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
65 // Edge Case: Invalid triangle
66 if (!this._isValidTriangle()) {
67 return false;
68 }
69
70 const [a, b, c] = this.sides;
71
72 // Edge Case: At least two sides are equal
73 return a === b || b === c || a === c;
2674 }
2775
2876 /**
29 * @returns {boolean}
77 * Determines if the triangle is scalene (all sides different).
78 * @returns {boolean} True if the triangle is scalene, false otherwise.
3079 */
3180 get isScalene() {
32 throw new Error('Remove this line and implement the function');
81 // Edge Case: Invalid triangle
82 if (!this._isValidTriangle()) {
83 return false;
84 }
85
86 const [a, b, c] = this.sides;
87
88 // Edge Case: All sides are different
89 return a !== b && b !== c && a !== c;
3390 }
3491}
92
93// Handled Edge Cases:
94// - Incorrect number of sides provided to constructor
95// - Invalid triangle (sides <= 0)
96// - Triangle inequality violation
97// - Valid equilateral triangle
98// - Valid isosceles triangle
99// - Valid scalene triangle
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.