Finished
88 * @param {...number} sides
99 */
1010 constructor(...sides) {
11 throw new Error('Remove this line and implement the function');
11 // Edge Case: Invalid number of sides (not exactly 3)
12 if (sides.length !== 3) {
13 throw new Error('Triangle must have exactly 3 sides');
14 }
15
16 // Edge Case: Non-numeric values
17 if (sides.some(side => typeof side !== 'number')) {
18 throw new Error('All sides must be numbers');
19 }
20
21 // Edge Case: NaN values
22 if (sides.some(side => isNaN(side))) {
23 throw new Error('Sides cannot be NaN');
24 }
25
26 // Edge Case: Infinite values
27 if (sides.some(side => !isFinite(side))) {
28 throw new Error('Sides cannot be infinite');
29 }
30
31 this.sides = sides;
1232 }
1333
1434 /**
1535 * @returns {boolean}
1636 */
1737 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
38 // Edge Case: Invalid triangle (sides <= 0)
39 if (this.sides.some(side => side <= 0)) {
40 return false;
41 }
42
43 // Edge Case: Triangle inequality violation
44 if (!this._isValidTriangle()) {
45 return false;
46 }
47
48 const [a, b, c] = this.sides;
49 return a === b && b === c;
1950 }
2051
2152 /**
2253 * @returns {boolean}
2354 */
2455 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
56 // Edge Case: Invalid triangle (sides <= 0)
57 if (this.sides.some(side => side <= 0)) {
58 return false;
59 }
60
61 // Edge Case: Triangle inequality violation
62 if (!this._isValidTriangle()) {
63 return false;
64 }
65
66 const [a, b, c] = this.sides;
67 return a === b || b === c || a === c;
2668 }
2769
2870 /**
2971 * @returns {boolean}
3072 */
3173 get isScalene() {
32 throw new Error('Remove this line and implement the function');
74 // Edge Case: Invalid triangle (sides <= 0)
75 if (this.sides.some(side => side <= 0)) {
76 return false;
77 }
78
79 // Edge Case: Triangle inequality violation
80 if (!this._isValidTriangle()) {
81 return false;
82 }
83
84 const [a, b, c] = this.sides;
85 return a !== b && b !== c && a !== c;
86 }
87
88 /**
89 * Helper method to check if the sides form a valid triangle
90 * @returns {boolean}
91 */
92 _isValidTriangle() {
93 const [a, b, c] = this.sides;
94
95 // All sides must be greater than 0
96 if (a <= 0 || b <= 0 || c <= 0) {
97 return false;
98 }
99
100 // Triangle inequality: sum of any two sides must be >= third side
101 return (a + b >= c) && (b + c >= a) && (a + c >= b);
33102 }
34103}
104
105// Handled Edge Cases: Invalid number of sides, non-numeric values, NaN values, infinite values, sides <= 0, triangle inequality violation
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.