@@ -61,3 +61,70 @@ def a_c(self):
6161 self .assertLess (my_top_rand .a .size , 5 )
6262 print ("Size: %d" % my_top_rand .a .size )
6363
64+ def test_arr_sum (self ):
65+
66+ @vsc .randobj
67+ class ThreadGroupConstraintItem (object ):
68+ def __init__ (self , aThreadNum , aSharePercent ):
69+ self .mThreadNum = aThreadNum
70+ self .mSharePercent = aSharePercent
71+
72+ self .mSharePercentGoal = self .mSharePercent
73+ self .mSharePercentDelta = 10
74+ self .mSharePercentGoalMin = 0
75+ self .mSharePercentGoalMax = 0
76+ self ._genSharePrecent ()
77+ self .mSharePercentGoalMinConstr = vsc .rand_uint16_t (0 )
78+ self .mSharePercentGoalMaxConstr = vsc .rand_uint16_t (0 )
79+ self .mGroupSize = vsc .rand_uint16_t (0 )
80+ self .GroupList = vsc .randsz_list_t (vsc .rand_uint16_t ())
81+ self .GroupListScore = vsc .randsz_list_t (vsc .rand_uint16_t ())
82+
83+ @vsc .constraint
84+ def basic_c (self ):
85+ self .mGroupSize < self .mThreadNum
86+ self .mGroupSize > 0
87+ self .GroupList .size == self .mGroupSize
88+ self .GroupListScore .size == self .mGroupSize
89+ # self.GroupListSum == self.GroupList.sum
90+ # self.GroupList.sum == self.GroupListSum
91+ # self.GroupListSum == self.mThreadNum
92+ with vsc .foreach (self .GroupList , idx = True , it = False ) as idx :
93+ self .GroupList [idx ]<= self .mThreadNum
94+ self .GroupList [idx ]> 0
95+ with vsc .foreach (self .GroupList , idx = True , it = False ) as idx :
96+ with vsc .if_then (self .GroupList [idx ] > 1 ):
97+ self .GroupListScore [idx ] == 1
98+ with vsc .else_then ():
99+ self .GroupListScore [idx ] == 0
100+ self .GroupList .sum == self .mThreadNum
101+ # self.mSharePercentGoalMinConstr == self.mSharePercentGoalMin
102+ # self.mSharePercentGoalMaxConstr == self.mSharePercentGoalMax
103+ # self.GroupListScore.sum/self.mGroupSize < int(self.mSharePercentGoalMax/100)
104+ # self.GroupListScore.sum/self.mGroupSize > int(self.mSharePercentGoalMin/100)
105+
106+ def _genSharePrecent (self ):
107+ """generate share percent min/max
108+ """
109+ if self .mSharePercent > self .mSharePercentDelta :
110+ self .mSharePercentMin = self .mSharePercent - self .mSharePercentDelta
111+ else :
112+ self .mSharePercentMin = 0
113+
114+ if self .mSharePercent < 100 - self .mSharePercentDelta :
115+ self .mSharePercentMax = self .mSharePercent + self .mSharePercentDelta
116+ else :
117+ self .mSharePercentMax = 100
118+
119+ my_obj_rand = ThreadGroupConstraintItem (8 , 80 )
120+ for i in range (10 ):
121+ print ("Iter %d" , i )
122+ my_obj_rand .randomize (debug = False )
123+ self .assertEqual (my_obj_rand .mThreadNum , sum (my_obj_rand .GroupList ))
124+ # with vsc.randomize_with(my_obj_rand):
125+ # my_obj_rand.GroupList.sum == my_obj_rand.mThreadNum
126+ print ("Thread_num: %0d, GroupList.sum: %d" % (my_obj_rand .mThreadNum , sum (my_obj_rand .GroupList )))
127+ for i ,it in enumerate (my_obj_rand .GroupList ):
128+ print (" GroupList[%d]: %d" % (i , it ))
129+ print (" GroupListScore[%d]: %d" % (i , my_obj_rand .GroupListScore [i ]))
130+
0 commit comments