package main

import (
	"testing"
	"time"
)

func TestSM2(t *testing.T) {
	ts := time.Date(2000, 1, 1, 0, 0, 0, 0, time.Local)
	cases := map[string]struct {
		history []int
		want    int
	}{
		"never before and no attempts": {
			history: nil,
			want:    1,
		},
		"0": {
			history: []int{3, 3, 3, 0},
			want:    1,
		},
		"1": {
			history: []int{3, 3, 0, 3},
			want:    1,
		},
		"2": {
			history: []int{3, 0, 3, 3},
			want:    6,
		},
		"3": {
			history: []int{0, 3, 3, 3},
			want:    8,
		},
		"4": {
			history: []int{3, 3, 3, 3},
			want:    27,
		},
		"5": {
			history: []int{3, 3, 3, 3, 3},
			want:    52,
		},
	}

	for name, d := range cases {
		c := d
		t.Run(name, func(t *testing.T) {
			got := SM2Next(ts, c.history, time.Hour*24)
			t.Logf("Next(\n\t%s, \n\t%+v) = \n\t%s", ts, c.history, got)
			if got != ts.Add(time.Duration(c.want)*time.Hour*24) {
				t.Error(c.want, got)
			}
		})
	}
}
