Skip to content

Commit

Permalink
Merge pull request #481 from sir-gon/develop
Browse files Browse the repository at this point in the history
[BUGFIX] sonarcloud quality gate issues fixed
  • Loading branch information
sir-gon authored Sep 22, 2024
2 parents 4313e5b + 1f1db88 commit 2bac8c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
// Start Given code

export class Player {
name = '';

score = 0;

toString(): string {
// Given code
this.name.toString();
return '';
constructor(name: string, score: number) {
this.name = name;
this.score = score;
}

comparator(bPlayer: this): number {
// Given code
return 0 * this.score * bPlayer.score;
toString(): string {
return `${this.name} ${this.score}`;
}
}

// End Given code

export default { Player };
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ import TEST_CASES from './ctci_comparator_sorting.testcases.json';

describe('comparatorSorting', () => {
it('test_player', () => {
expect.assertions(2);
expect.assertions(1);

const aPlayer = new Player();
const _NAME_ = 'name';
const _SCORE_ = 0;

const aPlayer = new Player(_NAME_, _SCORE_);
const aPlayerAsString = aPlayer.toString();
const aExpected = '';
const aExpected = 'name 0';

expect(aExpected).toStrictEqual(aPlayerAsString);

const bPlayer = new Player();
const comparatorAnswerExpected = 0;

expect(aPlayer.comparator(bPlayer)).toStrictEqual(comparatorAnswerExpected);
});

it('test_comparator_sorting', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ export class SortablePlayer extends Player {
score = 0;

constructor(name: string, score: number) {
super();
super(name, score);

this.name = name;
this.score = score;
}

toString(): string {
return `${this.name} ${this.score}`;
}

comparator(bPlayer: this): number {
if (this.score > bPlayer.score) {
return -1;
Expand Down

0 comments on commit 2bac8c2

Please sign in to comment.