Merge branch 'cursor/activity-level-65da' into 'master'
fix: kleur de activiteitenkalender met de GitLab-grenzen See merge request Timfa/bluegit!53
@@ -37,16 +37,17 @@ func Location() *time.Location {
37
37
return loc
38
38
}
39
39
40
// Level zet een aantal om in 0..4. Vijf tinten, waarvan de eerste leeg is.
40
// Level zet een aantal om in 0..4, met de grenzen van GitLab:
41
// 0, 1-9, 10-19, 20-29 en 30 of meer.
41
42
func Level(n int) int {
42
43
switch {
43
44
case n <= 0:
44
45
return 0
45
case n == 1:
46
case n < 10:
46
47
return 1
47
case n <= 3:
48
case n < 20:
48
49
return 2
49
case n <= 6:
50
case n < 30:
50
51
return 3
51
52
default:
52
53
return 4
@@ -37,16 +37,17 @@ func Location() *time.Location {37
return loc37
return loc38
}38
}39
39
40
// Level zet een aantal om in 0..4. Vijf tinten, waarvan de eerste leeg is.40
// Level zet een aantal om in 0..4, met de grenzen van GitLab:41
// 0, 1-9, 10-19, 20-29 en 30 of meer.41
func Level(n int) int {42
func Level(n int) int {42
switch {43
switch {43
case n <= 0:44
case n <= 0:44
return 045
return 045
case n == 1:46
case n < 10:46
return 147
return 147
case n <= 3:48
case n < 20:48
return 249
return 249
case n <= 6:50
case n < 30:50
return 351
return 351
default:52
default:52
return 453
return 4@@ -9,7 +9,13 @@ import (
9
9
)
10
10
11
11
func TestLevel(t *testing.T) {
12
cases := []struct{ n, want int }{{0, 0}, {1, 1}, {2, 2}, {3, 2}, {4, 3}, {6, 3}, {7, 4}, {40, 4}}
12
cases := []struct{ n, want int }{
13
{-1, 0}, {0, 0},
14
{1, 1}, {9, 1},
15
{10, 2}, {19, 2},
16
{20, 3}, {29, 3},
17
{30, 4}, {40, 4},
18
}
13
19
for _, c := range cases {
14
20
if got := Level(c.n); got != c.want {
15
21
t.Fatalf("level %d = %d, wil %d", c.n, got, c.want)
@@ -46,7 +52,7 @@ func TestBuildYearGrid(t *testing.T) {
46
52
if len(last.Days) != 4 {
47
53
t.Fatalf("laatste week heeft %d dagen", len(last.Days))
48
54
}
49
if last.Days[2].Level != 3 || last.Days[2].Tip != "4 contributions on 20 October 2026" {
55
if last.Days[2].Level != 1 || last.Days[2].Tip != "4 contributions on 20 October 2026" {
50
56
t.Fatalf("dinsdag %+v", last.Days[2])
51
57
}
52
58
if last.Days[3].Level != 1 || !strings.Contains(last.Days[3].Tip, "1 contribution on 21 October 2026") {
@@ -9,7 +9,13 @@ import (9
)9
)10
10
11
func TestLevel(t *testing.T) {11
func TestLevel(t *testing.T) {12
cases := []struct{ n, want int }{{0, 0}, {1, 1}, {2, 2}, {3, 2}, {4, 3}, {6, 3}, {7, 4}, {40, 4}}12
cases := []struct{ n, want int }{13
{-1, 0}, {0, 0},14
{1, 1}, {9, 1},15
{10, 2}, {19, 2},16
{20, 3}, {29, 3},17
{30, 4}, {40, 4},18
}13
for _, c := range cases {19
for _, c := range cases {14
if got := Level(c.n); got != c.want {20
if got := Level(c.n); got != c.want {15
t.Fatalf("level %d = %d, wil %d", c.n, got, c.want)21
t.Fatalf("level %d = %d, wil %d", c.n, got, c.want)@@ -46,7 +52,7 @@ func TestBuildYearGrid(t *testing.T) {46
if len(last.Days) != 4 {52
if len(last.Days) != 4 {47
t.Fatalf("laatste week heeft %d dagen", len(last.Days))53
t.Fatalf("laatste week heeft %d dagen", len(last.Days))48
}54
}49
if last.Days[2].Level != 3 || last.Days[2].Tip != "4 contributions on 20 October 2026" {55
if last.Days[2].Level != 1 || last.Days[2].Tip != "4 contributions on 20 October 2026" {50
t.Fatalf("dinsdag %+v", last.Days[2])56
t.Fatalf("dinsdag %+v", last.Days[2])51
}57
}52
if last.Days[3].Level != 1 || !strings.Contains(last.Days[3].Tip, "1 contribution on 21 October 2026") {58
if last.Days[3].Level != 1 || !strings.Contains(last.Days[3].Tip, "1 contribution on 21 October 2026") {