Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temperature changes #1

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a333d05
Javascript module initialization
alcb1310 Jan 8, 2025
8cc733c
feat: celcius to farenheit conversion
alcb1310 Jan 8, 2025
3817529
feat: farenheit to celcius conversion
alcb1310 Jan 8, 2025
55c1271
feat: improved jsdoc documentation of the functions
alcb1310 Jan 8, 2025
0602f1f
feat: setup node to use ES6 import
alcb1310 Jan 8, 2025
338fd78
refactor: move the convert to farenheit function to its own file
alcb1310 Jan 8, 2025
086a3ec
refactor: move the convert to celcius function to its own file
alcb1310 Jan 8, 2025
b50f193
refactor: use common js files
alcb1310 Jan 8, 2025
09439b3
feat: added jest to execute tests
alcb1310 Jan 8, 2025
e9e24d9
chore: added @types/jest to get code completion
alcb1310 Jan 8, 2025
408caf0
test: converting to celsius testing
alcb1310 Jan 8, 2025
c5da23d
test: convreting to farenheit testing
alcb1310 Jan 8, 2025
6de7fe1
chore: migrate from require to import
alcb1310 Jan 9, 2025
a47dc14
feat: use constants for celcius conversions
alcb1310 Jan 9, 2025
620ddde
refactor: move the celcius and farenheit functions to its own directory
alcb1310 Jan 10, 2025
5a0ab90
feat: use constats for farenheit conversions
alcb1310 Jan 10, 2025
cae48f3
fix: farenheit test use toBeClose method for comparing decimal numbers
alcb1310 Jan 10, 2025
938d33d
refactor: move tests to temperature directory to mimmic the src direc…
alcb1310 Jan 10, 2025
8b7abbe
feat: convert from meters to feet
alcb1310 Jan 10, 2025
4d4e6e8
test: meters to feet conversion
alcb1310 Jan 10, 2025
c0c888a
feat: convert from feet to meters
alcb1310 Jan 10, 2025
b25c8a7
test: meters to feet conversion
alcb1310 Jan 10, 2025
97cb75c
feat: move the convert to meters to its own file
alcb1310 Jan 11, 2025
77b94ab
fix: update temperature tests dependencies
alcb1310 Jan 12, 2025
07a4c1a
chore: add pr github actions
alcb1310 Jan 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
pull_request:

jobs:
unit-test:
name: Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup pnpm
uses: pnpm/action-setup@v3 # docs https://pnpm.io/continuous-integration#github-actions
with:
version: 9
# Further steps for your build/test process
- name: Install dependencies
run: pnpm install
- name: Run tests
run: pnpm test
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "temperature",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"start": "node src/index.js"
},
"type": "module",
"keywords": [
"chingu",
"roundtables",
"git",
"advanced",
"temperature"
],
"author": "Andres Court",
"license": "GNU",
"devDependencies": {
"@jest/globals": "^29.7.0",
"jest": "^29.7.0"
}
}
2,450 changes: 2,450 additions & 0 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {number} conversion factor from farenheit to celcius */
export const CelciusFactor = 5;

/** @type {number} conversion factor from celcius to farenheit */
export const FarenheitFactor = 9 / 5;

/** @type {number} Offset between celcius and farenheit zero value */
export const TemperatureOffset = 32;

/** @type {number} Factor to convert from feet to meters */
export const DistanceFactor = 3.28084;
12 changes: 12 additions & 0 deletions src/distance/ConvertToMeters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { DistanceFactor } from "../constants";

/**
* Converts a distance expressed in feet to meters
*
* @type val {number} distance in feet
* @returns {number} the distance in meters
*/

export function ConvertToMeters(val) {
return val / DistanceFactor;
}
11 changes: 11 additions & 0 deletions src/distance/feet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DistanceFactor } from "../constants";

/**
* Converts a distance expressed in meters to feet
*
* @type val {number} distance in meters
* @returns {number} the distance in feet
*/
export function ConvertToFeet(val) {
return val * DistanceFactor;
}
11 changes: 11 additions & 0 deletions src/distance/meters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DistanceFactor } from "../constants";

/**
* Converts a distance expressed in feet to meters
*
* @type val {number} distance in feet
* @returns {number} the distance in meters
*/
export function ConvertToMeters(val) {
return val / DistanceFactor;
}
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ConvertToFarenheit from "./temperature/farenheit.js";
import ConverToCelcius from "./temperature/celcius.js";

const far = ConvertToFarenheit(21);
const cel = ConverToCelcius(69.8);

console.log(far);
console.log(cel);
22 changes: 22 additions & 0 deletions src/temperature/celcius.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CelciusFactor, TemperatureOffset } from "../constants.js";

/**
* Convert a temperature that is in Farenheit to Celcius
*
* Formula used
* celcius = (farenheit - 32) * 5/9
*
* @param {number} temp The temperature in farenheit
* @returns {number} The converted celcius value
*
* @author Andres Court
*/
function ConverToCelcius(temp) {
/** @type {number} */
var value = temp - TemperatureOffset;
value = value * CelciusFactor;

return value;
}

export default ConverToCelcius;
22 changes: 22 additions & 0 deletions src/temperature/farenheit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { FarenheitFactor, TemperatureOffset } from "../constants";

/**
* Convert a temperature that is in Celcius to farenheit
*
* Formula used
* farenheit = 32 + (9/5 * celcius)
*
* @param {number} temp The temperature in celcius
* @returns {number} The converted farenheit value
*
* @author Andres Court
*/
function ConvertToFarenheit(temp) {
/** @type {number} */
let value = temp * FarenheitFactor;
value = value + TemperatureOffset;

return value;
}

export default ConvertToFarenheit;
10 changes: 10 additions & 0 deletions tests/distance/feet.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, it, expect } from "@jest/globals";
import { ConvertToFeet } from "../../src/distance/feet";

describe("Convert to Feet", () => {
it("should convert 10 meters to equal 32.8084 feet", () => {
const res = ConvertToFeet(10);

expect(res).toBeCloseTo(32.8084);
});
});
10 changes: 10 additions & 0 deletions tests/distance/meter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, it, expect } from "@jest/globals";
import { ConvertToMeters } from "../../src/distance/meters";

describe("Convert to meters", () => {
it("should convert 32.8084 feet to equal 10 meters", () => {
const res = ConvertToMeters(32.808);

expect(res).toBeCloseTo(10);
});
});
16 changes: 16 additions & 0 deletions tests/temperature/celsius.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { it, describe, expect } from "@jest/globals";
import convertToCelcius from "../../src/temperature/celcius.js";

describe("Convert to Celcius", () => {
it("should convert 32°F to equal 0°C", () => {
const cel = convertToCelcius(32);

expect(cel).toBe(0);
});

it("should convert 69.8°F to 21°C", () => {
const cel = convertToCelcius(69.8);

expect(cel).toBe(21);
});
});
16 changes: 16 additions & 0 deletions tests/temperature/farenheit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { it, describe, expect } from "@jest/globals";
import convertToFarenheit from "../../src/temperature/farenheit.js";

describe("Convert to Celcius", () => {
it("should convert 0°C to equal 32°F", () => {
const far = convertToFarenheit(0);

expect(far).toBe(32);
});

it("should convert 21°C to 69.8°F", () => {
const far = convertToFarenheit(21);

expect(far).toBeCloseTo(69.8);
});
});
Loading