mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-21 04:26:14 -04:00
Pause when tab is hidden, using visibility change api
This commit is contained in:
parent
1a56b5f1d1
commit
33d74e8c84
68 changed files with 7290 additions and 6933 deletions
|
@ -1,49 +1,54 @@
|
|||
import {getMajorityValue, makeEmptyPerksMap, sample, sumOfKeys} from "./game_utils";
|
||||
import {Upgrade} from "./types";
|
||||
import {
|
||||
getMajorityValue,
|
||||
makeEmptyPerksMap,
|
||||
sample,
|
||||
sumOfKeys,
|
||||
} from "./game_utils";
|
||||
import { Upgrade } from "./types";
|
||||
|
||||
describe('getMajorityValue', ()=>{
|
||||
|
||||
it('returns the most common string',()=>{
|
||||
expect(getMajorityValue(['1','1','2','2','3','2','3','2','2','1'])).toStrictEqual('2')
|
||||
})
|
||||
it('returns the only string',()=>{
|
||||
expect(getMajorityValue(['1'])).toStrictEqual('1')
|
||||
})
|
||||
it('returns nothing for empty array',()=>{
|
||||
expect(getMajorityValue([])).toStrictEqual(undefined)
|
||||
})
|
||||
|
||||
})
|
||||
describe('sample', ()=>{
|
||||
|
||||
it('returns a random pick from the array',()=>{
|
||||
expect(['1','2','3'].includes(sample(['1','2','3']))).toBeTruthy()
|
||||
})
|
||||
it('returns the only item if there is just one',()=>{
|
||||
expect(sample(['1'])).toStrictEqual('1')
|
||||
})
|
||||
it('returns nothing for empty array',()=>{
|
||||
expect(sample([])).toStrictEqual(undefined)
|
||||
})
|
||||
|
||||
})
|
||||
describe('sumOfKeys', ()=>{
|
||||
it('returns the sum of the keys of an array',()=>{
|
||||
expect(sumOfKeys({a:1,b:2})).toEqual(3)
|
||||
})
|
||||
it('returns 0 for an empty object',()=>{
|
||||
expect(sumOfKeys({})).toEqual(0)
|
||||
})
|
||||
it('returns 0 for undefined',()=>{
|
||||
expect(sumOfKeys(undefined)).toEqual(0)
|
||||
})
|
||||
it('returns 0 for null',()=>{
|
||||
expect(sumOfKeys(null)).toEqual(0)
|
||||
})
|
||||
})
|
||||
describe('makeEmptyPerksMap', ()=>{
|
||||
it('returns an object',()=>{
|
||||
expect(makeEmptyPerksMap([{id:"ball_attract_ball"}])).toEqual({ball_attract_ball:0})
|
||||
expect(makeEmptyPerksMap([])).toEqual({})
|
||||
})
|
||||
})
|
||||
describe("getMajorityValue", () => {
|
||||
it("returns the most common string", () => {
|
||||
expect(
|
||||
getMajorityValue(["1", "1", "2", "2", "3", "2", "3", "2", "2", "1"]),
|
||||
).toStrictEqual("2");
|
||||
});
|
||||
it("returns the only string", () => {
|
||||
expect(getMajorityValue(["1"])).toStrictEqual("1");
|
||||
});
|
||||
it("returns nothing for empty array", () => {
|
||||
expect(getMajorityValue([])).toStrictEqual(undefined);
|
||||
});
|
||||
});
|
||||
describe("sample", () => {
|
||||
it("returns a random pick from the array", () => {
|
||||
expect(["1", "2", "3"].includes(sample(["1", "2", "3"]))).toBeTruthy();
|
||||
});
|
||||
it("returns the only item if there is just one", () => {
|
||||
expect(sample(["1"])).toStrictEqual("1");
|
||||
});
|
||||
it("returns nothing for empty array", () => {
|
||||
expect(sample([])).toStrictEqual(undefined);
|
||||
});
|
||||
});
|
||||
describe("sumOfKeys", () => {
|
||||
it("returns the sum of the keys of an array", () => {
|
||||
expect(sumOfKeys({ a: 1, b: 2 })).toEqual(3);
|
||||
});
|
||||
it("returns 0 for an empty object", () => {
|
||||
expect(sumOfKeys({})).toEqual(0);
|
||||
});
|
||||
it("returns 0 for undefined", () => {
|
||||
expect(sumOfKeys(undefined)).toEqual(0);
|
||||
});
|
||||
it("returns 0 for null", () => {
|
||||
expect(sumOfKeys(null)).toEqual(0);
|
||||
});
|
||||
});
|
||||
describe("makeEmptyPerksMap", () => {
|
||||
it("returns an object", () => {
|
||||
expect(makeEmptyPerksMap([{ id: "ball_attract_ball" }])).toEqual({
|
||||
ball_attract_ball: 0,
|
||||
});
|
||||
expect(makeEmptyPerksMap([])).toEqual({});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue