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
7fe79c2
commit 827e106
Showing
16 changed files
with
168 additions
and
46 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 |
---|---|---|
@@ -1,26 +1,12 @@ | ||
import { randomize } from '../../utils' | ||
import { BaseSequencer } from './BaseSequencer' | ||
|
||
export class RandomSequencer extends BaseSequencer { | ||
private random(seed: number) { | ||
const x = Math.sin(seed++) * 10000 | ||
return x - Math.floor(x) | ||
} | ||
|
||
public async sort(files: string[]) { | ||
const { sequence } = this.ctx.config | ||
|
||
let seed = sequence?.seed ?? Date.now() | ||
let length = files.length | ||
|
||
while (length) { | ||
const index = Math.floor(this.random(seed) * length--) | ||
|
||
const previous = files[length] | ||
files[length] = files[index] | ||
files[index] = previous | ||
++seed | ||
} | ||
const seed = sequence?.seed ?? Date.now() | ||
|
||
return files | ||
return randomize(files, seed) | ||
} | ||
} |
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,31 @@ | ||
import { afterAll, describe, expect, test } from 'vitest' | ||
|
||
// tests use seed of 101, so they have deterministic random order | ||
const numbers: number[] = [] | ||
|
||
describe.random('random tests', () => { | ||
describe('inside', () => { | ||
// random is not inhereted from parent | ||
|
||
test('inside 1', () => { | ||
numbers.push(1) | ||
}) | ||
test('inside 2', () => { | ||
numbers.push(2) | ||
}) | ||
}) | ||
|
||
test('test 1', () => { | ||
numbers.push(3) | ||
}) | ||
test('test 2', () => { | ||
numbers.push(4) | ||
}) | ||
test('test 3', () => { | ||
numbers.push(5) | ||
}) | ||
|
||
afterAll(() => { | ||
expect(numbers).toStrictEqual([4, 5, 3, 1, 2]) | ||
}) | ||
}) |
Oops, something went wrong.