1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "print_integer.h"
#include <limits.h>
// test code - test functionality of print_integer.h
// REMINDER: do not copy test cases from this file (unless specified)
// you can use this to generate ideas for test cases,
// but your tests should be your own
int main(int argc, char* argv[]) {
// zero in base 10 <- okay to copy
printf("0 in base 10 is ");
print_integer(0, 10, "");
fputc('\n', stdout);
// single digit in base 10 <-- okay to copy idea
print_integer(4, 10, "");
fputc('\n', stdout);
// one digit in base 16
print_integer(12, 16, "");
fputc('\n', stdout);
// two digits in base 10
print_integer(41, 10, "");
fputc('\n', stdout);
// three digits in base 10
print_integer(413, 10, "");
fputc('\n', stdout);
// other TDD tests
// finished with TDD
// easy tests
print_integer(0x7b, 16, ""); // prints "7b"
print_integer( 123, 16, ""); // prints "7b"
// lines 38 and 39 are redundant
// compiles to the same
print_integer(0124, 8, ""); // prints "124"
// extra 0 at beginning makes octal
print_integer(1234, 10, "");
// edge cases - n <-- use the idea of edge cases to come up with your own
// you may end up with similar tests to mine, the important thing is practice finding edge cases
print_integer(INT_MIN, 10, "");
print_integer(INT_MAX, 10, "");
// edge cases - radix
print_integer(100, 2, "");
print_integer(100, 36, "");
// edge cases - prefix
print_integer(100, 10, ""); // min prefix, empty
print_integer(100, 10, "Bacon"); // "longest"* prefix
// * long enough that we are reasonably sure longer will work
// corner casesi <-- free to use this test
print_integer(INT_MAX, 2, "");
// boundry cases - boundary around switch from numbers to letters
print_integer( 9, 16, "");
print_integer(10, 16, "");
print_integer(11, 16, "");
// boundary around negative numbers
print_integer(-1, 16, "");
print_integer( 0, 16, "");
print_integer( 1, 16, "");
// special case - negative and prefix
print_integer(-9, 16, "do not copy"); // expect -do not copy9
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2022 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.