Konoha

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: Ensure exactly three sides are provided
13 if (sides.length !== 3) {
14 throw new Error('A triangle must have exactly three sides');
15 }
16
17 // Edge Case: Ensure all sides are numbers
18 if (sides.some(side => typeof side !== 'number')) {
19 throw new Error('All sides must be numbers');
20 }
21
22 this.sides = sides;
23
24 // Edge Case: Ensure all sides are positive
25 if (this.sides.some(side => side <= 0)) {
26 this.isValidTriangle = false;
27 return;
28 }
29
30 // Edge Case: Check triangle inequality theorem
31 const [a, b, c] = this.sides;
32 if ((a + b < c) || (b + c < a) || (a + c < b)) {
33 this.isValidTriangle = false;
34 return;
35 }
36
37 this.isValidTriangle = true;
1238 }
1339
1440 /**
15 * @returns {boolean}
41 * Checks if the triangle is equilateral (all sides equal).
42 * @returns {boolean} True if the triangle is equilateral, false otherwise.
1643 */
1744 get isEquilateral() {
18 throw new Error('Remove this line and implement the function');
45 // Edge Case: Invalid triangle
46 if (!this.isValidTriangle) {
47 return false;
48 }
49
50 const [a, b, c] = this.sides;
51 return a === b && b === c;
1952 }
2053
2154 /**
22 * @returns {boolean}
55 * Checks if the triangle is isosceles (at least two sides equal).
56 * @returns {boolean} True if the triangle is isosceles, false otherwise.
2357 */
2458 get isIsosceles() {
25 throw new Error('Remove this line and implement the function');
59 // Edge Case: Invalid triangle
60 if (!this.isValidTriangle) {
61 return false;
62 }
63
64 const [a, b, c] = this.sides;
65 return a === b || b === c || a === c;
2666 }
2767
2868 /**
29 * @returns {boolean}
69 * Checks if the triangle is scalene (all sides different).
70 * @returns {boolean} True if the triangle is scalene, false otherwise.
3071 */
3172 get isScalene() {
32 throw new Error('Remove this line and implement the function');
73 // Edge Case: Invalid triangle
74 if (!this.isValidTriangle) {
75 return false;
76 }
77
78 const [a, b, c] = this.sides;
79 return a !== b && b !== c && a !== c;
3380 }
3481}
82
83// Handled Edge Cases:
84// - Invalid number of sides (not exactly 3)
85// - Non-numeric side values
86// - Non-positive side lengths
87// - Triangle inequality violation
88// - Checking properties on invalid triangles
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.