-
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.
* starting gameState tests * copy shared to client before build * a couple more tests * fix exchange bug * more tests * more tests
- Loading branch information
1 parent
212d911
commit a4be3ed
Showing
12 changed files
with
405 additions
and
55 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Chance } from "chance" | ||
import { shuffle } from "./array" | ||
|
||
const chance = new Chance() | ||
|
||
describe('array', () => { | ||
it('should throw if input is not iterable', () => { | ||
expect(() => shuffle(null)).toThrow() | ||
}) | ||
|
||
it('should shuffle original array', () => { | ||
const original = Array.from({ length: 100 }, () => chance.natural()) | ||
const shuffled = shuffle(original) | ||
expect(shuffled).not.toEqual(original) | ||
expect(shuffled.length).toBe(original.length) | ||
shuffled.forEach((elementS) => { | ||
expect(original.find((elementO) => elementO === elementS)).not.toBeNull() | ||
}) | ||
}) | ||
}) |
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 @@ | ||
export const shuffle = <T>(array: T[]): T[] => { | ||
const unShuffled = [...array] | ||
const shuffled: T[] = [] | ||
|
||
while (unShuffled.length) { | ||
shuffled.push(unShuffled.splice(Math.floor(Math.random() * unShuffled.length), 1)[0]) | ||
} | ||
|
||
return shuffled | ||
} |
Oops, something went wrong.