1 | /* Copyright (C) 2006 MySQL AB |
2 | Use is subject to license terms |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; version 2 of the License. |
7 | |
8 | This program is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License |
14 | along with this program; if not, write to the Free Software |
15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
16 | |
17 | #include <tap.h> |
18 | |
19 | unsigned int gcs(unsigned int a, unsigned int b) |
20 | { |
21 | if (b > a) { |
22 | unsigned int t = a; |
23 | a = b; |
24 | b = t; |
25 | } |
26 | |
27 | while (b != 0) { |
28 | unsigned int m = a % b; |
29 | a = b; |
30 | b = m; |
31 | } |
32 | return a; |
33 | } |
34 | |
35 | int main() { |
36 | unsigned int a,b; |
37 | unsigned int failed; |
38 | plan(1); |
39 | diag("Testing basic functions" ); |
40 | failed = 0; |
41 | for (a = 1 ; a < 2000 ; ++a) |
42 | for (b = 1 ; b < 2000 ; ++b) |
43 | { |
44 | unsigned int d = gcs(a, b); |
45 | if (a % d != 0 || b % d != 0) { |
46 | ++failed; |
47 | diag("Failed for gcs(%4u,%4u)" , a, b); |
48 | } |
49 | } |
50 | ok(failed == 0, "Testing gcs()" ); |
51 | return exit_status(); |
52 | } |
53 | |
54 | |