Exemplo n.º 1
0
/** 
  Test funckji dictionary_hints().
  Wstawienie do słownika 7 słów.
  Sprawdzenie, czy funkcja zwraca prawidłowe podpowiedzi.
  */
static void dictionary_hints_test(void** state) {
	struct dictionary *dict;
	dict = dictionary_new();
	struct word_list *l = malloc(sizeof(word_list));
    word_list_init(l);
    wchar_t *word1 = L"at";
    wchar_t *word2 = L"car";
    wchar_t *word3 = L"cat";
    wchar_t *word4 = L"cats";
    wchar_t *word5 = L"cut";
    wchar_t *word6 = L"mat";
    wchar_t *word7 = L"rat";
	dictionary_insert(dict, word1);
	dictionary_insert(dict, word2);
	dictionary_insert(dict, word3);
	dictionary_insert(dict, word4);
	dictionary_insert(dict, word5);
	dictionary_insert(dict, word6);
	dictionary_insert(dict, word7);
	dictionary_hints(dict, word3, l);
	assert_string_equal(l->next->word, word1);
	assert_string_equal(l->next->next->word, word2);
	assert_string_equal(l->next->next->next->word, word3);
	assert_string_equal(l->next->next->next->next->word, word4);
	assert_string_equal(l->next->next->next->next->next->word, word5);
	assert_string_equal(l->next->next->next->next->next->next->word, word6);
	assert_string_equal(l->next->next->next->next->next->next->next->word, word7);
	word_list_done(l);
	dictionary_done(dict);
	free(l);
}
Exemplo n.º 2
0
/**
  Test funkcji word_list_init().
  Sprawdzenie, czy word_list powstaje prawidłowo.
  */
static void word_list_init_test(void** state) {
    struct word_list *l = malloc(sizeof(word_list));
    word_list_init(l);
    assert_int_equal(word_list_size(l), 0);
    word_list_done(l);
    free(l);
}
Exemplo n.º 3
0
/**
  Test funckji word_list_add().
  Dodanie elementu do pustej listy.
  */
static void word_list_add_to_empty_test(void** state) {
    struct word_list *l = malloc(sizeof(word_list));
    word_list_init(l);
    word_list_add(l, test);
    assert_int_equal(word_list_size(l), 1);
    assert_true(wcscmp(test, word_list_get(l)[0]) == 0);
    word_list_done(l);
    free(l);
}
Exemplo n.º 4
0
/**
  Ustawienie początkowych parametrów word_list.
  */
static int word_list_setup(void **state) {
    struct word_list *l = malloc(sizeof(struct word_list));
    if (!l) 
        return -1;
    word_list_init(l);
    word_list_add(l, third);
    word_list_add(l, first);
    word_list_add(l, second);
    *state = l;
    return 0;
}
Exemplo n.º 5
0
void dictionary_hints(const struct dictionary *dict, const wchar_t* word,
        struct word_list *list)
{
	word_list_init(list);
	int *n;
	wchar_t **hints;
	possible_hints(dict, word, &n, &hints);
	for (int i = 0; i < *n; i++)
		if (dictionary_find(dict, hints[i]) && !word_list_find(list, hints[i]))
			word_list_add(list, hints[i]);
	for (int i = 0; i < *n; i++)
		free(hints[i]);

}
Exemplo n.º 6
0
/**
  Testuje zapisyanie do listy słów.
  @param state Środowisko testowe.
  */
static void trie_to_word_list_test(void** state)
{
    trie_setup(state);

    Trie *trie = *state;

    struct word_list list;
    word_list_init(&list);

    trie_to_word_list(trie, &list);

    assert_int_equal(word_list_size(&list), 3);
    for (size_t i = 0; i < word_list_size(&list); i++)
    {
        assert_true(trie_has_word(trie, word_list_get(&list)[i]));
    }

    word_list_done(&list);
    trie_teardown(state);
}