From b52b3bed4a943b815f55a785f7e387ed38894743 Mon Sep 17 00:00:00 2001 From: lcvieira2001 Date: Sun, 30 Oct 2022 02:43:00 -0300 Subject: [PATCH 1/3] Added sphere volume --- Geometry/SphereVolume.js | 7 +++++++ Geometry/Test/SphereVolume.test.js | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100644 Geometry/SphereVolume.js create mode 100644 Geometry/Test/SphereVolume.test.js diff --git a/Geometry/SphereVolume.js b/Geometry/SphereVolume.js new file mode 100644 index 0000000000..9493a45c4c --- /dev/null +++ b/Geometry/SphereVolume.js @@ -0,0 +1,7 @@ +// https://en.wikipedia.org/wiki/Sphere rounds to 2 decimal places +const sphereVolume = (radius) => { + const volume = Math.pow(radius, 3) * Math.PI * 4 / 3 + return parseFloat(volume.toFixed(2)) +} + +export { sphereVolume } diff --git a/Geometry/Test/SphereVolume.test.js b/Geometry/Test/SphereVolume.test.js new file mode 100644 index 0000000000..4c5ff9a338 --- /dev/null +++ b/Geometry/Test/SphereVolume.test.js @@ -0,0 +1,8 @@ +import { sphereVolume } from '../SphereVolume' + +describe('SphereVolume', () => { + it('should return the sphere volume given the radius', () => { + const res = sphereVolume(3) + expect(res).toEqual(113.1) + }) +}) From 6abb5f308c300dd1a07fa3b290802f70d7f266fb Mon Sep 17 00:00:00 2001 From: lcvieira2001 Date: Sun, 30 Oct 2022 12:01:46 -0300 Subject: [PATCH 2/3] Fixed indentation --- Geometry/Sphere.js | 19 +++++++++++++++++++ Geometry/SphereVolume.js | 7 ------- Geometry/Test/Sphere.test.js | 11 +++++++++++ Geometry/Test/SphereVolume.test.js | 8 -------- 4 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 Geometry/Sphere.js delete mode 100644 Geometry/SphereVolume.js create mode 100644 Geometry/Test/Sphere.test.js delete mode 100644 Geometry/Test/SphereVolume.test.js diff --git a/Geometry/Sphere.js b/Geometry/Sphere.js new file mode 100644 index 0000000000..f3110928c2 --- /dev/null +++ b/Geometry/Sphere.js @@ -0,0 +1,19 @@ +/** + * This class represents a sphere and can calculate its volume and surface area + * https://en.wikipedia.org/wiki/Sphere + * @constructor + * @param {number} radius - The radius of the sphere + */ +export default class Sphere { + constructor (radius) { + this.radius = radius + } + + volume = () => { + return Math.pow(this.radius, 3) * Math.PI * 4 / 3 + } + + surfaceArea = () => { + return Math.pow(this.radius, 2) * Math.PI * 4 + } +} diff --git a/Geometry/SphereVolume.js b/Geometry/SphereVolume.js deleted file mode 100644 index 9493a45c4c..0000000000 --- a/Geometry/SphereVolume.js +++ /dev/null @@ -1,7 +0,0 @@ -// https://en.wikipedia.org/wiki/Sphere rounds to 2 decimal places -const sphereVolume = (radius) => { - const volume = Math.pow(radius, 3) * Math.PI * 4 / 3 - return parseFloat(volume.toFixed(2)) -} - -export { sphereVolume } diff --git a/Geometry/Test/Sphere.test.js b/Geometry/Test/Sphere.test.js new file mode 100644 index 0000000000..c7db827819 --- /dev/null +++ b/Geometry/Test/Sphere.test.js @@ -0,0 +1,11 @@ +import Sphere from '../Sphere' + +const sphere = new Sphere(3) + +test('The Volume of a cone with base radius equal to 3 and height equal to 5', () => { + expect(parseFloat(sphere.volume().toFixed(2))).toEqual(113.1) +}) + +test('The Surface Area of a cone with base radius equal to 3 and height equal to 5', () => { + expect(parseFloat(sphere.surfaceArea().toFixed(2))).toEqual(113.1) +}) diff --git a/Geometry/Test/SphereVolume.test.js b/Geometry/Test/SphereVolume.test.js deleted file mode 100644 index 4c5ff9a338..0000000000 --- a/Geometry/Test/SphereVolume.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import { sphereVolume } from '../SphereVolume' - -describe('SphereVolume', () => { - it('should return the sphere volume given the radius', () => { - const res = sphereVolume(3) - expect(res).toEqual(113.1) - }) -}) From e823470ed2c5a3def190d2b30a512a4d0832b337 Mon Sep 17 00:00:00 2001 From: lcvieira2001 Date: Sun, 30 Oct 2022 12:19:28 -0300 Subject: [PATCH 3/3] Added PR Suggestions --- Geometry/Sphere.js | 2 +- Geometry/Test/Sphere.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Geometry/Sphere.js b/Geometry/Sphere.js index f3110928c2..82f539b917 100644 --- a/Geometry/Sphere.js +++ b/Geometry/Sphere.js @@ -1,8 +1,8 @@ /** * This class represents a sphere and can calculate its volume and surface area - * https://en.wikipedia.org/wiki/Sphere * @constructor * @param {number} radius - The radius of the sphere + * @see https://en.wikipedia.org/wiki/Sphere */ export default class Sphere { constructor (radius) { diff --git a/Geometry/Test/Sphere.test.js b/Geometry/Test/Sphere.test.js index c7db827819..18f8333a7c 100644 --- a/Geometry/Test/Sphere.test.js +++ b/Geometry/Test/Sphere.test.js @@ -2,10 +2,10 @@ import Sphere from '../Sphere' const sphere = new Sphere(3) -test('The Volume of a cone with base radius equal to 3 and height equal to 5', () => { +test('The Volume of a sphere with base radius equal to 3 and height equal to 5', () => { expect(parseFloat(sphere.volume().toFixed(2))).toEqual(113.1) }) -test('The Surface Area of a cone with base radius equal to 3 and height equal to 5', () => { +test('The Surface Area of a sphere with base radius equal to 3 and height equal to 5', () => { expect(parseFloat(sphere.surfaceArea().toFixed(2))).toEqual(113.1) }) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy