fistinz

Finished
55
66export class Triangle {
77 /**
8 * @param {...number} sides
8 * Creates a Triangle instance with the given sides.
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: Not enough sides provided
13 if (sides.length !== 3) {
14 throw new Error('Exactly three sides must be provided');
15 }
16
17 // Edge Case: Non-numeric values
18 if (sides.some(side => typeof side !== 'number')) {
19 throw new Error('All sides must be numbers');
20 }
21
22 this.sides = sides;
1223 }
1324
1425 /**
15 * @returns {boolean}
26 * Checks if the triangle is equilateral (all sides equal).
27 * @returns {boolean} True if the triangle is equilateral, false otherwise.
28 * Handled Edge Cases: Invalid triangle, zero or negative sides, all sides equal
1629 */
1730 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
31 // Edge Case: Invalid triangle
32 if (!this._isValidTriangle()) {
33 return false;
34 }
35
36 // Edge Case: All sides must be positive
37 if (this.sides.some(side => side <= 0)) {
38 return false;
39 }
40
41 const [a, b, c] = this.sides;
42 return a === b && b === c;
1943 }
2044
2145 /**
22 * @returns {boolean}
46 * Checks if the triangle is isosceles (at least two sides equal).
47 * @returns {boolean} True if the triangle is isosceles, false otherwise.
48 * Handled Edge Cases: Invalid triangle, zero or negative sides, at least two sides equal
2349 */
2450 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
51 // Edge Case: Invalid triangle
52 if (!this._isValidTriangle()) {
53 return false;
54 }
55
56 // Edge Case: All sides must be positive
57 if (this.sides.some(side => side <= 0)) {
58 return false;
59 }
60
61 const [a, b, c] = this.sides;
62 return a === b || b === c || a === c;
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, zero or negative sides, all sides different
3069 */
3170 get isScalene() {
32 throw new Error('Remove this line and implement the function');
71 // Edge Case: Invalid triangle
72 if (!this._isValidTriangle()) {
73 return false;
74 }
75
76 // Edge Case: All sides must be positive
77 if (this.sides.some(side => side <= 0)) {
78 return false;
79 }
80
81 const [a, b, c] = this.sides;
82 return a !== b && b !== c && a !== c;
83 }
84
85 /**
86 * Validates if the sides form a valid triangle according to triangle inequality.
87 * @returns {boolean} True if valid triangle, false otherwise.
88 * Handled Edge Cases: Triangle inequality violation
89 */
90 _isValidTriangle() {
91 const [a, b, c] = this.sides;
92
93 // Edge Case: Triangle inequality violation
94 return (a + b >= c) && (b + c >= a) && (a + c >= b);
3395 }
3496}
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.