generated from techmmunity/base-project-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
829c9b1
commit 66728bb
Showing
10 changed files
with
320 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { getGCD } from "../get-gcd"; | ||
|
||
/** | ||
* Gets the aspect ratio (like 16:9, 4:3) | ||
*/ | ||
export const getAspectRatio = (width: number, height: number) => { | ||
const divisor = getGCD(width, height); | ||
|
||
return `${width / divisor}:${height / divisor}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Gets the Greatest Common Divisor (GCD) | ||
* of 2 numbers | ||
*/ | ||
export const getGCD = (a: number, b: number): number => | ||
b ? getGCD(b, a % b) : a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* eslint-disable sonarjs/no-duplicate-string */ | ||
|
||
import { getAspectRatio } from "../lib/get-aspect-ratio"; | ||
|
||
describe("getAspectRatio Util", () => { | ||
describe("With width bigger than height", () => { | ||
it("should return the aspect ratio (5:4)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getAspectRatio(1280, 1024); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe("5:4"); | ||
}); | ||
|
||
it("should return the aspect ratio (6:5)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getAspectRatio(1152, 960); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe("6:5"); | ||
}); | ||
|
||
it("should return the aspect ratio (4:3)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getAspectRatio(1280, 960); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe("4:3"); | ||
}); | ||
|
||
it("should return the aspect ratio (16:9)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getAspectRatio(1920, 1080); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe("16:9"); | ||
}); | ||
}); | ||
|
||
describe("With height bigger than width", () => { | ||
it("should return the aspect ratio (4:5)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getAspectRatio(1024, 1280); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe("4:5"); | ||
}); | ||
|
||
it("should return the aspect ratio (5:6)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getAspectRatio(960, 1152); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe("5:6"); | ||
}); | ||
|
||
it("should return the aspect ratio (3:4)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getAspectRatio(960, 1280); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe("3:4"); | ||
}); | ||
|
||
it("should return the aspect ratio (9:16)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getAspectRatio(1080, 1920); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe("9:16"); | ||
}); | ||
}); | ||
|
||
describe("With width equal to height", () => { | ||
it("should return the aspect ratio (1:1 - 1024)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getAspectRatio(1024, 1024); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe("1:1"); | ||
}); | ||
|
||
it("should return the aspect ratio (1:1 - 960)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getAspectRatio(960, 960); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe("1:1"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { getGCD } from "../lib/get-gcd"; | ||
|
||
describe("getGCD Util", () => { | ||
describe("With a bigger than b", () => { | ||
it("should return the GCD (256)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getGCD(1280, 1024); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe(256); | ||
}); | ||
|
||
it("should return the GCD (192)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getGCD(1152, 960); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe(192); | ||
}); | ||
|
||
it("should return the GCD (320)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getGCD(1280, 960); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe(320); | ||
}); | ||
|
||
it("should return the GCD (120)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getGCD(1920, 1080); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe(120); | ||
}); | ||
}); | ||
|
||
describe("With b bigger than a", () => { | ||
it("should return the GCD (256)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getGCD(1024, 1280); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe(256); | ||
}); | ||
|
||
it("should return the GCD (192)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getGCD(960, 1152); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe(192); | ||
}); | ||
|
||
it("should return the GCD (320)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getGCD(960, 1280); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe(320); | ||
}); | ||
|
||
it("should return the GCD (120)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getGCD(1080, 1920); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe(120); | ||
}); | ||
}); | ||
|
||
describe("With a equal to a", () => { | ||
it("should return the GCD (1024)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getGCD(1024, 1024); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe(1024); | ||
}); | ||
|
||
it("should return the GCD (960)", () => { | ||
let result: any; | ||
|
||
try { | ||
result = getGCD(960, 960); | ||
} catch (err: any) { | ||
result = err; | ||
} | ||
|
||
expect(result).toBe(960); | ||
}); | ||
}); | ||
}); |