summary refs log tree commit diff stats
path: root/c/acronym/test/test_acronym.c
blob: 220033591e00fd61e391a199b3a321b79603cbca (plain) (blame)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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();
}