update tests

This commit is contained in:
Vlasta Vesely 2020-01-07 13:18:54 +01:00
parent dba90f5c15
commit 1beea31afa
No known key found for this signature in database
GPG key ID: EB0E649DC0DFCC22
7 changed files with 80 additions and 90 deletions

View file

@ -3,7 +3,7 @@ PREFIX=/usr/local
.PHONY: main test install uninstall clean
OBJECTS = iast.o iast-czech.o transliteration.o transcription.o utf8.o encoder.o
TEST_OBJECTS = tests/main.o tests/translit.o tests/transcript.o
TEST_OBJECTS = tests/main.o tests/translit.o tests/transcript.o tests/encoder.o
CFLAGS = -Wall
LIBS =
TEST_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags check)
@ -40,4 +40,4 @@ uninstall:
rm -f $(PREFIX)/share/man/man1/$(PROGNAME).1.gz
clean:
$(RM) iast *.o */*.o *.d */*.d doc/*.gz
$(RM) iast tests/test *.o */*.o *.d */*.d doc/*.gz

27
tests/encoder.c Normal file
View file

@ -0,0 +1,27 @@
#include "test.h"
#include "encoder.h"
#include "../encoder.h"
static void test_encoding(const char *in, const char *expected)
{
char *iast = encode_iast_punctation(in);
ck_assert_str_eq(expected, iast);
free(iast);
}
START_TEST(test_encode_punctation)
{
test_encoding("sam.skr.tam", "saṃskṛtam");
test_encoding("yogah.", "yogaḥ");
test_encoding("tantras,a-stram", "tantraśāstram");
test_encoding("tantrašástram", "tantraśāstram");
}
END_TEST
void register_encoder_tests(TCase *test_case)
{
tcase_add_test(test_case, test_encode_punctation);
}

8
tests/encoder.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef __TEST_ENCODER_H
#define __TEST_ENCODER_H
#include <check.h>
void register_encoder_tests(TCase *test_case);
#endif /* __TEST_ENCODER_H */

View file

@ -1,6 +1,7 @@
#include "test.h"
#include "translit.h"
#include "transcript.h"
#include "encoder.h"
static Suite *create_test_suite()
{
@ -12,6 +13,7 @@ static Suite *create_test_suite()
register_translit_tests(test_case);
register_transcript_tests(test_case);
register_encoder_tests(test_case);
suite_add_tcase(suite, test_case);
return suite;

View file

@ -1,40 +0,0 @@
#!/bin/sh
set -e
test_word()
{
output=$(echo -n "$1" | ./iast $3 --)
expected="$2"
test "x$output" = "x$expected" &&
echo "\033[32m$output\033[0m = \033[32m$expected\033[0m" ||
echo "\033[31m$output\033[0m != \033[31m$expected\033[0m"
}
echo "Transliteration to IAST"
test_word "संस्कृतम्" "saṃskṛtam"
test_word "आर्यावर्त" "āryāvarta"
test_word "तन्त्रशास्त्रम्" "tantraśāstram"
test_word "सांख्य" "sāṃkhya"
test_word "ऋग्वेद" "ṛgveda"
test_word "महाभारतम्" "mahābhāratam"
test_word "सरस्वती नदी" "sarasvatī nadī"
test_word "देवनागरी" "devanāgarī"
test_word "योगः" "yogaḥ"
test_word "भगवद्गीता" "bhagavadgītā"
test_word "सम्भोग" "sambhoga"
echo
echo "Transliteration to czech"
test_word "तन्त्रशास्त्रम्" "tantrašástra" -c
test_word "सांख्य" "sánkhja" -c
test_word "महाभारतम्" "mahábhárata" -c
test_word "योगः" "jóga" -c
test_word "भगवद्गीता" "bhagavadgíta" -c
echo
echo "Encoding"
test_word "sam.skr.tam" "saṃskṛtam" -e
test_word "yogah." "yogaḥ" -e
test_word "tantras,a-stram" "tantraśāstram" -e
test_word "tantrašástram" "tantraśāstram" -e

View file

@ -2,29 +2,24 @@
#include "transcript.h"
#include "../transcription.h"
static void test_transcript(const char *devanagari, const char *latin)
{
char *czech = transcript_devanagari_to_czech(devanagari);
ck_assert_str_eq(latin, czech);
free(czech);
}
START_TEST(test_transcript_devanagari_to_czech)
{
char *czech;
test_transcript("तन्त्रशास्त्रम्", "tantrašástra");
czech = transcript_devanagari_to_czech("तन्त्रशास्त्रम्");
ck_assert_str_eq("tantrašástra", czech);
free(czech);
test_transcript("सांख्य", "sánkhja");
czech = transcript_devanagari_to_czech("सांख्य");
ck_assert_str_eq("sánkhja", czech);
free(czech);
test_transcript("महाभारतम्", "mahábhárata");
czech = transcript_devanagari_to_czech("महाभारतम्");
ck_assert_str_eq("mahábhárata", czech);
free(czech);
test_transcript("योगः", "jóga");
czech = transcript_devanagari_to_czech("योगः");
ck_assert_str_eq("jóga", czech);
free(czech);
czech = transcript_devanagari_to_czech("भगवद्गीता");
ck_assert_str_eq("bhagavadgíta", czech);
free(czech);
test_transcript("भगवद्गीता", "bhagavadgíta");
}
END_TEST

View file

@ -2,51 +2,49 @@
#include "translit.h"
#include "../transliteration.h"
static void test_transliterate_devanagari_to_latin(const char *devanagari,
const char *latin)
{
char *str = transliterate_devanagari_to_latin(devanagari);
ck_assert_str_eq(latin, str);
free(str);
}
static void test_transliterate_latin_to_devanagari(const char *latin,
const char *devanagari)
{
char *str = transliterate_latin_to_devanagari(latin);
ck_assert_str_eq(devanagari, str);
free(str);
}
START_TEST(test_translit_devanagari_to_latin)
{
char *latin;
/* https://en.wikipedia.org/wiki/Sanskrit */
latin = transliterate_devanagari_to_latin("संस्कृतम्");
ck_assert_str_eq("saṃskṛtam", latin);
free(latin);
test_transliterate_devanagari_to_latin("संस्कृतम्", "saṃskṛtam");
/* https://en.wikipedia.org/wiki/Bhagavad_Gita */
latin = transliterate_devanagari_to_latin("भगवद्गीता");
ck_assert_str_eq("bhagavadgītā", latin);
free(latin);
test_transliterate_devanagari_to_latin("भगवद्गीता", "bhagavadgītā");
/* https://en.wikipedia.org/wiki/%C4%80ry%C4%81varta */
latin = transliterate_devanagari_to_latin("आर्यावर्त");
ck_assert_str_eq("āryāvarta", latin);
free(latin);
test_transliterate_devanagari_to_latin("आर्यावर्त", "āryāvarta");
/* https://en.wikipedia.org/wiki/Mahabharata */
latin = transliterate_devanagari_to_latin("महाभारतम्");
ck_assert_str_eq("mahābhāratam", latin);
free(latin);
test_transliterate_devanagari_to_latin("महाभारतम्", "mahābhāratam");
/* https://en.wikipedia.org/wiki/Devanagari */
test_transliterate_devanagari_to_latin("देवनागरी", "devanāgarī");
}
END_TEST
START_TEST(test_translit_latin_to_devanagari)
{
char *devanagari;
devanagari = transliterate_latin_to_devanagari("saṃskṛtam");
ck_assert_str_eq("संस्कृतम्", devanagari);
free(devanagari);
devanagari = transliterate_latin_to_devanagari("bhagavadgītā");
ck_assert_str_eq("भगवद्गीता", devanagari);
free(devanagari);
devanagari = transliterate_latin_to_devanagari("āryāvarta");
ck_assert_str_eq("आर्यावर्त", devanagari);
free(devanagari);
devanagari = transliterate_latin_to_devanagari("mahābhāratam");
ck_assert_str_eq("महाभारतम्", devanagari);
free(devanagari);
test_transliterate_latin_to_devanagari("saṃskṛtam", "संस्कृतम्");
test_transliterate_latin_to_devanagari("bhagavadgītā", "भगवद्गीता");
test_transliterate_latin_to_devanagari("āryāvarta", "आर्यावर्त");
test_transliterate_latin_to_devanagari("mahābhāratam", "महाभारतम्");
test_transliterate_latin_to_devanagari("devanāgarī", "देवनागरी");
}
END_TEST