Skip to content

Commit

Permalink
✨ Hex's toString() returns constructor name
Browse files Browse the repository at this point in the history
Together with its `q` and `r` coordinates.
  • Loading branch information
flauwekeul committed Aug 9, 2022
1 parent fe29840 commit e3cafe0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/hex/hex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ describe('equals()', () => {
})

describe('toString()', () => {
test('returns the q and r coordinates', () => {
expect(new Hex([-2, 2]).toString()).toBe('-2,2')
test('returns the constructor name and q and r coordinates', () => {
expect(new Hex([-2, 2]).toString()).toBe('Hex(-2,2)')

class CustomHex extends Hex {}
expect(new CustomHex([4, 0]).toString()).toBe('CustomHex(4,0)')
})
})

Expand Down
2 changes: 1 addition & 1 deletion src/hex/hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class Hex
}

toString() {
return `${this.q},${this.r}`
return `${this.constructor.name}(${this.q},${this.r})`
}

translate(delta: PartialCubeCoordinates) {
Expand Down

0 comments on commit e3cafe0

Please sign in to comment.