diff options
author | Andinus <andinus@nand.sh> | 2021-08-11 15:26:15 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-08-11 15:26:15 +0530 |
commit | 321825828ac918bad28d0597a8616c6dc9802c3c (patch) | |
tree | 0b8e9cb1012197750eb58e972736319b2a6abac2 /c/acronym/test/test_acronym.c | |
parent | 2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff) | |
download | exercism-321825828ac918bad28d0597a8616c6dc9802c3c.tar.gz |
Add solved exercises
Diffstat (limited to 'c/acronym/test/test_acronym.c')
-rw-r--r-- | c/acronym/test/test_acronym.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/c/acronym/test/test_acronym.c b/c/acronym/test/test_acronym.c new file mode 100644 index 0000000..2200335 --- /dev/null +++ b/c/acronym/test/test_acronym.c @@ -0,0 +1,116 @@ +#include "vendor/unity.h" +#include "../src/acronym.h" +#include <stdlib.h> +#include <string.h> + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +static void check_abbreviation(char *phrase, char *expected) +{ + char *actual = abbreviate(phrase); + TEST_ASSERT_EQUAL_STRING(expected, actual); + free(actual); +} + +static void test_null_string(void) +{ + char *phrase = NULL; + char *expected = NULL; + check_abbreviation(phrase, expected); +} + +static void test_empty_string(void) +{ + char *phrase = ""; + char *expected = NULL; + check_abbreviation(phrase, expected); +} + +static void test_basic_abbreviation(void) +{ + char *phrase = "Portable Network Graphics"; + char *expected = "PNG"; + check_abbreviation(phrase, expected); +} + +static void test_lowercase_words(void) +{ + char *phrase = "Ruby on Rails"; + char *expected = "ROR"; + check_abbreviation(phrase, expected); +} + +static void test_punctuation(void) +{ + char *phrase = "First In, First Out"; + char *expected = "FIFO"; + check_abbreviation(phrase, expected); +} + +static void test_all_caps_words(void) +{ + char *phrase = "GNU Image Manipulation Program"; + char *expected = "GIMP"; + check_abbreviation(phrase, expected); +} + +static void test_punctuation_without_whitespace(void) +{ + char *phrase = "Complementary metal-oxide semiconductor"; + char *expected = "CMOS"; + check_abbreviation(phrase, expected); +} + +static void test_long_abbreviation(void) +{ + char *phrase = "Rolling On The Floor Laughing So Hard " + "That My Dogs Came Over And Licked Me"; + char *expected = "ROTFLSHTMDCOALM"; + check_abbreviation(phrase, expected); +} + +static void test_consecutive_delimiters_abbreviation(void) +{ + char *phrase = "Something - I made up from thin air"; + char *expected = "SIMUFTA"; + check_abbreviation(phrase, expected); +} + +static void test_apostrophes(void) +{ + char *phrase = "Halley's Comet"; + char *expected = "HC"; + check_abbreviation(phrase, expected); +} + +static void test_underscore_emphasis(void) +{ + char *phrase = "The Road _Not_ Taken"; + char *expected = "TRNT"; + check_abbreviation(phrase, expected); +} + +int main(void) +{ + UnityBegin("test/test_acronym.c"); + + RUN_TEST(test_null_string); + RUN_TEST(test_empty_string); + RUN_TEST(test_basic_abbreviation); + RUN_TEST(test_lowercase_words); + RUN_TEST(test_punctuation); + RUN_TEST(test_all_caps_words); + RUN_TEST(test_punctuation_without_whitespace); + RUN_TEST(test_long_abbreviation); + RUN_TEST(test_consecutive_delimiters_abbreviation); + RUN_TEST(test_apostrophes); + RUN_TEST(test_underscore_emphasis); + + return UnityEnd(); +} |