add more tests (#26)

* added more tests

* (fix) no cpu profile.
This commit is contained in:
2021-04-29 21:42:51 +02:00
committed by GitHub
parent 23418bbc60
commit 924fca5b90
14 changed files with 196 additions and 39 deletions

2
.gitignore vendored
View File

@ -12,4 +12,4 @@ Thumbs.db
!/data/*.js
!/data/*.json
/private
coverage

View File

@ -1,12 +1,24 @@
const {CalculateQuality} = require('@dsabot/CalculateQuality');
require('module-alias/register');
const { CalculateQuality } = require('@dsabot/CalculateQuality');
const TestValues = [
[1,1], [2,1], [3,1],
[4,2], [5,2], [6,2],
[7,3], [8,3], [9,3],
[10,4],[11,4],[12,4],
[13,5],[14,5],[15,5]
[1, 1],
[2, 1],
[3, 1],
[4, 2],
[5, 2],
[6, 2],
[7, 3],
[8, 3],
[9, 3],
[10, 4],
[11, 4],
[12, 4],
[13, 5],
[14, 5],
[15, 5],
];
test.each(TestValues)('Retrieving Quality for %s', (input, output) => {
expect(CalculateQuality(input)).toBe(output);
});
});

View File

@ -0,0 +1,6 @@
require('module-alias/register');
const { Capitalize } = require('@dsabot/Capitalize');
it('should capitalize the first letter.', () => {
expect(Capitalize('mother')).toBe('Mother');
});

View File

@ -0,0 +1,60 @@
require('module-alias/register');
const { CompareResults } = require('@dsabot/CompareResults');
it('should return an object', () => {
let Obj = {
Passed: 0,
CriticalHit: 0,
Fumbles: 0,
PointsUsed: [],
PointsRemaining: 0,
};
expect(CompareResults).toBeInstanceOf(Object);
expect(CompareResults()).toMatchObject(Obj);
});
it('should match No. of Fumbles', () => {
let Obj = {
Passed: 0,
CriticalHit: 0,
Fumbles: 2,
PointsUsed: [0, 0, 0],
PointsRemaining: 0,
};
expect(CompareResults([9, 20, 20])).toMatchObject(Obj);
});
it('should match No. of Passed', () => {
let Obj = {
Passed: 3,
CriticalHit: 0,
Fumbles: 0,
PointsUsed: [0, 0, 0],
PointsRemaining: 0,
};
expect(CompareResults([7, 7, 7])).toMatchObject(Obj);
});
it('should match No. of Critical Hits', () => {
let Obj = {
Passed: 3,
CriticalHit: 2,
Fumbles: 0,
PointsUsed: [0, 0, 0],
PointsRemaining: 0,
};
expect(CompareResults([8, 1, 1])).toMatchObject(Obj);
});
it('should decrease Points remaining', () => {
let Obj = {
Passed: 3,
CriticalHit: 0,
Fumbles: 0,
PointsUsed: [0, 0, 3],
PointsRemaining: 3,
};
expect(CompareResults([11, 9, 15], [12, 12, 12], 0, 6)).toMatchObject(Obj);
});

View File

@ -1,6 +1,4 @@
const {
CountOccurences
} = require('../../functions/CountOccurences');
const { CountOccurences } = require('../../functions/CountOccurences');
test('Counting Occurences', () => {
expect(CountOccurences([1, 2, 3, 4, 1], 1)).toBe(2);
});
expect(CountOccurences([1, 2, 3, 4, 1], 1)).toBe(2);
});

View File

@ -0,0 +1,9 @@
require('module-alias/register');
const { CreateResultTable, f } = require('@dsabot/CreateResultTable');
it('turn any number into a string', () => {
expect(f(2)).toBe('+2');
expect(f(0)).toBe('0');
expect(f(-1)).toBe('-1');
});

View File

@ -0,0 +1,19 @@
require('module-alias/register');
const { Random } = require('@dsabot/Random');
it('should return with no min or max value', () => {
expect(Random.int()).toBeUndefined();
});
it('call for use should return true', () => {
expect(Random.use(null)).toBeTruthy();
});
it('should return between 1 and 2', () => {
expect(Random.int(1, 2)).toBeGreaterThanOrEqual(1);
});
it('should return between 1 and 2', () => {
expect(Random.int(1, 2)).toBeLessThanOrEqual(2);
});
it('should return exactly 1', () => {
expect(Random.int(1, 1)).toBe(1);
});

View File

@ -1,8 +1,8 @@
const { roll } = require('@dsabot/Roll');
describe('rolling dice', () => {
const expected = [1, 2, 3, 4, 5, 6];
test.each(expected)('contains only numbers from 1 to 6', (value) => {
expect(roll(200, 6).dice).toContain(value);
});
});
const expected = [1, 2, 3, 4, 5, 6];
test.each(expected)('contains only numbers from 1 to 6', value => {
expect(roll(200, 6).dice).toContain(value);
});
});

View File

@ -0,0 +1,23 @@
require('module-alias/register');
const { getAttributeLevels } = require('@dsabot/getAttributeLevels');
const Character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'klugheit', level: 11 },
{ id: 'intuition', level: 12 },
{ id: 'charisma', level: 13 },
{ id: 'fingerfertigkeit', level: 14 },
{ id: 'gewandtheit', level: 15 },
{ id: 'konstitution', level: 16 },
{ id: 'koerperkraft', level: 17 },
],
};
it('should return an array', () => {
expect(getAttributeLevels(['MU', 'IN', 'KO'], Character)).toBeInstanceOf(Array);
});
it('should have 3 items in it.', () => {
expect(getAttributeLevels(['MU', 'IN', 'KO'], Character)).toHaveLength(3);
});

View File

@ -1,13 +1,14 @@
const Random = {int, use};
const Random = { int, use };
function int (min, max) {
if (!min || !max) { return; }
//return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min))) + min;
return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min) + 1)) + min;
function int(min, max) {
if (!min || !max) {
return;
}
return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min) + 1)) + min;
}
function use (str) {
function use(str) {
return true;
}
module.exports = { Random };
module.exports = { Random };

View File

@ -1,14 +1,14 @@
const globals = require('../globals');
const getAttributeLevels = (Attributes = [], Character = {}) => {
let AttributeId;
let AttributeLevel;
let AttributeList = [];
for (let Attribute of Attributes) {
AttributeId = globals.Werte.find((attribute) => attribute.kuerzel === Attribute).id;
AttributeLevel = Character.attributes.find((att) => att.id === AttributeId).level;
AttributeList.push({ Name: Attribute, Level: AttributeLevel });
}
return AttributeList;
let AttributeId;
let AttributeLevel;
let AttributeList = [];
for (let Attribute of Attributes) {
AttributeId = globals.Werte.find(att => att.kuerzel === Attribute).id;
AttributeLevel = Character.attributes.find(att => att.id === AttributeId).level;
AttributeList.push({ Name: Attribute, Level: AttributeLevel });
}
return AttributeList;
};
module.exports = { getAttributeLevels};
module.exports = { getAttributeLevels };

View File

@ -5,6 +5,6 @@ module.exports = {
'@Commands/(.*)': '<rootDir>/commands/$1',
'@Root/(.*)': '<rootDir>/$1',
'@data/(.*)': '<rootDir>/data/$i',
'@lib/(.*)': '<rootDir>/lib/$i',
'@Lib/(.*)': '<rootDir>/lib/$i',
},
};

30
package-lock.json generated
View File

@ -1,11 +1,11 @@
{
"name": "dsabot",
"version": "1.1.0",
"version": "1.5.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "1.1.0",
"version": "1.5.0",
"license": "ISC",
"dependencies": {
"discord.js": "^12.5.3",
@ -16,6 +16,7 @@
"random": "^3.0.6"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"jest": "^26.6.3"
}
},
@ -673,6 +674,7 @@
"jest-resolve": "^26.6.2",
"jest-util": "^26.6.2",
"jest-worker": "^26.6.2",
"node-notifier": "^8.0.0",
"slash": "^3.0.0",
"source-map": "^0.6.0",
"string-length": "^4.0.1",
@ -865,6 +867,16 @@
"@types/istanbul-lib-report": "*"
}
},
"node_modules/@types/jest": {
"version": "26.0.23",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.23.tgz",
"integrity": "sha512-ZHLmWMJ9jJ9PTiT58juykZpL7KjwJywFN3Rr2pTSkyQfydf/rk22yS7W8p5DaVUMQ2BQC7oYiU3FjbTM/mYrOA==",
"dev": true,
"dependencies": {
"jest-diff": "^26.0.0",
"pretty-format": "^26.0.0"
}
},
"node_modules/@types/node": {
"version": "14.14.25",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.25.tgz",
@ -1889,7 +1901,8 @@
"esprima": "^4.0.1",
"estraverse": "^4.2.0",
"esutils": "^2.0.2",
"optionator": "^0.8.1"
"optionator": "^0.8.1",
"source-map": "~0.6.1"
},
"bin": {
"escodegen": "bin/escodegen.js",
@ -3137,6 +3150,7 @@
"@types/node": "*",
"anymatch": "^3.0.3",
"fb-watchman": "^2.0.0",
"fsevents": "^2.1.2",
"graceful-fs": "^4.2.4",
"jest-regex-util": "^26.0.0",
"jest-serializer": "^26.6.2",
@ -6996,6 +7010,16 @@
"@types/istanbul-lib-report": "*"
}
},
"@types/jest": {
"version": "26.0.23",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.23.tgz",
"integrity": "sha512-ZHLmWMJ9jJ9PTiT58juykZpL7KjwJywFN3Rr2pTSkyQfydf/rk22yS7W8p5DaVUMQ2BQC7oYiU3FjbTM/mYrOA==",
"dev": true,
"requires": {
"jest-diff": "^26.0.0",
"pretty-format": "^26.0.0"
}
},
"@types/node": {
"version": "14.14.25",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.25.tgz",

View File

@ -25,6 +25,11 @@
"random": "^3.0.6"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"jest": "^26.6.3"
},
"jest": {
"collectCoverage": true,
"collectCoverageFrom": ["**/*.{js,jsx}", "!**/node_modules/**", "!**/vendor/**"]
}
}