summaryrefslogtreecommitdiff
path: root/internal/calendar/precedence_test.go
blob: 6d9dc151a76747f3a3f8257bbc406d907eb8fc14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package calendar

import "testing"

func tempCand(rank Rank, class Class, priv bool, s Season) candidate {
	return candidate{Cel: Celebration{Rank: rank, Class: class}, Temporal: true, Privileged: priv, Season: s}
}
func saintCand(rank Rank, class Class) candidate {
	return candidate{Cel: Celebration{Rank: rank, Class: class}, Temporal: false, Season: Ordinary}
}

func TestPrecedenceBands(t *testing.T) {
	sundayLent := tempCand(RankSolemnity, ClassNone, true, Lent)
	genSolemnity := saintCand(RankSolemnity, ClassSaint)
	genFeast := saintCand(RankFeast, ClassSaint)
	genMemorial := saintCand(RankMemorial, ClassSaint)
	// A Sunday of Lent is band 2; a general solemnity is band 3 → the Sunday wins.
	if !(precedence(sundayLent) < precedence(genSolemnity)) {
		t.Error("Sunday of Lent (band 2) must outrank a general solemnity (band 3)")
	}
	if !(precedence(genSolemnity) < precedence(genFeast) && precedence(genFeast) < precedence(genMemorial)) {
		t.Error("solemnity > feast > memorial ordering broken")
	}
}

func TestPick(t *testing.T) {
	sunday := tempCand(RankSolemnity, ClassNone, true, Ordinary)
	memorial := saintCand(RankMemorial, ClassSaint)
	obs, others := pick([]candidate{memorial, sunday})
	if obs.Cel.Rank != RankSolemnity || !obs.Temporal {
		t.Errorf("Sunday must win, got %+v", obs.Cel)
	}
	if len(others) != 1 || others[0].Cel.Rank != RankMemorial {
		t.Errorf("memorial should be a commemoration, got %+v", others)
	}
}