@@ -9,7 +9,7 @@ public class RandomExtensionTests
99 [ Test ]
1010 public void RandomWorks ( )
1111 {
12- int [ ] numbers = new int [ ] { 1 , 2 , 3 , 4 , 5 } ;
12+ int [ ] numbers = new [ ] { 1 , 2 , 3 , 4 , 5 } ;
1313 Debug . Log ( numbers . Random ( ) ) ;
1414 Debug . Log ( numbers . Random ( ) ) ;
1515 }
@@ -30,14 +30,14 @@ public Item(string name, int percent)
3030 public void RandomPercent ( )
3131 {
3232 // Arrange
33- Item [ ] items = new Item [ ] {
33+ Item [ ] items = new [ ] {
3434 new Item ( "normal sword" , 80 ) ,
3535 new Item ( "epic sword" , 19 ) ,
3636 new Item ( "regendary sword" , 1 ) ,
3737 } ;
3838
3939 int gotchaCount = 1000 ;
40- Dictionary < string , int > hasItemCount = new Dictionary < string , int > ( )
40+ Dictionary < string , int > hasItemCount = new Dictionary < string , int >
4141 {
4242 { "normal" , 0 } , { "epic" , 0 } , { "regendary" , 0 }
4343 } ;
@@ -61,20 +61,19 @@ public void RandomPercent()
6161 for ( int i = 0 ; i < items . Length ; i ++ )
6262 {
6363 Item item = items [ i ] ;
64- float errorRate = 0.2f ;
64+ float errorRate = 0.5f ; // 랜덤에 걸리지 않기 위해 범위를 많이 넓힘
6565 int expectCount = ( int ) ( gotchaCount * ( item . percent / 100f ) ) ;
6666 int errorRange = ( int ) ( expectCount * errorRate ) ;
6767 KeyValuePair < string , int > itemCount = hasItemCount . First ( hasItem => item . name . StartsWith ( hasItem . Key ) ) ;
6868
69- // 대부분 통과하나, 랜덤 확률에 의해 가끔 실패함..
70- // Assert.GreaterOrEqual(itemCount.Value, expectCount - errorRange);
69+ Assert . GreaterOrEqual ( itemCount . Value , expectCount - errorRange ) ;
7170 }
7271 }
7372
7473 [ Test ]
7574 public void RandomFilter ( )
7675 {
77- int [ ] numbers = new int [ ] { 1 , 2 , 3 , 4 , 5 } ;
76+ int [ ] numbers = new [ ] { 1 , 2 , 3 , 4 , 5 } ;
7877 HashSet < int > set = new HashSet < int > ( ) ;
7978
8079 for ( int i = 0 ; i < numbers . Length ; i ++ )
0 commit comments