我有一个进程,我以100000块的形式查询数据库,如果是超时错误,我想重试最多5次,否则发出警报。我怎么能为此写一个#include <stdio.h>
void show (int subs[], int k) {
int i;
for (i=1; i<=k; i++)
printf("%i ", subs[i]);
puts("");
}
void enumerate (int n) {
int subs[n+1], k = n, l = 0;
*subs = 0;
// Populate subs with longest possible sequence.
for (int i = 0; i < n + 1; i++) {
subs[i] = i;
}
while (0 < k) {
show(subs, k);
// Find first increasible spot
l = 0;
for (int i = k; 0 < i; i--) {
if (subs[i] + k - i < n) {
l = i;
break;
}
}
if (0 < l) {
// Create our increasing sequence
subs[l]++;
for (int i = l+1; i <= n; i++) {
subs[i] = subs[i-1] + 1;
}
}
else {
// Make k shorter and reset the sequence.
k = k-1;
for (int i = 0; i < n + 1; i++) {
subs[i] = i;
}
}
}
}
int main(void) {
enumerate(4);
return 0;
}
?我不确定如何模拟环境,所以我可以仔细检查逻辑。测试警报(这是一封电子邮件)也很困难,除了发送它并查看它是否到达。你会怎么写这个测试?这是我的代码:
unittest
错误会在调用它的过程中被捕获。