Module:grc-accent/testcases

From Wiktionary, the free dictionary
Jump to navigation Jump to search

All tests passed. (refresh)

TextExpectedActual
test_add_accent:
Passedκρεως (1, noun)κρέωςκρέως
PassedΤρως (1, noun)ΤρώςΤρώς
Passedπολεως (1, noun)πόλεωςπόλεως
Passedπολεων (1, noun)πόλεωνπόλεων
PassedΠειριθοι (2, noun)ΠειρίθοιΠειρίθοι
PassedᾸ̓θηναιοιν (-2, noun)Ᾰ̓θηναίοινᾸ̓θηναίοιν
PassedᾸ̓θηναιοις (-2, noun)Ᾰ̓θηναίοιςᾸ̓θηναίοις
Passedβᾰρειαι (-2, noun)βᾰρεῖαιβᾰρεῖαι
Passedᾰ̓ληθειαι (-3, noun)ᾰ̓λήθειαιᾰ̓λήθειαι
PassedᾸ̓θηναιοι (3, noun)Ᾰ̓θηναῖοιᾸ̓θηναῖοι
Passedβᾰρειαι (2, noun)βᾰρεῖαιβᾰρεῖαι
Passedᾰ̓ληθειαι (2, noun)ᾰ̓λήθειαιᾰ̓λήθειαι
Passedαἱμᾰ (1, noun)αἷμᾰαἷμᾰ
Passedλογος (-2)λόγοςλόγος
Passedπροτερᾱ (-3)προτέρᾱπροτέρᾱ
PassedΑἰθιοπων (2)ΑἰθιόπωνΑἰθιόπων
Passedχωρῶν (1)χωρῶνχωρῶν
Passedδημος (1)δῆμοςδῆμος
Passedτοιουτος (2)τοιοῦτοςτοιοῦτος
Passedχωρᾱ (1)χώρᾱχώρᾱ
Passedμοιρᾰ (1)μοῖρᾰμοῖρᾰ
Passedπροτερᾱ (1)προτέρᾱπροτέρᾱ
Passedἐγενετο (1)ἐγένετοἐγένετο
Passedφως (1, circumflex)φῶςφῶς
Passedμοιρα (1)μοίραμοίρα
Passedμοιρα (1, circumflex)μοῖραμοῖρα
Passedἐγενετο (1, circumflex)ἐγένετοἐγένετο
Passedλογος (1)λόγοςλόγος
Passedλογος (1, circumflex)λόγοςλόγος
TextExpectedActual
test_detect_accent:
Passedἐγένετο2, acute2, acute
Passedἐγένετο (from end)3, acute3, acute
Passedτοιοῦτος2, circumflex2, circumflex
Passedτοιοῦτος (from end)2, circumflex2, circumflex
Passedφῶς1, circumflex1, circumflex
Passedφῶς (from end)1, circumflex1, circumflex
TextExpectedActual
test_get_accent_term:
Passedπολὺςbarytonebarytone
Passedπολύςoxytoneoxytone
Passedλέγωparoxytoneparoxytone
Passedγίγνομαιproparoxytoneproparoxytone
Passedφῶςperispomenonperispomenon
Passedοἷοςproperispomenonproperispomenon
TextExpectedActual
test_get_length:
ambiguous vowels
Passedαἷμᾰlong, shortlong, short
Passedμοῖραlong, eitherlong, either
Passedπάθοςeither, shorteither, short
Passedπᾰ́θοςshort, shortshort, short
Passedἆρᾰlong, shortlong, short
capital letters
Passedᾍδηςlong, longlong, long
PassedΑἰσχύλοςlong, either, shortlong, either, short
PassedἨλέκτρᾱlong, short, longlong, short, long
PassedἙλλάςshort, eithershort, either
short final diphthongs
Passedᾰ̓λήθειαιshort, long, long, shortshort, long, long, short
PassedᾸ̓θηναιοιshort, long, long, shortshort, long, long, short
PassedᾸ̓θηναίοινshort, long, long, longshort, long, long, long
PassedᾸ̓θηναίοιςshort, long, long, longshort, long, long, long
TextExpectedActual
test_get_weight:
Passedὀρθ (1)heavyheavy
Passedὀρθheavyheavy
Passedμικρ (1)heavyheavy
Passedμικρheavyheavy
Passedἰδι (1)(nil)(nil)
Passedἰδι(nil)(nil)
Passedῐ̓δῐ (1)lightlight
Passedῐ̓δῐlightlight
Passedφῐλ (1)lightlight
Passedφῐλlightlight
TextExpectedActual
test_harmonize_length:
Passedᾰ̓́λοξ, ἄλοκοςᾰ̓́λοξ, ᾰ̓́λοκοςᾰ̓́λοξ, ᾰ̓́λοκος
Passedἄλοκος, ᾰ̓́λοξᾰ̓́λοκος, ᾰ̓́λοξᾰ̓́λοκος, ᾰ̓́λοξ
Passedἄλοξ, ἄλοκοςᾰ̓́λοξ, ᾰ̓́λοκοςᾰ̓́λοξ, ᾰ̓́λοκος
PassedΑἰθίοψ, ΑἰθίοποςΑἰθῐ́οψ, Αἰθῐ́οποςΑἰθῐ́οψ, Αἰθῐ́οπος
transfer length only if both vowels have the same breathing mark
Passedἄξιος, ᾱἄξιος, ᾱἄξιος, ᾱ
TextExpectedActual
test_length_at:
Passedμοῖρα (2 syllables from end)longlong
Passedπάθους (2 syllables from end)eithereither
Passedπᾰ́θος (2 syllables from end)shortshort
TextExpectedActual
test_mark_implied_length:
Passedμοῖραμοῖρᾰμοῖρᾰ
Passedχώραχώρᾱχώρᾱ
Passedπάθοςπᾰ́θοςπᾰ́θος
Passedἀλήθειαἀλήθειᾰἀλήθειᾰ
TextExpectedActual
test_strip_accent:
Passedᾰ̓́νθρωποςανθρωποςανθρωπος
PassedΠηληῐ̈ᾰ́δηςΠηληιαδηςΠηληιαδης
TextExpectedActual
test_strip_tone:
PassedΠηληῐ̈ᾰ́δηςΠηληῐ̈ᾰδηςΠηληῐ̈ᾰδης
PassedᾹ̔́ͅδηςᾹ̔ͅδηςᾹ̔ͅδης
Passedμολὼν λαβέμολων λαβεμολων λαβε
circumflex → macron
Passedπᾶςπᾱςπᾱς
circumflexes on diphthongs should not
be replaced with macrons
Passedοἷαιοἱαιοἱαι
Passedγᾰλεοῦγᾰλεουγᾰλεου

local tests = require("Module:UnitTests")
local m_accent = require("Module:grc-accent")

local m_utilities = require("Module:grc-utilities")
local m_table = require("Module:table")
local tag = m_utilities.tag
local compose = mw.ustring.toNFC

function tests:check_mark_implied_length(example, expected)
	self:equals(
		tag(example),
		compose(m_accent.mark_implied_length(example)),
		compose(expected),
		{ display = tag }
	)
end

function tests:check_length_at(example, position, expected)
	self:equals(
		tag(example) .. " (" .. position .. " syllables from end)",
		m_accent.length_at(example, position),
		expected
	)
end

function tests:check_get_length(example, expected, is_noun)
	local lengths = {}
	local get_length = m_accent.get_length
	local tokens = m_utilities.tokenize(example)
	local token_count = #tokens
	local short_diphthong = is_noun
	for i, token in m_table.reverseIpairs(tokens) do
		if m_accent.contains_vowel(token) then
			if i ~= token_count then
				short_diphthong = false
			end
			table.insert(lengths, get_length(token, short_diphthong))
		end
	end
	lengths = m_table.reverseConcat(lengths, ", ")
	
	self:equals(
		tag(example),
		lengths,
		expected
	)
end

function tests:check_harmonize_length(word1, word2, expected)
	self:equals(
		tag(word1 .. ", " .. word2),
		compose(table.concat({ m_accent.harmonize_length(word1, word2) }, ", ")),
		compose(expected),
		{ display = tag }
	)
end

function tests:check_strip_accent(example, expected)
	self:equals(
		tag(example),
		compose(m_accent.strip_accent(example)),
		compose(expected),
		{ display = tag }
	)
