blob: 220033591e00fd61e391a199b3a321b79603cbca (
plain) (
tree)
|
|
#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();
}
|