package report

import "testing"

func TestLineFormat(t *testing.T) {
	cases := []struct {
		label  string
		filled int64
		total  int64
		want   string
	}{
		{"Images", 97000, 100000, "Images : 97.000/100.000 (97%)"},
		{"Description", 95000, 100000, "Description : 95.000/100.000 (95%)"},
		{"Related KW", 99800, 100000, "Related KW : 99.800/100.000 (99.8%)"},
		{"AI Title", 99800, 100000, "AI Title : 99.800/100.000 (99.8%)"},
		{"AI Articles", 100000, 100000, "AI Articles : 100.000/100.000 (100%)"},
		{"Images", 950, 1000, "Images : 950/1.000 (95%)"},
		{"Images", 0, 0, "Images : 0/0 (0%)"},
	}
	for _, c := range cases {
		if got := Line(c.label, c.filled, c.total); got != c.want {
			t.Errorf("Line(%q,%d,%d) = %q, want %q", c.label, c.filled, c.total, got, c.want)
		}
	}
}

func TestFoldersLine(t *testing.T) {
	if got := Folders(50); got != "Export : 50 Folder" {
		t.Errorf("Folders(50) = %q", got)
	}
}

func TestOutcomeLine(t *testing.T) {
	if got := Outcome("Upload", 49, 1); got != "Upload : SUCCESS 49, FAIL 1" {
		t.Errorf("Outcome = %q", got)
	}
	if got := Outcome("Submit", 47, 3); got != "Submit : SUCCESS 47, FAIL 3" {
		t.Errorf("Outcome = %q", got)
	}
}

func TestDotThousands(t *testing.T) {
	cases := map[int64]string{
		0: "0", 7: "7", 950: "950", 1000: "1.000",
		97000: "97.000", 100000: "100.000", 1234567: "1.234.567",
	}
	for n, want := range cases {
		if got := dot(n); got != want {
			t.Errorf("dot(%d) = %q, want %q", n, got, want)
		}
	}
}

func TestPercent(t *testing.T) {
	cases := []struct {
		filled, total int64
		want          string
	}{
		{97000, 100000, "97"},
		{99800, 100000, "99.8"},
		{100000, 100000, "100"},
		{0, 100000, "0"},
		{0, 0, "0"},
	}
	for _, c := range cases {
		if got := percent(c.filled, c.total); got != c.want {
			t.Errorf("percent(%d,%d) = %q, want %q", c.filled, c.total, got, c.want)
		}
	}
}
