예제 #1
0
 def test_application_code_hundred_thousand(self):
     n = 100000
     tempList = []
     temp = ''
     ri = RandomInformation(n)
     for i in range(n // 2):
         temp = ri.randomApplicationCode()
         self.assertTrue(temp not in tempList)
         tempList.append(temp)
예제 #2
0
 def test_id_success(self):
     ri = RandomInformation()
     ids = ri.idGenerater()
     for i in range(20):
         next(ids)
     self.assertEqual(next(ids), 21)
     for i in range(20):
         next(ids)
     self.assertEqual(next(ids), 42)
예제 #3
0
 def test_application_code_ten_thousand(self):
     n = 10000
     tempList = []
     temp = ''
     ri = RandomInformation(n)
     for i in range(n):
         temp = ri.randomApplicationCode()
         self.assertTrue(temp not in tempList)
         tempList.append(temp)
     else:
         with self.assertRaises(Exception):
             ri.randomApplicationCode()
예제 #4
0
 def test_application_code_nagative_number(self):
     ri = RandomInformation(-1)
     with self.assertRaises(Exception):
         ri.randomApplicationCode()
     ri = RandomInformation(-10)
     with self.assertRaises(Exception):
         ri.randomApplicationCode()
예제 #5
0
 def test_seed_equal(self):
     ri1 = RandomInformation(seed=100)
     ri2 = RandomInformation(seed=100)
     for i in range(500):
         result1 = ri1.randomApplicationCode()
         result2 = ri2.randomApplicationCode()
         self.assertEqual(result1, result2)
예제 #6
0
def start_lottery():
    session = SessionInfo(1, '第一期摇号结果', 10000, 1)
    randomInfo = RandomInformation(seed=session.getSeed())
    # 创建参与者
    pool = []
    for i in range(session.getValidApplictionCodeCount()):
        pool.append(
            ParticipantInfo(i, int(time.time()),
                            randomInfo.randomApplicationCode(),
                            random.randint(1, 14)))
    # 根据申请嘛排序

    def sortApplicationCode(x, y):
        return -1 if x.getApplicationCode() < y.getApplicationCode() else 1

    pool = sorted(pool, key=functools.cmp_to_key(sortApplicationCode))
    # 分配摇号基数序列
    tempId = 0
    for i in range(1, 15):
        for j in pool:
            if j.getRate() >= i:
                tempId += 1
                j.setAppendLotteryBaseId(tempId)
    # for i in pool:
    # print(i.getLotteryBaseId(), i.getRate())
    # 摇号结果
    resultPool = []
    random.seed(session.getSeed())
    while len(resultPool) < session.getTotalWins():
        randomCode = random.randint(1, tempId)
        for i in pool:
            if randomCode in i.getLotteryBaseId(
            ) and randomCode not in resultPool:
                resultPool.append(i)
    print(tempId)
    for i in resultPool:
        print(i)
예제 #7
0
 def test_application_code_one(self):
     ri = RandomInformation(1)
     ri.randomApplicationCode()
     with self.assertRaises(Exception):
         ri.randomApplicationCode()
예제 #8
0
 def test_id_failure(self):
     ri = RandomInformation()
     ids = ri.idGenerater()
     for i in range(20):
         next(ids)
     self.assertNotEqual(next(ids), 1)