viola

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.
910 */
1011 constructor(...sides) {
11 throw new Error('Remove this line and implement the function');
12 // Edge Case: Invalid number of sides (not exactly 3)
13 if (sides.length !== 3) {
14 this.sides = [];
15 return;
16 }
17
18 this.sides = sides;
1219 }
1320
1421 /**
15 * @returns {boolean}
22 * Checks if the triangle is equilateral (all sides equal).
23 * @returns {boolean} True if the triangle is equilateral, false otherwise.
24 * Handled Edge Cases: Invalid triangle, non-positive sides, triangle inequality violation, all sides equal
1625 */
1726 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
27 // Edge Case: Not enough sides to form a triangle
28 if (this.sides.length !== 3) return false;
29
30 const [a, b, c] = this.sides;
31
32 // Edge Case: Sides with zero or negative length
33 if (a <= 0 || b <= 0 || c <= 0) return false;
34
35 // Edge Case: Triangle inequality violation
36 if (a + b < c || b + c < a || a + c < b) return false;
37
38 // Edge Case: All sides are equal
39 return a === b && b === c;
40 // Handled Edge Cases: Invalid triangle, non-positive sides, triangle inequality violation, all sides equal
1941 }
2042
2143 /**
22 * @returns {boolean}
44 * Checks if the triangle is isosceles (at least two sides equal).
45 * @returns {boolean} True if the triangle is isosceles, false otherwise.
46 * Handled Edge Cases: Invalid triangle, non-positive sides, triangle inequality violation, at least two sides equal
2347 */
2448 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
49 // Edge Case: Not enough sides to form a triangle
50 if (this.sides.length !== 3) return false;
51
52 const [a, b, c] = this.sides;
53
54 // Edge Case: Sides with zero or negative length
55 if (a <= 0 || b <= 0 || c <= 0) return false;
56
57 // Edge Case: Triangle inequality violation
58 if (a + b < c || b + c < a || a + c < b) return false;
59
60 // Edge Case: At least two sides are equal
61 return a === b || b === c || a === c;
62 // Handled Edge Cases: Invalid triangle, non-positive sides, triangle inequality violation, at least two sides equal
2663 }
2764
2865 /**
29 * @returns {boolean}
66 * Checks if the triangle is scalene (all sides different).
67 * @returns {boolean} True if the triangle is scalene, false otherwise.
68 * Handled Edge Cases: Invalid triangle, non-positive sides, triangle inequality violation, all sides different
3069 */
3170 get isScalene() {
32 throw new Error('Remove this line and implement the function');
71 // Edge Case: Not enough sides to form a triangle
72 if (this.sides.length !== 3) return false;
73
74 const [a, b, c] = this.sides;
75
76 // Edge Case: Sides with zero or negative length
77 if (a <= 0 || b <= 0 || c <= 0) return false;
78
79 // Edge Case: Triangle inequality violation
80 if (a + b < c || b + c < a || a + c < b) return false;
81
82 // Edge Case: All sides are different
83 return a !== b && b !== c && a !== c;
84 // Handled Edge Cases: Invalid triangle, non-positive sides, triangle inequality violation, all sides different
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.