-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The refactoring of the good and bad tests
- Loading branch information
Showing
204 changed files
with
4,655 additions
and
0 deletions.
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
project/tests/in_progress/for_main/bad/algorthms/hanoy/00181/00181.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* example from http://barnyard.syr.edu/quickies/hanoi.c */ | ||
|
||
/* hanoi.c: solves the tower of hanoi problem. (Programming exercise.) */ | ||
/* By Terry R. McConnell (12/2/97) */ | ||
/* Compile: cc -o hanoi hanoi.c */ | ||
|
||
/* This program does no error checking. But then, if it's right, | ||
it's right ... right ? */ | ||
|
||
|
||
/* The original towers of hanoi problem seems to have been originally posed | ||
by one M. Claus in 1883. There is a popular legend that goes along with | ||
it that has been often repeated and paraphrased. It goes something like this: | ||
In the great temple at Benares there are 3 golden spikes. On one of them, | ||
God placed 64 disks increasing in size from bottom to top, at the beginning | ||
of time. Since then, and to this day, the priest on duty constantly transfers | ||
disks, one at a time, in such a way that no larger disk is ever put on top | ||
of a smaller one. When the disks have been transferred entirely to another | ||
spike the Universe will come to an end in a large thunderclap. | ||
This paraphrases the original legend due to DeParville, La Nature, Paris 1884, | ||
Part I, 285-286. For this and further information see: Mathematical | ||
Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967, | ||
303-305. | ||
* | ||
* | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define TRUE 1 | ||
#define FALSE 0 | ||
|
||
/* This is the number of "disks" on tower A initially. Taken to be 64 in the | ||
* legend. The number of moves required, in general, is 2^N - 1. For N = 64, | ||
* this is 18,446,744,073,709,551,615 */ | ||
#define N 4 | ||
|
||
/* These are the three towers. For example if the state of A is 0,1,3,4, that | ||
* means that there are three discs on A of sizes 1, 3, and 4. (Think of right | ||
* as being the "down" direction.) */ | ||
int A[N], B[N], C[N]; | ||
|
||
void Hanoi(int,int*,int*,int*); | ||
|
||
/* Print the current configuration of A, B, and C to the screen */ | ||
void PrintAll() | ||
{ | ||
int i; | ||
|
||
printf("A: "); | ||
for(i=0;i<N;i++)printf(" %d ",A[i]); | ||
printf("\n"); | ||
|
||
printf("B: "); | ||
for(i=0;i<N;i++)printf(" %d ",B[i]); | ||
printf("\n"); | ||
|
||
printf("C: "); | ||
for(i=0;i<N;i++)printf(" %d ",C[i]); | ||
printf("\n"); | ||
printf("------------------------------------------\n"); | ||
return; | ||
} | ||
|
||
/* Move the leftmost nonzero element of source to dest, leave behind 0. */ | ||
/* Returns the value moved (not used.) */ | ||
int Move(int *source, int *dest) | ||
{ | ||
int i = 0, j = 0; | ||
|
||
while (i<N && (source[i])==0) i++; | ||
while (j<N && (dest[j])==0) j++; | ||
|
||
dest[j-1] = source[i]; | ||
source[i] = 0; | ||
PrintAll(); /* Print configuration after each move. */ | ||
return dest[j-1]; | ||
} | ||
|
||
|
||
/* Moves first n nonzero numbers from source to dest using the rules of Hanoi. | ||
Calls itself recursively. | ||
*/ | ||
void Hanoi(int n,int *source, int *dest, int *spare) | ||
{ | ||
int i; | ||
if(n==1){ | ||
Move(source,dest); | ||
return; | ||
} | ||
|
||
Hanoi(n-1,source,spare,dest); | ||
Move(source,dest); | ||
Hanoi(n-1,spare,dest,source); | ||
return; | ||
} | ||
|
||
int test() | ||
{ | ||
int i; | ||
|
||
/* initialize the towers */ | ||
for(i=0;i<N;i++)A[i]=i+1; | ||
for(i=0;i<N;i++)B[i]=0; | ||
for(i=0;i<N;i++)C[i]=0; | ||
|
||
printf("Solution of Tower of Hanoi Problem with %d Disks\n\n",N); | ||
|
||
/* Print the starting state */ | ||
printf("Starting state:\n"); | ||
PrintAll(); | ||
printf("\n\nSubsequent states:\n\n"); | ||
|
||
/* Do it! Use A = Source, B = Destination, C = Spare */ | ||
Hanoi(N,A,B,C); | ||
|
||
return 0; | ||
} | ||
|
||
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ | ||
|
||
#include <stdio.h> | ||
int main() | ||
{ | ||
int x = test(); | ||
printf("%d\n", x); | ||
return x; | ||
} |
16 changes: 16 additions & 0 deletions
16
project/tests/in_progress/for_main/bad/operations/ptr_bin_op/ptr_plus_val/ptr_plus_long.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//clang -Xclang -ast-dump -fsyntax-only main.c | ||
#include <stdio.h> | ||
|
||
long array[3] = {0, 1, 2}; | ||
long *ptr; | ||
|
||
int main() { | ||
ptr = array; | ||
printf("array[0] = %ld\n", *ptr); | ||
ptr = array + 2; | ||
printf("array[2] = %ld\n", *ptr); | ||
--ptr; | ||
printf("array[1] = %ld\n", *ptr); | ||
|
||
return 0; | ||
} |
17 changes: 17 additions & 0 deletions
17
project/tests/in_progress/for_main/bad/operations/question/00076/00076.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
int | ||
test() | ||
{ | ||
if(0 ? 1 : 0) | ||
return 1; | ||
if(1 ? 0 : 1) | ||
return 2; | ||
return 0; | ||
} | ||
|
||
#include <stdio.h> | ||
int main() | ||
{ | ||
int x = test(); | ||
printf("%d\n", x); | ||
return x; | ||
} |
19 changes: 19 additions & 0 deletions
19
project/tests/in_progress/for_main/bad/operations/question/00109/00109.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
int | ||
test() | ||
{ | ||
int x = 0; | ||
int y = 1; | ||
if(x ? 1 : 0) | ||
return 1; | ||
if(y ? 0 : 1) | ||
return 2; | ||
return 0; | ||
} | ||
|
||
#include <stdio.h> | ||
int main() | ||
{ | ||
int x = test(); | ||
printf("%d\n", x); | ||
return x; | ||
} |
18 changes: 18 additions & 0 deletions
18
project/tests/in_progress/for_main/bad/operations/question/00137/00137.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#define x(y) #y | ||
|
||
int | ||
test(void) | ||
{ | ||
char *p; | ||
p = x(hello) " is better than bye"; | ||
|
||
return (*p == 'h') ? 0 : 1; | ||
} | ||
|
||
#include <stdio.h> | ||
int main() | ||
{ | ||
int x = test(); | ||
printf("%d\n", x); | ||
return x; | ||
} |
18 changes: 18 additions & 0 deletions
18
project/tests/in_progress/for_main/bad/operations/question/00138/00138.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#define M(x) x | ||
#define A(a,b) a(b) | ||
|
||
int | ||
test(void) | ||
{ | ||
char *a = A(M,"hi"); | ||
|
||
return (a[1] == 'i') ? 0 : 1; | ||
} | ||
|
||
#include <stdio.h> | ||
int main() | ||
{ | ||
int x = test(); | ||
printf("%d\n", x); | ||
return x; | ||
} |
25 changes: 25 additions & 0 deletions
25
project/tests/in_progress/for_main/bad/operations/question/00144/00144.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
int | ||
test(void) | ||
{ | ||
int i, *q; | ||
void *p; | ||
|
||
i = i ? 0 : 0l; | ||
p = i ? (void *) 0 : 0; | ||
p = i ? 0 : (void *) 0; | ||
p = i ? 0 : (const void *) 0; | ||
q = i ? 0 : p; | ||
q = i ? p : 0; | ||
q = i ? q : 0; | ||
q = i ? 0 : q; | ||
|
||
return (int) q; | ||
} | ||
|
||
#include <stdio.h> | ||
int main() | ||
{ | ||
int x = test(); | ||
printf("%d\n", x); | ||
return x; | ||
} |
23 changes: 23 additions & 0 deletions
23
project/tests/in_progress/for_main/bad/operations/question/00183/00183.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <stdio.h> | ||
|
||
int test() | ||
{ | ||
int Count; | ||
|
||
for (Count = 0; Count < 10; Count++) | ||
{ | ||
printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3)); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/ | ||
|
||
#include <stdio.h> | ||
int main() | ||
{ | ||
int x = test(); | ||
printf("%d\n", x); | ||
return x; | ||
} |
52 changes: 52 additions & 0 deletions
52
project/tests/in_progress/for_main/bad/operations/shift/00200/00200.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* $Id: lshift-type.c 53089 2012-07-06 11:18:26Z vinc17/ypig $ | ||
Tests on left-shift type, written by Vincent Lefevre <vincent@vinc17.net>. | ||
ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on | ||
each of the operands. The type of the result is that of the promoted | ||
left operand." | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#define PTYPE(M) ((M) < 0 || -(M) < 0 ? -1 : 1) * (int) sizeof((M)+0) | ||
#define CHECK(X,T) check(#X, PTYPE(X), PTYPE((X) << (T) 1)) | ||
#define TEST1(X,T) do { CHECK(X,T); CHECK(X,unsigned T); } while (0) | ||
#define TEST2(X) \ | ||
do \ | ||
{ \ | ||
TEST1((X),short); \ | ||
TEST1((X),int); \ | ||
TEST1((X),long); \ | ||
TEST1((X),long long); \ | ||
} \ | ||
while (0) | ||
#define TEST3(X,T) do { TEST2((T)(X)); TEST2((unsigned T)(X)); } while (0) | ||
#define TEST4(X) \ | ||
do \ | ||
{ \ | ||
TEST3((X),short); \ | ||
TEST3((X),int); \ | ||
TEST3((X),long); \ | ||
TEST3((X),long long); \ | ||
} \ | ||
while (0) | ||
|
||
static int debug, nfailed = 0; | ||
|
||
static void check (const char *s, int arg1, int shift) | ||
{ | ||
int failed = arg1 != shift; | ||
if (debug || failed) | ||
printf ("%s %d %d\n", s, arg1, shift); | ||
nfailed += failed; | ||
} | ||
|
||
int main (int argc, char **argv) | ||
{ | ||
debug = argc > 1; | ||
TEST4(1); | ||
TEST4(-1); | ||
printf ("%d test(s) failed\n", nfailed); | ||
return nfailed != 0; | ||
} |
25 changes: 25 additions & 0 deletions
25
project/tests/in_progress/for_main/bad/operations/sizeof/00038/00038.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
int | ||
test() | ||
{ | ||
int x, *p; | ||
|
||
if (sizeof(0) < 2) | ||
return 1; | ||
if (sizeof 0 < 2) | ||
return 1; | ||
if (sizeof(char) < 1) | ||
return 1; | ||
if (sizeof(int) - 2 < 0) | ||
return 1; | ||
if (sizeof(&x) != sizeof p) | ||
return 1; | ||
return 0; | ||
} | ||
|
||
#include <stdio.h> | ||
int main() | ||
{ | ||
int x = test(); | ||
printf("%d\n", x); | ||
return x; | ||
} |
17 changes: 17 additions & 0 deletions
17
project/tests/in_progress/for_main/bad/operations/sizeof/00057/00057.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
int | ||
test() | ||
{ | ||
char a[16], b[16]; | ||
|
||
if(sizeof(a) != sizeof(b)) | ||
return 1; | ||
return 0; | ||
} | ||
|
||
#include <stdio.h> | ||
int main() | ||
{ | ||
int x = test(); | ||
printf("%d\n", x); | ||
return x; | ||
} |
Oops, something went wrong.
3ed1d9a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to github. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub:
3ed1d9a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to github. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: