55 *
66 * Copyright Oxide Computer Company
77 */
8- import { afterAll , beforeAll , describe , expect , it } from 'vitest'
9-
10- import {
11- displayBigNum ,
12- nearest10 ,
13- percentage ,
14- round ,
15- splitDecimal ,
16- toEngNotation ,
17- } from './math'
8+ import { describe , expect , it } from 'vitest'
9+
10+ import { displayBigNum , nearest10 , percentage , round , splitDecimal } from './math'
1811import { GiB } from './units'
1912
2013function roundTest ( ) {
@@ -119,15 +112,6 @@ describe('with default locale', () => {
119112} )
120113
121114describe ( 'with de-DE locale' , ( ) => {
122- const originalLanguage = global . navigator . language
123-
124- beforeAll ( ( ) => {
125- Object . defineProperty ( global . navigator , 'language' , {
126- value : 'de-DE' ,
127- writable : true ,
128- } )
129- } )
130-
131115 it . each ( [
132116 [ 0.23 , [ '0' , ',23' ] ] ,
133117 [ 0.236 , [ '0' , ',24' ] ] ,
@@ -150,17 +134,14 @@ describe('with de-DE locale', () => {
150134 [ - 50.2 , [ '-50' , ',2' ] ] , // should correctly not round down to -51
151135 [ 1000.5 , [ '1.000' , ',5' ] ] , // test localeString grouping
152136 ] ) ( 'splitDecimal %d -> %s' , ( input , output ) => {
153- expect ( splitDecimal ( input ) ) . toEqual ( output )
137+ expect ( splitDecimal ( input , 'de-DE' ) ) . toEqual ( output )
154138 } )
155139
156- // rounding must work the same irrespective of locale
157- it ( 'round' , roundTest )
158-
159140 it . each ( [
160141 [ 0n , [ '0' , false ] ] ,
161142 [ 1n , [ '1' , false ] ] ,
162143 [ 155n , [ '155' , false ] ] ,
163- [ 999999n , [ '999, 999' , false ] ] ,
144+ [ 999999n , [ '999. 999' , false ] ] ,
164145 [ 1000000n , [ '1 Mio.' , true ] ] ,
165146 [ 1234567n , [ '1,2 Mio.' , true ] ] ,
166147 [ 9999999n , [ '10 Mio.' , true ] ] , // note non-breaking space
@@ -169,14 +150,7 @@ describe('with de-DE locale', () => {
169150 [ 1293859032098219 , [ '1,3e15' , true ] ] ,
170151 [ 23094304823948203952304920342n , [ '23,1e27' , true ] ] ,
171152 ] ) ( 'displayBigNum %d -> %s' , ( input , output ) => {
172- expect ( displayBigNum ( input ) ) . toEqual ( output )
173- } )
174-
175- afterAll ( ( ) => {
176- Object . defineProperty ( global . navigator , 'language' , {
177- value : originalLanguage ,
178- writable : true ,
179- } )
153+ expect ( displayBigNum ( input , 'de-DE' ) ) . toEqual ( output )
180154 } )
181155} )
182156
@@ -195,8 +169,8 @@ it.each([
195169 [ 'en-CA' ] ,
196170 [ 'en-IN' ] ,
197171 [ 'ko-KR' ] ,
198- ] ) ( 'toEngNotation dots %s' , ( locale ) => {
199- expect ( toEngNotation ( n , locale ) ) . toEqual ( '23.1e27' )
172+ ] ) ( 'displayBigNum dots %s' , ( locale ) => {
173+ expect ( displayBigNum ( n , locale ) ) . toEqual ( [ '23.1e27' , true ] )
200174} )
201175
202176it . each ( [
@@ -212,8 +186,8 @@ it.each([
212186 [ 'tr-TR' ] ,
213187 [ 'pt-PT' ] ,
214188 // ['ar-SA'], // saudi arabia, arabic script
215- ] ) ( 'toEngNotation commas %s' , ( locale ) => {
216- expect ( toEngNotation ( n , locale ) ) . toEqual ( '23,1e27' )
189+ ] ) ( 'displayBigNum commas %s' , ( locale ) => {
190+ expect ( displayBigNum ( n , locale ) ) . toEqual ( [ '23,1e27' , true ] )
217191} )
218192
219193it . each ( [
0 commit comments