test(kinship): separate tests by language

Signed-off-by: Arc676/Alessandro Vinciguerra <alesvinciguerra@gmail.com>
This commit is contained in:
Arc676/Alessandro Vinciguerra committed 2026-11-11 21:48:00 +01:00
1 parent f8d1a48240
commit af3a388db8
2 files changed
+41 -37

No files matched your search

@@ -0,0 +1,40 @@
import { describe, it, expect } from 'vitest'
import { nameKinship } from './index.js'
import { path } from './kinship.fr.test.js'
const both = (moves) => ['male', 'female', null].map((sex) => nameKinship(path(moves, sex), 'en'))
describe('nommage anglais', () => {
it('genre le mot quand le sexe est connu', () => {
expect(both(['up'])).toEqual(['Father', 'Mother', 'Parent'])
expect(both(['up', 'up'])).toEqual(['Grandfather', 'Grandmother', 'Grandparent'])
expect(both(['up', 'up', 'up', 'up'])).toEqual(['Great-great-grandfather', 'Great-great-grandmother', 'Great-great-grandparent'])
expect(both(['down', 'down'])).toEqual(['Grandson', 'Granddaughter', 'Grandchild'])
expect(both(['sibling'])).toEqual(['Brother', 'Sister', 'Sibling'])
expect(both(['up', 'sibling'])).toEqual(['Uncle', 'Aunt', 'Uncle/Aunt'])
expect(both(['sibling', 'down'])).toEqual(['Nephew', 'Niece', 'Nibling'])
expect(both(['spouse', 'up'])).toEqual(['Father-in-law', 'Mother-in-law', 'Parent-in-law'])
expect(both(['up', 'spouse'])).toEqual(['Stepfather', 'Stepmother', 'Stepparent'])
expect(both(['spouse', 'down'])).toEqual(['Stepson', 'Stepdaughter', 'Stepchild'])
expect(both(['down', 'spouse'])).toEqual(['Son-in-law', 'Daughter-in-law', 'Child-in-law'])
expect(both(['spouse', 'sibling'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law'])
expect(both(['sibling', 'spouse'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law'])
expect(both(['up', 'spouse', 'down'])).toEqual(['Stepbrother', 'Stepsister', 'Stepsibling'])
expect(both(['up', 'down'])).toEqual(['Half-brother', 'Half-sister', 'Half-sibling'])
expect(both(['spouse'])).toEqual(['Partner', 'Partner', 'Partner'])
expect(both(['up', 'sibling', 'down'])).toEqual(['First cousin', 'First cousin', 'First cousin'])
expect(both(['up', 'up', 'sibling', 'down', 'down'])).toEqual(['Second cousin', 'Second cousin', 'Second cousin'])
expect(both(['up', 'up', 'sibling', 'down'])).toEqual(['First cousin once removed', 'First cousin once removed', 'First cousin once removed'])
expect(both(['up', 'up', 'up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down'])).toEqual(['Third cousin thrice removed', 'Third cousin thrice removed', 'Third cousin thrice removed'])
expect(both(['up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin twice removed', 'First cousin twice removed', 'First cousin twice removed'])
expect(both(['up', 'up', 'up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin 4 times removed', 'First cousin 4 times removed', 'First cousin 4 times removed'])
expect(both(['up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down', 'down'])).toEqual(['4th cousin', '4th cousin', '4th cousin'])
expect(both(['up', 'up', 'sibling'])).toEqual(['Great-uncle', 'Great-aunt', 'Great-uncle/aunt'])
expect(both(['up', 'up', 'up', 'sibling'])).toEqual(['Great-great-uncle', 'Great-great-aunt', 'Great-great-uncle/aunt'])
expect(both(['sibling', 'down', 'down'])).toEqual(['Grandnephew', 'Grandniece', 'Grandnibling'])
})
it('une langue inconnue retombe sur l’anglais', () => {
expect(nameKinship(path(['up'], 'female'), 'xx')).toBe('Mother')
})
})
@@ -3,13 +3,12 @@ import { kinshipFacts, nameKinship, normalizeSex } from './index.js'
import { computeRelationshipLabel, kinshipPath } from '../../components/galaxy/pathfinding.js'
// Chemin écrit à la main : moves = suite de pas, sex = sexe de la personne au bout
const path = (moves, sex = null, extra = {}) => ({
export const path = (moves, sex = null, extra = {}) => ({
from: { id: 'moi', sex: null, birthYear: null },
steps: moves.map((move, i) => ({ move, person: { id: `p${i}`, sex: i === moves.length - 1 ? sex : null, birthYear: null, ...(extra[i] || {}) } })),
})
const both = (moves) => ['male', 'female', null].map((sex) => nameKinship(path(moves, sex), 'fr'))
const bothEn = (moves) => ['male', 'female', null].map((sex) => nameKinship(path(moves, sex), 'en'))
describe('nommage français', () => {
it('genre le mot quand le sexe est connu, garde la forme double sinon', () => {
@@ -59,41 +58,6 @@ describe('nommage français', () => {
})
})
describe('nommage anglais', () => {
it('genre le mot quand le sexe est connu', () => {
expect(bothEn(['up'])).toEqual(['Father', 'Mother', 'Parent'])
expect(bothEn(['up', 'up'])).toEqual(['Grandfather', 'Grandmother', 'Grandparent'])
expect(bothEn(['up', 'up', 'up', 'up'])).toEqual(['Great-great-grandfather', 'Great-great-grandmother', 'Great-great-grandparent'])
expect(bothEn(['down', 'down'])).toEqual(['Grandson', 'Granddaughter', 'Grandchild'])
expect(bothEn(['sibling'])).toEqual(['Brother', 'Sister', 'Sibling'])
expect(bothEn(['up', 'sibling'])).toEqual(['Uncle', 'Aunt', 'Uncle/Aunt'])
expect(bothEn(['sibling', 'down'])).toEqual(['Nephew', 'Niece', 'Nibling'])
expect(bothEn(['spouse', 'up'])).toEqual(['Father-in-law', 'Mother-in-law', 'Parent-in-law'])
expect(bothEn(['up', 'spouse'])).toEqual(['Stepfather', 'Stepmother', 'Stepparent'])
expect(bothEn(['spouse', 'down'])).toEqual(['Stepson', 'Stepdaughter', 'Stepchild'])
expect(bothEn(['down', 'spouse'])).toEqual(['Son-in-law', 'Daughter-in-law', 'Child-in-law'])
expect(bothEn(['spouse', 'sibling'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law'])
expect(bothEn(['sibling', 'spouse'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law'])
expect(bothEn(['up', 'spouse', 'down'])).toEqual(['Stepbrother', 'Stepsister', 'Stepsibling'])
expect(bothEn(['up', 'down'])).toEqual(['Half-brother', 'Half-sister', 'Half-sibling'])
expect(bothEn(['spouse'])).toEqual(['Partner', 'Partner', 'Partner'])
expect(bothEn(['up', 'sibling', 'down'])).toEqual(['First cousin', 'First cousin', 'First cousin'])
expect(bothEn(['up', 'up', 'sibling', 'down', 'down'])).toEqual(['Second cousin', 'Second cousin', 'Second cousin'])
expect(bothEn(['up', 'up', 'sibling', 'down'])).toEqual(['First cousin once removed', 'First cousin once removed', 'First cousin once removed'])
expect(bothEn(['up', 'up', 'up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down'])).toEqual(['Third cousin thrice removed', 'Third cousin thrice removed', 'Third cousin thrice removed'])
expect(bothEn(['up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin twice removed', 'First cousin twice removed', 'First cousin twice removed'])
expect(bothEn(['up', 'up', 'up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin 4 times removed', 'First cousin 4 times removed', 'First cousin 4 times removed'])
expect(bothEn(['up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down', 'down'])).toEqual(['4th cousin', '4th cousin', '4th cousin'])
expect(bothEn(['up', 'up', 'sibling'])).toEqual(['Great-uncle', 'Great-aunt', 'Great-uncle/aunt'])
expect(bothEn(['up', 'up', 'up', 'sibling'])).toEqual(['Great-great-uncle', 'Great-great-aunt', 'Great-great-uncle/aunt'])
expect(bothEn(['sibling', 'down', 'down'])).toEqual(['Grandnephew', 'Grandniece', 'Grandnibling'])
})
it('une langue inconnue retombe sur l’anglais', () => {
expect(nameKinship(path(['up'], 'female'), 'xx')).toBe('Mother')
})
})
describe('chemin de parenté depuis le chemin BFS', () => {
// moi → union de mes parents → mon père → union des grands-parents → ma tante
const edgePath = [