Skip to content

Commit 19114ce

Browse files
authored
Merge pull request #8 from Saikowsik23/main
made changes to unit-conversions geometry (even in tests)
2 parents 1504ae0 + 8ad1e3e commit 19114ce

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

adv-math/src/geometry-trigonometry/geometry.js

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ class Geometry {
3333
static equilateralTriangleArea(side) {
3434
return (Math.sqrt(3) / 4) * Math.pow(side, 2);
3535
}
36+
//Method to calulate the area of the triangle given its side lengths
37+
static triangleArea_sides(side1, side2, side3) {
38+
const s = (side1 + side2 + side3) / 2;
39+
return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
40+
}
41+
//Method to calulate the area of a square given its side length
42+
static squareArea(side) {
43+
return Math.pow(side, 2);
44+
}
45+
//Method to calculate the perimeter of a square given its side length
46+
static squarePerimeter(side) {
47+
return 4 * side;
48+
}
3649

3750
// Method to calculate the volume of a cube given its side length
3851
static cubeVolume(side) {

adv-math/src/units-conversions/units.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@ class Units {
1818
static convertTemperature(value, fromUnit, toUnit) {
1919
if (fromUnit === 'Celsius' && toUnit === 'Fahrenheit') {
2020
return (value * 9 / 5) + 32;
21+
} else if (fromUnit=='Celsius' && toUnit=='Kelvin') {
22+
return value + 273.15;
2123
} else if (fromUnit === 'Fahrenheit' && toUnit === 'Celsius') {
2224
return (value - 32) * 5 / 9;
23-
} else {
25+
} else if (fromUnit=='Fahrenheit' && toUnit=='Kelvin') {
26+
return (value + 459.67) * 5 / 9;
27+
} else if (fromUnit=='Kelvin' && toUnit=='Celsius') {
28+
return value - 273.15;
29+
} else if (fromUnit=='Kelvin' && toUnit=='Fahrenheit') {
30+
return (value * 9 / 5) - 459.67;
31+
}
32+
33+
else {
2434
throw new Error('Invalid temperature unit conversion.');
2535
}
2636
}

adv-math/tests/geometry-trigonometry.test.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,45 @@ describe('Geometry', () => {
1717
test('calculates the circumference of a circle', () => {
1818
expect(Geometry.circleCircumference(3)).toBeCloseTo(18.850, 3);
1919
});
20-
20+
test('calculates the area of a triangle', () => {
21+
expect(Geometry.triangleArea(3, 4)).toBe(6);
22+
});
23+
test('calculates the volume of a sphere', () => {
24+
expect(Geometry.sphereVolume(3)).toBeCloseTo(113.097, 3);
25+
});
26+
test('calculates the area of an equilateral triangle', () => {
27+
expect(Geometry.equilateralTriangleArea(3)).toBeCloseTo(3.897, 3);
28+
});
29+
test('calculates the area of a triangle given its side lengths', () => {
30+
expect(Geometry.triangleArea_sides(3, 4, 5)).toBe(6);
31+
});
32+
test('calculates the area of a square given its side length', () => {
33+
expect(Geometry.squareArea(3)).toBe(9);
34+
});
35+
test('calculates the perimeter of a square given its side length', () => {
36+
expect(Geometry.squarePerimeter(3)).toBe(12);
37+
});
38+
test('calculates the volume of a cube given its side length', () => {
39+
expect(Geometry.cubeVolume(3)).toBe(27);
40+
});
41+
test('calculates the volume of a rectangular prism given length, width, and height', () => {
42+
expect(Geometry.rectangularPrismVolume(3, 4, 5)).toBe(60);
43+
});
44+
test('calculates the surface area of a rectangular prism given length, width, and height', () => {
45+
expect(Geometry.rectangularPrismSurfaceArea(3, 4, 5)).toBe(94);
46+
});
47+
test('calculates the volume of a cylinder given radius and height', () => {
48+
expect(Geometry.cylinderVolume(3, 5)).toBeCloseTo(141.371, 3);
49+
});
50+
test('calculates the surface area of a cylinder given radius and height', () => {
51+
expect(Geometry.cylinderSurfaceArea(3, 5)).toBeCloseTo(150.796, 3);
52+
});
53+
test('calculates the volume of a cone given radius and height', () => {
54+
expect(Geometry.coneVolume(3, 5)).toBeCloseTo(47.123, 3);
55+
});
56+
test('calculates the surface area of a cone given radius and height', () => {
57+
expect(Geometry.coneSurfaceArea(3, 5)).toBeCloseTo(83.229, 3);
58+
});
2159
// Add more test cases as needed
2260
});
2361

adv-math/tests/units-conversions.test.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ describe('Units', () => {
1212
test('converts Celsius to Fahrenheit', () => {
1313
expect(Units.convertTemperature(25, 'Celsius', 'Fahrenheit')).toBeCloseTo(77, 1);
1414
});
15-
15+
test('converts Celsius to Kelvin', () => {
16+
expect(Units.convertTemperature(25, 'Celsius', 'Kelvin')).toBeCloseTo(298.15, 1);
17+
});
18+
test('converts Fahrenheit to Kelvin', () => {
19+
expect(Units.convertTemperature(68, 'Fahrenheit', 'Kelvin')).toBeCloseTo(293.15, 1);
20+
});
1621
test('converts Fahrenheit to Celsius', () => {
1722
expect(Units.convertTemperature(68, 'Fahrenheit', 'Celsius')).toBeCloseTo(20, 1);
1823
});
24+
test('converts Kelvin to Celsius', () => {
25+
expect(Units.convertTemperature(300, 'Kelvin', 'Celsius')).toBeCloseTo(26.85, 1);
26+
});
27+
test('converts Kelvin to Fahrenheit', () => {
28+
expect(Units.convertTemperature(300, 'Kelvin', 'Fahrenheit')).toBeCloseTo(80.33, 1);
29+
});
1930

2031
// Add more test cases as needed
2132
});

0 commit comments

Comments
 (0)