@@ -6,26 +6,25 @@ import { IAssetMetadata, ITag } from "../../models/applicationState";
66 * @param params Params containing substitution values
77 */
88export function splitTestAsset ( allAssets : IAssetMetadata [ ] , tags : ITag [ ] , testSplitRatio : number ) : string [ ] {
9- const testAssets : string [ ] = [ ] ;
9+ if ( testSplitRatio <= 0 || testSplitRatio > 1 ) { return [ ] ; }
1010
11- if ( testSplitRatio > 0 && testSplitRatio <= 1 ) {
12- const tagsAssetDict : { [ index : string ] : { assetList : Set < string > } } = { } ;
13- tags . forEach ( ( tag ) => tagsAssetDict [ tag . name ] = { assetList : new Set ( ) } ) ;
14- allAssets . forEach ( ( assetMetadata ) => {
15- assetMetadata . regions . forEach ( ( region ) => {
16- region . tags . forEach ( ( tagName ) => {
17- if ( tagsAssetDict [ tagName ] ) {
18- tagsAssetDict [ tagName ] . assetList . add ( assetMetadata . asset . name ) ;
19- }
20- } ) ;
11+ const testAssets : string [ ] = [ ] ;
12+ const tagsAssetDict : { [ index : string ] : { assetList : Set < string > } } = { } ;
13+ tags . forEach ( ( tag ) => tagsAssetDict [ tag . name ] = { assetList : new Set ( ) } ) ;
14+ allAssets . forEach ( ( assetMetadata ) => {
15+ assetMetadata . regions . forEach ( ( region ) => {
16+ region . tags . forEach ( ( tagName ) => {
17+ if ( tagsAssetDict [ tagName ] ) {
18+ tagsAssetDict [ tagName ] . assetList . add ( assetMetadata . asset . name ) ;
19+ }
2120 } ) ;
2221 } ) ;
22+ } ) ;
2323
24- for ( const tagKey of Object . keys ( tagsAssetDict ) ) {
25- const assetList = tagsAssetDict [ tagKey ] . assetList ;
26- const testCount = Math . ceil ( assetList . size * testSplitRatio ) ;
27- testAssets . push ( ...Array . from ( assetList ) . slice ( 0 , testCount ) ) ;
28- }
24+ for ( const tagKey of Object . keys ( tagsAssetDict ) ) {
25+ const assetList = tagsAssetDict [ tagKey ] . assetList ;
26+ const testCount = Math . ceil ( assetList . size * testSplitRatio ) ;
27+ testAssets . push ( ...Array . from ( assetList ) . slice ( 0 , testCount ) ) ;
2928 }
3029 return testAssets ;
3130}
0 commit comments