diff options
author | Haidong Ji | 2022-04-15 15:51:30 -0500 |
---|---|---|
committer | Haidong Ji | 2022-04-15 15:51:30 -0500 |
commit | 442a49ad5a48d417345959b903ae6a6d32d55759 (patch) | |
tree | c7127bb497e5e439018b1915e0136eec2c9cb124 /22_tests_power/test-power.c |
Excellent fundamentals and displine training, many tools and techniques
exercises: gdb, emacs, valgrind, git
Diffstat (limited to '22_tests_power/test-power.c')
-rw-r--r-- | 22_tests_power/test-power.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/22_tests_power/test-power.c b/22_tests_power/test-power.c new file mode 100644 index 0000000..95cb54e --- /dev/null +++ b/22_tests_power/test-power.c @@ -0,0 +1,88 @@ +#include <stdio.h> +#include <stdlib.h> + +unsigned power (unsigned x, unsigned y); + +int main() { + unsigned x; + unsigned y; + unsigned ans; + + x = 2; + y = 0; + ans = 1; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + x = 1; + y = 0; + ans = 1; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + + x = 1; + y = 1; + ans = 1; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + + x = 2; + y = 1; + ans = 2; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + + x = 2; + y = 3; + ans = 8; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + + x = 3; + y = 3; + ans = 27; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + + x = 1; + y = 3; + ans = 1; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + + x = 0; + y = 0; + ans = 1; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + + x = 3; + y = 2; + ans = 9; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + + x = -3; + y = 2; + ans = 9; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + + x = -2; + y = 3; + ans = -8; + if (ans != power(x, y)) { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} |