Skip to content

Commit

Permalink
refactor(PathService): Clean up arePathsEmpty() (#1899)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima authored Aug 20, 2024
1 parent 75b4575 commit e28191d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/app/services/pathService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('PathService', () => {
service = TestBed.inject(PathService);
});
consolidatePaths();
arePathsEmpty();
});

function consolidatePaths() {
Expand All @@ -35,3 +36,12 @@ function consolidatePaths() {
});
});
}

function arePathsEmpty() {
describe('arePathsEmpty()', () => {
it('should return true iff all paths are empty', () => {
expect(service.arePathsEmpty([[], []])).toBeTrue();
expect(service.arePathsEmpty([['node1'], []])).toBeFalse();
});
});
}
13 changes: 2 additions & 11 deletions src/assets/wise5/services/pathService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@ export class PathService {
/**
* Check if all the paths are empty
* @param paths an array of paths. each path is an array of node ids
* @return whether all the paths are empty
* @return true iff all the paths are empty
*/
arePathsEmpty(paths: string[][]): boolean {
if (paths != null) {
for (let path of paths) {
if (path != null) {
if (path.length !== 0) {
return false;
}
}
}
}
return true;
return paths.every((path) => path.length === 0);
}

/**
Expand Down

0 comments on commit e28191d

Please sign in to comment.