-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: format quorum using compact format (#994)
- Loading branch information
Showing
4 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { formatQuorum } from './quorum'; | ||
|
||
describe('formatQuorum', () => { | ||
it('should format using 3 significant digits', () => { | ||
expect(formatQuorum(0.001)).toBe('0.1%'); | ||
expect(formatQuorum(0.1234)).toBe('12.3%'); | ||
expect(formatQuorum(0.555667)).toBe('55.5%'); | ||
expect(formatQuorum(4.446326)).toBe('444%'); | ||
expect(formatQuorum(999.90111)).toBe('99.9k%'); | ||
}); | ||
|
||
it('should not round up but truncate', () => { | ||
expect(formatQuorum(0.9999)).toBe('99.9%'); | ||
}); | ||
|
||
it('should format big numbers in compact format', () => { | ||
expect(formatQuorum(1000)).toBe('100k%'); | ||
expect(formatQuorum(1234)).toBe('123k%'); | ||
expect(formatQuorum(5556)).toBe('555k%'); | ||
expect(formatQuorum(44444)).toBe('4.44m%'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters