aboutsummaryrefslogtreecommitdiff
path: root/internal/mainsa/date_test.go
blob: 0d5c5d837b657ed083844936c2f1feb8026cd398 (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package mainsa

import (
	"testing"
	"time"
)

func TestSuliLen(t *testing.T) {
	if suliLen != sunosInSuli*sunoLen {
		t.Fatalf("expected a year to be %d sunos, got: %d sunos", sunosInSuli, suliLen/sunoLen)
	}

	t.Logf("%d sunos in linja", sunosInLinja)
	t.Logf("%d sunos in sike", sunosInSike)
	t.Logf("%d sunos in tawa", sunosInTawa)
	t.Logf("%d sunos in suli", sunosInSuli)
}

func TestAt(t *testing.T) {
	cases := []struct {
		name    string
		inp     time.Time
		wantErr bool
		outp    TenpoNimi
	}{
		{
			name:    "before",
			inp:     YearZero.Add(-1 * time.Hour),
			wantErr: true,
		},
		{
			name: "second_day",
			inp:  YearZero.Add(sunoLen),
			outp: TenpoNimi{
				Year:      0,
				Season:    Kasi,
				Month:     Kama,
				Week:      Wan,
				Day:       Tu,
				Remainder: time.Duration(0),
			},
		},
	}

	for _, cs := range cases {
		t.Run(cs.name, func(t *testing.T) {
			tn, err := At(cs.inp)
			if err != nil && !cs.wantErr {
				t.Fatal(err)
			}

			if cs.wantErr && err == nil {
				t.Fatal("wanted an error but got none")
			}

			if cs.wantErr {
				return
			}

			cts := cs.outp.String()
			tts := tn.String()
			t.Logf("expected: %s", cts)
			t.Logf("got:      %s", tts)
			if cts != tts {
				t.Fatal("see -v")
			}
		})
	}
}