end

function tests:check_strip_tone(example, expected)
	self:equals(
		tag(example),
		compose(m_accent.strip_tone(example)),
		compose(expected),
		{ display = tag }
	)
end

function tests:check_get_weight(example, expected, position)
	self:equals(
		tag(example) .. " (" .. position .. ")",
		m_accent.get_weight(example, position),
		expected
	)
	self:equals(
		tag(example),
		m_accent.get_weight(example),
		expected
	)
end

function tests:check_add_accent(example, position, expected, circumflex, is_noun)
	self:equals(
		tag(example) .. " (" .. m_table.sparseConcat({ position, circumflex and "circumflex" or nil, is_noun and "noun" or nil }, ", ") .. ")",
		compose(m_accent.add_accent(example, position, { short_diphthong = is_noun, synaeresis = is_noun, circumflex = circumflex })),
		compose(expected),
		{ display = tag }
	)
end

local function display_detect_accent(syllable, accent_name)
	return syllable .. ", " .. accent_name
end

function tests:check_detect_accent(example, expected, from_end)
	self:equals(
		tag(example) .. (from_end and " (from end)" or ""),
		display_detect_accent(m_accent.detect_accent(example, from_end)),
		expected
	)
end

function tests:check_get_accent_term(example, expected)
	self:equals(
		tag(example),
		m_accent.get_accent_term(example),
		expected
	)
end

function tests:test_mark_implied_length()
	local examples = {
		{ "μοῖρα", "μοῖρᾰ" },
		{ "χώρα", "χώρᾱ" },
		{ "πάθος", "πᾰ́θος" },
		{ "ἀλήθεια", "ἀλήθειᾰ" },
	}
	
	tests:iterate(examples, "check_mark_implied_length")
end

function tests:test_length_at()
	local examples = {
		{ "μοῖρα", 2, "long" },
		{ "πάθους", 2, "either" },
		{ "πᾰ́θος", 2, "short" },
	}
	
	tests:iterate(examples, "check_length_at")
end

function tests:test_get_length()
	local examples = {
		"ambiguous vowels",
		{ "αἷμᾰ", "long, short", true },
		{ "μοῖρα", "long, either" },
		{ "πάθος", "either, short" },
		{ "πᾰ́θος", "short, short" },
		{ "ἆρᾰ", "long, short" },
		"capital letters",
		{ "ᾍδης", "long, long" },
		{ "Αἰσχύλος", "long, either, short" },
		{ "Ἠλέκτρᾱ", "long, short, long" },
		{ "Ἑλλάς", "short, either" },
		"short final diphthongs",
		{ "ᾰ̓λήθειαι", "short, long, long, short", true },
		{ "Ᾰ̓θηναιοι", "short, long, long, short", true },
		{ "Ᾰ̓θηναίοιν", "short, long, long, long", true },
		{ "Ᾰ̓θηναίοις", "short, long, long, long", true },
	}
	
	tests:iterate(examples, "check_get_length")
end

function tests:test_harmonize_length()
	local examples = {
		{ "ᾰ̓́λοξ", "ἄλοκος", "ᾰ̓́λοξ, ᾰ̓́λοκος" },
		{ "ἄλοκος", "ᾰ̓́λοξ", "ᾰ̓́λοκος, ᾰ̓́λοξ" },
		{ "ἄλοξ", "ἄλοκος", "ᾰ̓́λοξ, ᾰ̓́λοκος" },
		{ "Αἰθίοψ", "Αἰθίοπος", "Αἰθῐ́οψ, Αἰθῐ́οπος" },
		"transfer length only if both vowels have the same breathing mark",
		{ "ἄξιος", "ᾱ", "ἄξιος, ᾱ" },
	}
	
	tests:iterate(examples, "check_harmonize_length")
end

function tests:test_strip_accent()
	local examples = {
		{ "ᾰ̓́νθρωπος", "ανθρωπος" },
		{ "Πηληῐ̈ᾰ́δης", "Πηληιαδης" },
		-- { },
	}
	
	tests:iterate(examples, "check_strip_accent")
end

