Skip to content

Commit 0db8a34

Browse files
committed
Update: checking the output
1 parent 2fdf568 commit 0db8a34

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

10_Harshad_Number/C/jb1717/10_Harshad_Number_test.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdio.h>
2+
#include <assert.h>
23
#include "10_Harshad_Number.h"
34

45
/*
@@ -7,12 +8,25 @@
78
int main(void)
89
{
910
int pretty = 0;
11+
int idx = 0;
12+
int sample[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
13+
12, 18, 20, 21, 24, 27, 30, 36,
14+
40, 42, 45, 48, 50, 54, 60, 63,
15+
70, 72, 80, 81, 84, 90, 100, 102,
16+
108, 110, 111, 112, 114, 117, 120,
17+
126, 132, 133, 135, 140, 144, 150,
18+
152,153, 156, 162, 171, 180, 190,
19+
192, 195, 198, 200};
1020

1121
printf("Display all Harshad numbers between 1 and 200\n\n");
22+
1223
for (int i = 0; i < 201; ++i)
1324
{
1425
if (isHarshad(i))
1526
{
27+
// if a number is consider Harshad but not in the sample
28+
assert(sample[idx++] == i);
29+
1630
printf("%d", i);
1731
pretty++;
1832
if (pretty % 5 == 0)
@@ -21,6 +35,6 @@ int main(void)
2135
printf("\t");
2236
}
2337
}
24-
printf("\n\n=== END ===\n");
38+
printf("\n\n=== END ===\n\n");
2539
return (0);
2640
}

0 commit comments

Comments
 (0)