Module:User:Erutuon/grc-accent/sandbox/testcases

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

Module error: No such module "grc-accent/sandbox/testcases".

Lua error in Module:module_categorization at line 298: Could not infer any languages or scripts from root pagename 'User:Erutuon'


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