|
| 1 | +#include "vendor/unity.h" |
| 2 | + |
| 3 | +#define BUFFER_SIZE 80 |
| 4 | + |
| 5 | +extern void ciphertext(char *buffer, const char *plaintext); |
| 6 | + |
| 7 | +void setUp(void) { |
| 8 | +} |
| 9 | + |
| 10 | +void tearDown(void) { |
| 11 | +} |
| 12 | + |
| 13 | +void test_empty_plaintext_results_in_an_empty_ciphertext(void) { |
| 14 | + char buffer[BUFFER_SIZE]; |
| 15 | + |
| 16 | + ciphertext(buffer, ""); |
| 17 | + TEST_ASSERT_EQUAL_STRING("", buffer); |
| 18 | +} |
| 19 | + |
| 20 | +void test_normalization_results_in_empty_plaintext(void) { |
| 21 | + TEST_IGNORE(); |
| 22 | + char buffer[BUFFER_SIZE]; |
| 23 | + |
| 24 | + ciphertext(buffer, "... --- ..."); |
| 25 | + TEST_ASSERT_EQUAL_STRING("", buffer); |
| 26 | +} |
| 27 | + |
| 28 | +void test_lowercase(void) { |
| 29 | + TEST_IGNORE(); |
| 30 | + char buffer[BUFFER_SIZE]; |
| 31 | + |
| 32 | + ciphertext(buffer, "A"); |
| 33 | + TEST_ASSERT_EQUAL_STRING("a", buffer); |
| 34 | +} |
| 35 | + |
| 36 | +void test_remove_spaces(void) { |
| 37 | + TEST_IGNORE(); |
| 38 | + char buffer[BUFFER_SIZE]; |
| 39 | + |
| 40 | + ciphertext(buffer, " b "); |
| 41 | + TEST_ASSERT_EQUAL_STRING("b", buffer); |
| 42 | +} |
| 43 | + |
| 44 | +void test_remove_punctuation(void) { |
| 45 | + TEST_IGNORE(); |
| 46 | + char buffer[BUFFER_SIZE]; |
| 47 | + |
| 48 | + ciphertext(buffer, "@1,%!"); |
| 49 | + TEST_ASSERT_EQUAL_STRING("1", buffer); |
| 50 | +} |
| 51 | + |
| 52 | +void test_9_character_plaintext_results_in_3_chunks_of_3_characters(void) { |
| 53 | + TEST_IGNORE(); |
| 54 | + char buffer[BUFFER_SIZE]; |
| 55 | + |
| 56 | + ciphertext(buffer, "This is fun!"); |
| 57 | + TEST_ASSERT_EQUAL_STRING("tsf hiu isn", buffer); |
| 58 | +} |
| 59 | + |
| 60 | +void test_8_character_plaintext_results_in_3_chunks_the_last_one_with_a_trailing_space(void) { |
| 61 | + TEST_IGNORE(); |
| 62 | + char buffer[BUFFER_SIZE]; |
| 63 | + |
| 64 | + ciphertext(buffer, "Chill out."); |
| 65 | + TEST_ASSERT_EQUAL_STRING("clu hlt io ", buffer); |
| 66 | +} |
| 67 | + |
| 68 | +void test_54_character_plaintext_results_in_8_chunks_the_last_two_with_trailing_spaces(void) { |
| 69 | + TEST_IGNORE(); |
| 70 | + char buffer[BUFFER_SIZE]; |
| 71 | + |
| 72 | + ciphertext(buffer, "If man was meant to stay on the ground, god would have given us roots."); |
| 73 | + TEST_ASSERT_EQUAL_STRING("imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau ", buffer); |
| 74 | +} |
| 75 | + |
| 76 | +int main(void) { |
| 77 | + UNITY_BEGIN(); |
| 78 | + RUN_TEST(test_empty_plaintext_results_in_an_empty_ciphertext); |
| 79 | + RUN_TEST(test_normalization_results_in_empty_plaintext); |
| 80 | + RUN_TEST(test_lowercase); |
| 81 | + RUN_TEST(test_remove_spaces); |
| 82 | + RUN_TEST(test_remove_punctuation); |
| 83 | + RUN_TEST(test_9_character_plaintext_results_in_3_chunks_of_3_characters); |
| 84 | + RUN_TEST(test_8_character_plaintext_results_in_3_chunks_the_last_one_with_a_trailing_space); |
| 85 | + RUN_TEST(test_54_character_plaintext_results_in_8_chunks_the_last_two_with_trailing_spaces); |
| 86 | + return UNITY_END(); |
| 87 | +} |
0 commit comments