From 442a49ad5a48d417345959b903ae6a6d32d55759 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Fri, 15 Apr 2022 15:51:30 -0500 Subject: Great C programming fun Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git --- 22_tests_power/test-power.c | 88 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 22_tests_power/test-power.c (limited to '22_tests_power/test-power.c') 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 +#include + +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; +} -- cgit v1.2.3