// ĠCopyright Ġ 2 0 0 0 - 2 0 2 0 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġcom . intellij . internal . statistics Ċ Ċ import Ġcom . intellij . internal . statistic . beans . Usage Descriptor Ċ import Ġcom . intellij . internal . statistic . event Log . Event Log Configuration Ċ import Ġcom . intellij . internal . statistic . utils . Statistics Util . getNext Power Of Two Ċ import Ġcom . intellij . internal . statistic . utils . getCount ing Step Name Ċ import Ġcom . intellij . internal . statistic . utils . getCount ing Usage Ċ import Ġorg . junit . Test Ċ import Ġkotlin . test . assertEquals Ċ Ċ class ĠStatistics Util Test Ġ{ ĊĠ Ġ@ Test ĊĠ Ġfun Ġtest _ count ing _ usage () Ġ{ ĊĠĠĠ Ġval Ġsteps Ġ= ĠlistOf ( 0 , Ġ 1 , Ġ 2 , Ġ 1 0 , Ġ 1 0 0 0 , Ġ 1 0 Ġ* Ġ 1 0 0 0 , Ġ 1 0 0 0 Ġ* Ġ 1 0 0 0 ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 0 ", Ġ 0 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 1 ", Ġ 1 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 2 +", Ġ 2 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 2 +", Ġ 3 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 2 +", Ġ 9 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 1 0 +", Ġ 1 0 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 1 0 +", Ġ 5 0 0 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 1 K +", Ġ 1 0 0 0 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 1 0 K +", Ġ 2 0 0 Ġ* Ġ 1 0 0 0 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 1 0 K +", Ġ 9 9 9 9 9 9 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 1 M +", Ġ 1 0 0 0 Ġ* Ġ 1 0 0 0 , Ġsteps ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 1 M +", Ġ 2 0 0 0 Ġ* Ġ 1 0 0 0 , Ġsteps ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest _ infinite _ count ing _ usage () Ġ{ ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count .< 0 ", Ġ- 1 0 0 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count .< 0 ", Ġ- 1 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 0 ", Ġ 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 ", Ġ 1 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 2 ", Ġ 2 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 3 +", Ġ 3 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 3 +", Ġ 4 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 5 +", Ġ 5 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 5 +", Ġ 6 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 5 +", Ġ 7 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 5 +", Ġ 9 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 0 +", Ġ 1 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 0 +", Ġ 1 4 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 5 +", Ġ 1 5 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 5 +", Ġ 2 9 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 3 0 +", Ġ 3 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 3 0 +", Ġ 4 9 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 5 0 +", Ġ 5 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 5 0 +", Ġ 9 9 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 0 0 +", Ġ 1 0 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 0 0 +", Ġ 3 4 1 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 K +", Ġ 1 0 0 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 0 0 K +", Ġ 2 0 0 Ġ* Ġ 1 0 0 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 5 0 0 K +", Ġ 9 9 9 9 9 9 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 M +", Ġ 1 0 0 0 Ġ* Ġ 1 0 0 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 M +", Ġ 2 0 0 0 Ġ* Ġ 1 0 0 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 5 M +", Ġ 6 0 0 0 Ġ* Ġ 1 0 0 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . 1 0 0 M +", Ġ 2 0 0 0 Ġ* Ġ 1 0 0 0 Ġ* Ġ 1 0 0 ) ĊĠĠĠ Ġassert Infinite Count ing Usage (" test . value . count . MAN Y ", Ġ 2 0 0 0 Ġ* Ġ 1 0 0 0 Ġ* Ġ 1 0 0 0 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġcounting Ġusage Ġon Ġempty Ġlist `() Ġ{ ĊĠĠĠ Ġval Ġempty Steps Ġ= ĠlistOf < Int >() ĊĠĠĠ Ġassert Count ing Usage (" test . value . count . 1 ", Ġ 1 , Ġempty Steps ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġcounting Ġusage Ġif Ġvalue Ġis Ġless Ġthan Ġthe Ġfirst Ġstep `() Ġ{ ĊĠĠĠ Ġval Ġsteps Ġ= ĠlistOf ( 1 , Ġ 5 , Ġ 1 0 ) ĊĠĠĠ Ġassert Count ing Usage (" test . value . count .< 1 ", Ġ 0 , Ġsteps ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġnext Ġpower Ġof Ġtwo `() Ġ{ ĊĠĠĠ Ġtest Power Of Two ( 0 , Ġ 1 ) ĊĠĠĠ Ġtest Power Of Two (- 5 , Ġ 1 ) ĊĠĠĠ Ġtest Power Of Two ( 1 , Ġ 1 ) ĊĠĠĠ Ġtest Power Of Two ( 2 , Ġ 2 ) ĊĠĠĠ Ġtest Power Of Two ( 3 , Ġ 4 ) ĊĠĠĠ Ġtest Power Of Two ( 5 , Ġ 8 ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġtest Power Of Two ( value : ĠInt , Ġexpected : ĠInt ) Ġ{ ĊĠĠĠ ĠassertEquals ( expected , ĠgetNext Power Of Two ( value ), Ġ" Incorrect Ġkey Ġfor Ġvalue Ġ`$ value ` ") ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġhash Ġsensitive Ġdata `() Ġ{ ĊĠĠĠ Ġval Ġsalt Ġ= Ġbyte ArrayOf ( 4 5 , Ġ 1 0 5 , Ġ 1 9 , Ġ- 8 0 , Ġ 1 0 9 , Ġ 3 8 , Ġ 2 4 , Ġ- 2 3 , Ġ 2 7 , Ġ- 1 0 2 , Ġ- 1 2 3 , Ġ 9 2 , Ġ 6 0 , Ġ- 6 3 , Ġ- 8 3 , Ġ- 6 7 , Ġ- 6 6 , Ġ- 1 7 , Ġ- 2 6 , Ġ 4 4 , Ġ 1 2 3 , Ġ 2 8 , Ġ 4 0 , Ġ- 7 4 , Ġ 7 7 , Ġ- 1 0 5 , Ġ 1 0 5 , Ġ- 4 1 , Ġ 3 6 , Ġ- 5 5 , Ġ- 2 1 , Ġ 5 ) ĊĠĠĠ Ġdo Test Hash ing ( salt , Ġ" test - project - name ", Ġ" dfa 4 8 8 a 6 8 d 1 9 d 9 0 9 af 4 1 6 ea 0 2 c 8 0 1 3 e 3 1 4 5 6 2 8 0 3 d 4 2 1 ae 7 4 7 d 7 fec 0 6 dd 0 8 0 6 0 9 ") ĊĠĠĠ Ġdo Test Hash ing ( salt , Ġ" Some Framework ", Ġ" 8 9 4 bcf b 4 eb 5 2 e 8 0 2 ce 7 5 0 1 1 2 ad 3 ed 6 d 1 6 f 0 4 9 c 6 3 f 3 8 5 f 5 a 0 d 6 c 6 ab 5 d 6 3 e 5 4 c 4 e ") ĊĠĠĠ Ġdo Test Hash ing ( salt , Ġ" project ", Ġ" 4 d 8 5 bff 7 bbe fd 0 d 5 6 9 5 4 5 0 8 7 4 de 9 b 3 8 fb 1 f 1 0 bac add 2 3 ab dd 4 ea 5 1 1 2 4 8 aab 7 f 0 ") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġdo Test Hash ing ( salt : ĠByteArray , Ġdata : ĠString , Ġexpected : ĠString ) Ġ{ ĊĠĠĠ Ġval Ġactual Ġ= ĠEvent Log Configuration . hash Sha 2 5 6 ( salt , Ġdata ) ĊĠĠĠ ĠassertEquals ( expected , Ġactual , Ġ" Hash ing Ġalgorithm Ġwas Ġchanged Ġfor Ġ'$ data '") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Count ing Usage ( expected Key : ĠString , Ġactual Value : ĠInt , Ġsteps : ĠList < Int >) Ġ{ ĊĠĠĠ Ġassert Usage ( expected Key , Ġ 1 , Ġget Count ing Usage (" test . value . count ", Ġactual Value , Ġsteps ), Ġ" Incorrect Ġkey Ġfor Ġvalue Ġ'$ actual Value '") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Infinite Count ing Usage ( expected Key : ĠString , Ġactual Value : ĠInt ) Ġ{ ĊĠĠĠ Ġassert Usage ( expected Key , Ġ 1 , Ġget Count ing Usage (" test . value . count ", Ġactual Value ), Ġ" Incorrect Ġkey Ġfor Ġvalue Ġ'$ actual Value '") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Usage ( key : ĠString , Ġvalue : ĠInt , Ġactual Usage : ĠUsage Descriptor , Ġmessage : ĠString ? Ġ= Ġnull ) Ġ{ ĊĠĠĠ ĠassertEquals ( key , Ġactual Usage . key , Ġmessage ) ĊĠĠĠ ĠassertEquals ( value , Ġactual Usage . value , Ġmessage ) ĊĠ Ġ} Ċ } Ċ Ċ private Ġfun Ġget Count ing Usage ( key : ĠString , Ġvalue : ĠInt , Ġsteps : ĠList < Int >) Ġ: ĠUsage Descriptor Ġ{ ĊĠ Ġreturn ĠUsage Descriptor ("$ key ." Ġ+ Ġget Count ing Step Name ( value , Ġsteps ), Ġ 1 ) Ċ }