编写一个程序,随机生成NextDate函数的100条测试用例
时间: 2024-05-14 22:12:51 浏览: 56
由于不知道NextDate函数的具体实现,以下程序只能生成符合日期格式的随机测试用例:
```python
import random
# 生成随机的年份、月份、日期
def generate_random_date():
year = random.randint(1900, 2100)
month = random.randint(1, 12)
if month in [1, 3, 5, 7, 8, 10, 12]:
day = random.randint(1, 31)
elif month in [4, 6, 9, 11]:
day = random.randint(1, 30)
else:
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
day = random.randint(1, 29)
else:
day = random.randint(1, 28)
return (year, month, day)
# 将日期转换成字符串格式
def date_to_string(date):
year, month, day = date
return f"{year}-{month:02d}-{day:02d}"
# 生成100条测试用例
test_cases = []
for i in range(100):
date = generate_random_date()
test_cases.append(date_to_string(date))
# 打印测试用例
for case in test_cases:
print(case)
```
输出示例:
```
1965-07-19
1906-04-21
1993-09-16
2017-02-01
1973-12-16
...
```
阅读全文