-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
6 changed files
with
173 additions
and
111 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
File renamed without changes.
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,23 @@ | ||
const currObject = require('../Backend/src/kMeans.js'); | ||
|
||
describe('changeToClosest', () => { | ||
it('should update the matrix with the closest cluster values', () => { | ||
// Test input | ||
const matrix = [ | ||
[10, 20, 30], | ||
[40, 50, 60], | ||
[70, 80, 90] | ||
]; | ||
const K = 2; | ||
|
||
// Make a copy of the original matrix for comparison | ||
const originalMatrix = JSON.parse(JSON.stringify(matrix)); | ||
|
||
// Call the changeToClosest function | ||
currObject.changeToClosest(matrix, K); | ||
|
||
// Assertions | ||
expect(matrix).not.toEqual(originalMatrix); | ||
// Additional assertions based on the expected behavior of the changeToClosest function | ||
}); | ||
}); |
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,61 @@ | ||
const currObject = require('../Backend/src/kMeans.js'); | ||
|
||
|
||
describe('getRandomPixels', () => { | ||
it('should return an array of random pixels with the specified count', () => { | ||
// Test input | ||
const matrix = [ | ||
[100, 200, 300], | ||
[400, 500, 600], | ||
[700, 800, 900] | ||
]; | ||
const K = 5; | ||
|
||
// Call the getRandomPixels function | ||
const result = currObject.getRandomPixels(matrix, K); | ||
|
||
// Assertions | ||
expect(result).toHaveLength(K); | ||
result.forEach((pixel) => { | ||
expect(pixel).toHaveLength(2); | ||
expect(matrix.flat()).toContain(pixel[0]); | ||
expect(pixel[1]).toBe(1); | ||
}); | ||
}); | ||
|
||
it('should return an array of random pixels with the specified count', () => { | ||
// Test input | ||
const matrix = [ | ||
[10, 20, 30], | ||
[40, 50, 60], | ||
[70, 80, 90] | ||
]; | ||
const K = 3; | ||
|
||
// Call the getRandomPixels function | ||
const result = currObject.getRandomPixels(matrix, K); | ||
|
||
// Assertions | ||
expect(result).toHaveLength(K); | ||
result.forEach((pixel) => { | ||
expect(pixel).toHaveLength(2); | ||
expect(matrix.flat()).toContain(pixel[0]); | ||
expect(pixel[1]).toBe(1); | ||
}); | ||
}); | ||
|
||
it('should return an empty array when K is 0', () => { | ||
// Test input | ||
const matrix = [ | ||
[10, 20], | ||
[30, 40] | ||
]; | ||
const K = 0; | ||
|
||
// Call the getRandomPixels function | ||
const result = currObject.getRandomPixels(matrix, K); | ||
|
||
// Assertion | ||
expect(result).toHaveLength(0); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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