Module:grc-accent/sandbox/testcases

Definition from Wiktionary, the free dictionary
Jump to navigation Jump to search

All tests passed. (refresh)

Text Expected Actual
test_add_accent:
Passed ἀετως (-3, noun) ἀέτως ἀέτως
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) λόγος λόγος
Text Expected Actual
test_detect_accent:
Passed ἐγένετο 2, acute 2, acute
Passed ἐγένετο (from end) 3, acute 3, acute
Passed τοιοῦτος 2, circumflex 2, circumflex
Passed τοιοῦτος (from end) 2, circumflex 2, circumflex
Passed φῶς 1, circumflex 1, circumflex
Passed φῶς (from end) 1, circumflex 1, circumflex
Text Expected Actual
test_get_accent_term:
Passed πολὺς barytone barytone
Passed πολύς oxytone oxytone
Passed λέγω paroxytone paroxytone
Passed γίγνομαι proparoxytone proparoxytone
Passed φῶς perispomenon perispomenon
Passed οἷος properispomenon properispomenon
Text Expected Actual
test_get_length:
Passed ᾰ̓λήθειαι short, long, long, short short, long, long, short
Passed Ᾰ̓θηναιοι short, long, long, short short, long, long, short
Passed Ᾰ̓θηναίοιν short, long, long, long short, long, long, long
Passed Ᾰ̓θηναίοις short, long, long, long short, long, long, long
Passed αἷμᾰ long, short long, short
Passed μοῖρα long, either long, either
Passed πάθος either, short either, short
Passed πᾰ́θος short, short short, short
Passed ἆρᾰ long, short long, short
Passed ᾍδης long, long long, long
Passed Αἰσχύλος long, either, short long, either, short
Passed Ἠλέκτρᾱ long, short, long long, short, long
Passed Ἑλλάς short, either short, either
Text Expected Actual
test_get_weight:
Passed ὀρθ (1) heavy heavy
Passed ὀρθ heavy heavy
Passed μικρ (1) heavy heavy
Passed μικρ heavy heavy
Passed ἰδι (1) (nil) (nil)
Passed ἰδι (nil) (nil)
Passed ῐ̓δῐ (1) light light
Passed ῐ̓δῐ light light
Passed φῐλ (1) light light
Passed φῐλ light light
Text Expected Actual
test_harmonize_length:
Passed ᾰ̓́λοξ, ἄλοκος ᾰ̓́λοξ, ᾰ̓́λοκος ᾰ̓́λοξ, ᾰ̓́λοκος
Passed ἄλοκος, ᾰ̓́λοξ ᾰ̓́λοκος, ᾰ̓́λοξ ᾰ̓́λοκος, ᾰ̓́λοξ
Passed ἄλοξ, ἄλοκος ᾰ̓́λοξ, ᾰ̓́λοκος ᾰ̓́λοξ, ᾰ̓́λοκος
Passed Αἰθίοψ, Αἰθίοπος Αἰθῐ́οψ, Αἰθῐ́οπος Αἰθῐ́οψ, Αἰθῐ́οπος
Passed ἄξιος, ᾱ ἄξιος, ᾱ ἄξιος, ᾱ
Text Expected Actual
test_length_at:
Passed μοῖρα (2) long long
Passed πάθους (2) either either
Passed πᾰ́θος (2) short short
Text Expected Actual
test_mark_implied_length:
Passed μοῖρα μοῖρᾰ μοῖρᾰ
Passed χώρα χώρᾱ χώρᾱ
Passed πάθος πᾰ́θος πᾰ́θος
Passed ἀλήθεια ἀλήθειᾰ ἀλήθειᾰ
Text Expected Actual
test_strip_accent:
Passed ᾰ̓́νθρωπος ανθρωπος ανθρωπος
Passed Πηληῐ̈ᾰ́δης Πηληιαδης Πηληιαδης
Text Expected Actual
test_strip_tone:
Passed Πηληῐ̈ᾰ́δης Πηληῐ̈ᾰδης Πηληῐ̈ᾰδης
Passed Ᾱ̔́ͅδης Ᾱ̔ͅδης Ᾱ̔ͅδης
Passed πᾶς πᾱς πᾱς
Passed μολὼν λαβέ μολων λαβε μολων λαβε

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

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

local tag = m_utilities.tag

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 .. ")",
		m_accent.length_at(example, position),
		expected
	)
end

function tests:check_get_length(example, expected, is_noun)
	local lengths = {}
	local vowel_i = 1
	local get_length = m_accent.get_length
	for i, token in m_table.reverseIpairs(m_utilities.tokenize(example)) do
		if m_accent.contains_vowel(token) then
			if vowel_i ~= 1 then
				is_noun = false
			end
			table.insert(lengths, get_length(token, is_noun))
			vowel_i = vowel_i + 1
		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, { synaeresis = is_noun, short_diphthong = 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 = {
		{ "ᾰ̓λήθειαι", "short, long, long, short", true },
		{ "Ᾰ̓θηναιοι", "short, long, long, short", true },
		{ "Ᾰ̓θηναίοιν", "short, long, long, long" },
		{ "Ᾰ̓θηναίοις", "short, long, long, long" },
		{ "αἷμᾰ", "long, short", true },
		{ "μοῖρα", "long, either" },
		{ "πάθος", "either, short" },
		{ "πᾰ́θος", "short, short" },
		{ "ἆρᾰ", "long, short" },
		{ "ᾍδης", "long, long" },
		{ "Αἰσχύλος", "long, either, short" },
		{ "Ἠλέκτρᾱ", "long, short, long" },
		{ "Ἑλλάς", "short, either" },
	}
	
	tests:iterate(examples, "check_get_length")
end

function tests:test_harmonize_length()
	local examples = {
		{ "ᾰ̓́λοξ", "ἄλοκος", "ᾰ̓́λοξ, ᾰ̓́λοκος" },
		{ "ἄλοκος", "ᾰ̓́λοξ", "ᾰ̓́λοκος, ᾰ̓́λοξ" },
		{ "ἄλοξ", "ἄλοκος", "ᾰ̓́λοξ, ᾰ̓́λοκος" },
		{ "Αἰθίοψ", "Αἰθίοπος", "Αἰθῐ́οψ, Αἰθῐ́οπος" },
		{ "ἄξιος", "ᾱ", "ἄξιος, ᾱ" },
	}
	
	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
		{ "πᾶς", "πᾱς" },
		{ "μολὼν λαβέ", "μολων λαβε" },
	}
	
	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 = {
		{ "ἀετως", -3, "ἀέτως", nil, true },
		{ "κρεως", 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