Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print total points #2

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions src/Printer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bold, underline, black, blue, bgGreen, green, yellow, red } from 'chalk';
import { tick, cross } from 'figures';
import { bgGreen, black, blue, bold, green, red, underline, yellow } from 'chalk';
import { cross, tick } from 'figures';
import { TestRun } from '@skills17/test-result';

export default class Printer {
Expand Down Expand Up @@ -36,17 +36,9 @@ export default class Printer {
const maxPoints = group.getMaxPoints();
const groupName = bold(underline(group.getDisplayName()));
const pointsText = `${points}/${maxPoints} point${maxPoints !== 1 ? 's' : ''}`;
let pointsColor = green;
const pointsColor = this.getPointsColor(points, maxPoints);
let manualCheck = '';

if (points < maxPoints) {
if (points > 0) {
pointsColor = yellow;
} else {
pointsColor = red;
}
}

if (group.requiresManualCheck()) {
manualCheck = bold(yellow(' [manual check required]'));
}
Expand Down Expand Up @@ -80,6 +72,9 @@ export default class Printer {

// print footer
if (printFooter) {
if (printPoints) {
this.printTotal(printer);
}
printer(
`\n${blue('Info:')}`,
'The detailed test and error information is visible above the result summary.',
Expand All @@ -90,6 +85,35 @@ export default class Printer {
printer();
}

private getPointsColor(points: number, maxPoints: number) {
if (points > 0) {
return points === maxPoints ? green : yellow;
}
return red;
}

private printTotal(printer: (...data: string[]) => void) {
const totalPoints = this.run
.getGroups()
.reduce((groupPoints, group) => groupPoints + group.getPoints(), 0);
const totalMaxPoints = this.run
.getGroups()
.reduce((groupPoints, group) => groupPoints + group.getMaxPoints(), 0);

const totalPointsRounded = Math.round(totalPoints * 100) / 100;
const totalMaxPointsRounded = Math.round(totalMaxPoints * 100) / 100;

const totalPointsColor = this.getPointsColor(totalPoints, totalMaxPoints);

printer(
`\nTotal: ${totalPointsColor(
`${totalPointsRounded}/${totalMaxPointsRounded} point${
totalMaxPointsRounded !== 1 ? 's' : ''
}`,
)}`,
);
}

private printWarnings(printer: (...data: string[]) => void): void {
// search for groups without tests
const emptyGroups = this.run
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/display-name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Summary:
Last group: 1/1 point
✔ Foo

Total: 3/3 points

Info: The detailed test and error information is visible above the result summary.
`;

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/empty-groups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Summary:
C.+: 1/1 point
✔ Foo

Total: 2/2 points

Info: The detailed test and error information is visible above the result summary.
`;

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/extra-tests-fail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Summary:
? Foo please check manually for static return values and/or logical errors
✔ Bar

Total: 8/9 points

Info: The detailed test and error information is visible above the result summary.
`;

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/extra-tests-missing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Summary:
✔ Foo
✖ Bar

Total: 7/11 points

Info: The detailed test and error information is visible above the result summary.

WARNING: The following tests do NOT have extra tests and so can NOT be checked for possible cheating:
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/extra-tests-strategy-deduct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Summary:
✔ Foo
✔ Bar

Total: 6.5/12.5 points

Info: The detailed test and error information is visible above the result summary.
`;

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/extra-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Summary:
✖ Foo
✖ Bar

Total: 5/9 points

Info: The detailed test and error information is visible above the result summary.
`;

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/main-tests-missing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Summary:
✔ Foo
✖ Bar

Total: 5/8 points

Info: The detailed test and error information is visible above the result summary.

WARNING: The following extra tests do not belong to a main test and were ignored:
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/no-header.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { mockConsoleToString } from '../helpers';
const expectedOutput = ` A.+: 1/1 point
✔ Foo

Total: 1/1 point

Info: The detailed test and error information is visible above the result summary.
`;

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/required-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Summary:
✔ Foo
✔ Required

Total: 2/7 points

Info: The detailed test and error information is visible above the result summary.
`;

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/small-points.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Summary:
✔ 19
✔ 20

Total: 1.9/2 points

Info: The detailed test and error information is visible above the result summary.
`;

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/strategy-deduct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Summary:
✔ Foo
✔ Bar

Total: 6.5/12.5 points

Info: The detailed test and error information is visible above the result summary.
`;

Expand Down
2 changes: 2 additions & 0 deletions tests/integration/ungrouped-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Summary:
A.+: 1/1 point
✔ Foo

Total: 1/1 point

Info: The detailed test and error information is visible above the result summary.

WARNING: The following tests do not belong to a group and were ignored:
Expand Down
Loading