1 /*********************************************************************
2 * Filename: rot-13_test.c
3 * Author: Brad Conte (brad AT bradconte.com)
5 * Disclaimer: This code is presented "as is" without any guarantees.
6 * Details: Performs known-answer tests on the corresponding ROT-13
7 implementation. These tests do not encompass the full
8 range of available test vectors, however, if the tests
9 pass it is very, very likely that the code is correct
10 and was compiled properly. This code also serves as
11 example usage of the functions.
12 *********************************************************************/
14 /*************************** HEADER FILES ***************************/
19 /*********************** FUNCTION DEFINITIONS ***********************/
22 char text[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};
23 char code[] = {"NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"};
27 // To encode, just apply ROT-13.
30 pass = pass && !strcmp(code, buf);
32 // To decode, just re-apply ROT-13.
34 pass = pass && !strcmp(text, buf);
41 printf("ROT-13 tests: %s\n", rot13_test() ? "SUCCEEDED" : "FAILED");