# 测试你的红包代码

print redPacket(5, 2000)

[2.74, 7.32, 7.01, 0.37, 2.56]

```import wechat
import random

tests = 100
for i in range(tests):
people = random.randint(1, 20)
money = random.randint(people, people * 20000)
result = wechat.redPacket(people, money)
print people, money / 100.0, result

for r in result:
if r < 0.01:
print 'ERROR: result < 0.01'
total = 0
for r in result:
total += r
if total - money / 100.0 > 0.000001:
print 'ERROR: total result != money'```

total - money / 100.0 > 0.000001

total == money / 100.0

```import wechat
import random
import unittest

class TestRedPacket(unittest.TestCase):
def test_red(self):
tests = 100
for i in range(tests):
people = random.randint(1, 20)
money = random.randint(people, people * 20000)
result = wechat.redPacket(people, money)
print people, money / 100.0, result

for r in result:
self.assertGreaterEqual(r, 0.01)
total = 0
for r in result:
total += r
self.assertAlmostEqual(total, money / 100.0)

if __name__ == '__main__':
unittest.main()```

```.
--------------------
Ran 1 test in 0.011s

OK```

```F
====================
FAIL: test_red (__main__.TestRedPacket)
--------------------
Traceback (most recent call last):
File "/Users/crossin/Private/crossincode/article/wechat red/test2.py", line 17, in test_red
self.assertGreaterEqual(r, 0.01)
AssertionError: 0.0 not greater than or equal to 0.01

--------------------
Ran 1 test in 0.001s

FAILED (failures=1)```

412 篇文章49 人订阅

0 条评论

## 相关文章

### kill.exe溢出漏洞分析与EXP讨论

* 本文原创作者：zzz66686，本文属FreeBuf原创奖励计划，未经许可禁止转载 1. 前言 前几日，笔者在exploit-db上发现了一个kill.ex...

25190

25090

### Windows Community Toolkit 3.0 - Gaze Interaction

Gaze Input & Tracking - 也就是视觉输入和跟踪，是一种和鼠标/触摸屏输入非常不一样的交互方式，利用人类眼球的识别和眼球方向角度的跟踪，来判...

13430

11030

23940

88650

43290

### Numpy使用1

Numpy介绍 NumPy is the fundamental package for scientific computing with Python. I...

21290

323100

10620