function tests:test_strip_tone()
	local examples = {
		{ "Πηληῐ̈ᾰ́δης", "Πηληῐ̈ᾰδης" },
		{ "Ᾱ̔́ͅδης", "Ᾱ̔ͅδης" }, -- pleonastic
		{ "μολὼν λαβέ", "μολων λαβε" },
		"circumflex → macron",
		{ "πᾶς", "πᾱς" },
		"circumflexes on diphthongs should not<br>be replaced with macrons",
		{ "οἷαι", "οἱαι" }, -- οῑαι if tokenization yields ο-ῑαι
		{ "γᾰλεοῦ", "γᾰλεου" }, -- γᾰλεοῡ if tokenization yields γᾰλεο-ῦ
	}
	
	tests:iterate(examples, "check_strip_tone")
end

function tests:test_get_weight()
	local examples = {
		{ "ὀρθ", "heavy", 1 },
		{ "μικρ", "heavy", 1 },
		{ "ἰδι", nil, 1 },
		{ "ῐ̓δῐ", "light", 1 },
		{ "φῐλ", "light", 1 },
	}
	
	tests:iterate(examples, "check_get_weight")
end

function tests:test_add_accent()
	local examples = {
		{ "κρεως", 1, "κρέως", nil, true},
		{ "Τρως", 1, "Τρώς", nil, true },
		{ "πολεως", 1, "πόλεως", nil, true },
		{ "πολεων", 1, "πόλεων", nil, true },
		{ "Πειριθοι", 2, "Πειρίθοι", nil, true },
		{ "Ᾰ̓θηναιοιν", -2, "Ᾰ̓θηναίοιν", nil, true },
		{ "Ᾰ̓θηναιοις", -2, "Ᾰ̓θηναίοις", nil, true },
		{ "βᾰρειαι", -2, "βᾰρεῖαι", nil, true },
		{ "ᾰ̓ληθειαι", -3, "ᾰ̓λήθειαι", nil, true },
		{ "Ᾰ̓θηναιοι", 3, "Ᾰ̓θηναῖοι", nil, true },
		{ "βᾰρειαι", 2, "βᾰρεῖαι", nil, true },
		{ "ᾰ̓ληθειαι", 2, "ᾰ̓λήθειαι", nil, true },
		{ "αἱμᾰ", 1, "αἷμᾰ", nil, true },
		{ "λογος", -2, "λόγος" },
		{ "προτερᾱ", -3, "προτέρᾱ" },
		{ "Αἰθιοπων", 2, "Αἰθιόπων"}, -- position 2 because the nominative is Αἰθίοψ
		{ "χωρῶν", 1, "χωρῶν"}, -- don't modify existing accent
		{ "δημος", 1, "δῆμος" },
		{ "τοιουτος", 2, "τοιοῦτος" },
		{ "χωρᾱ", 1, "χώρᾱ" },
		{ "μοιρᾰ", 1, "μοῖρᾰ" },
		{ "προτερᾱ", 1, "προτέρᾱ" },
		{ "ἐγενετο", 1, "ἐγένετο" },
		{ "φως", 1, "φῶς", true },
		{ "μοιρα", 1, "μοίρα" },
		{ "μοιρα", 1, "μοῖρα", true },
		{ "ἐγενετο", 1, "ἐγένετο", true },
		{ "λογος", 1, "λόγος" },
		{ "λογος", 1, "λόγος", true },
	}
	
	tests:iterate(examples, "check_add_accent")
end

function tests:test_detect_accent()
	local examples = {
		{ "ἐγένετο",	"2, acute" },
		{ "ἐγένετο",	"3, acute", true },
		{ "τοιοῦτος",	"2, circumflex" },
		{ "τοιοῦτος",	"2, circumflex", true },
		{ "φῶς",		"1, circumflex" },
		{ "φῶς",		"1, circumflex", true },
	}
	
	tests:iterate(examples, "check_detect_accent")
end

function tests:test_get_accent_term()
	local examples = {
		{ "πολὺς", "barytone" },
		{ "πολύς", "oxytone" },
		{ "λέγω", "paroxytone" },
		{ "γίγνομαι", "proparoxytone" },
		{ "φῶς", "perispomenon" },
		{ "οἷος", "properispomenon" },
	}
	
	tests:iterate(examples, "check_get_accent_term")
end

return tests