This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
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.
#22 Update path mapping in jest unit tests
- Add initial test for black color factory - Update color.test.ts with better syntax - Configure module mapping for jest - Add new script to package.json - Add common to TS module path mapping - Update imports in sketch.ts
- Loading branch information
Showing
6 changed files
with
95 additions
and
69 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
62 changes: 62 additions & 0 deletions
62
tests/common/color/factory/rgb/black-color-factory.test.ts
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,62 @@ | ||
/* | ||
* Copyright (C) 2023 Brittni Watkins. | ||
* | ||
* This file is a part of brittni and the polar bear's Generative Art Project Template, | ||
* which is released under the GNU Affero General Public License, Version 3.0. | ||
* You may not use this file except in compliance with the license. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. See LICENSE or go to | ||
* https://www.gnu.org/licenses/agpl-3.0.en.html for full license details. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. | ||
*/ | ||
|
||
import {P5Lib, BlackColorFactory, Color} from "common"; | ||
|
||
function checkValueBetween(value: number, min: number, max: number) { | ||
expect(value).toBeGreaterThanOrEqual(min); | ||
expect(value).toBeLessThanOrEqual(max); | ||
} | ||
|
||
function generateConsecutiveArray(max: number): number[] { | ||
const array: number[] = []; | ||
|
||
for (let i: number = 1; i <= max; i++) { | ||
array.push(i); | ||
} | ||
|
||
return array; | ||
} | ||
|
||
function repeatTest(count: number, testName: string ,givenTest: () => void): void { | ||
const array: number[] = generateConsecutiveArray(count); | ||
test.each(array)(testName, givenTest); | ||
} | ||
|
||
describe('back color factory tests', (): void => { | ||
const p5: P5Lib = new P5Lib((): void => { return; }); | ||
|
||
test('get random black color', (): void => { | ||
const factory: BlackColorFactory = new BlackColorFactory(p5); | ||
const color:Color = factory.getRandomColor(); | ||
checkValueBetween(color.red, 0, 100); | ||
checkValueBetween(color.green, 0, 100); | ||
checkValueBetween(color.blue, 0, 100); | ||
expect(color.alpha).toBe(255); | ||
}); | ||
|
||
const testRandomBlackColor = (): void => { | ||
const factory: BlackColorFactory = new BlackColorFactory(p5); | ||
const color:Color = factory.getRandomColor(); | ||
checkValueBetween(color.red, 0, 100); | ||
checkValueBetween(color.green, 0, 100); | ||
checkValueBetween(color.blue, 0, 100); | ||
expect(color.alpha).toBe(255); | ||
} | ||
|
||
repeatTest(10, 'get random black color - test %i', testRandomBlackColor); | ||
}); |
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