|
| 1 | +package statistics |
| 2 | + |
| 3 | +import ( |
| 4 | + "strconv" |
| 5 | + "testing" |
| 6 | +) |
| 7 | + |
| 8 | +// --- weekdays slice --- |
| 9 | + |
| 10 | +func TestWeekdays_HasSevenEntries(t *testing.T) { |
| 11 | + if len(weekdays) != 7 { |
| 12 | + t.Errorf("expected 7 weekdays, got %d", len(weekdays)) |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +func TestWeekdays_StartsWithSunday(t *testing.T) { |
| 17 | + // SQLite strftime('%w') returns 0 for Sunday |
| 18 | + if weekdays[0] != "Sunday" { |
| 19 | + t.Errorf("expected weekdays[0]='Sunday', got '%s'", weekdays[0]) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +func TestWeekdays_EndsWithSaturday(t *testing.T) { |
| 24 | + if weekdays[6] != "Saturday" { |
| 25 | + t.Errorf("expected weekdays[6]='Saturday', got '%s'", weekdays[6]) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +func TestWeekdays_AllDaysPresent(t *testing.T) { |
| 30 | + expected := []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} |
| 31 | + for i, want := range expected { |
| 32 | + if weekdays[i] != want { |
| 33 | + t.Errorf("weekdays[%d]: expected '%s', got '%s'", i, want, weekdays[i]) |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +// --- months slice --- |
| 39 | + |
| 40 | +func TestMonths_HasTwelveEntries(t *testing.T) { |
| 41 | + if len(months) != 12 { |
| 42 | + t.Errorf("expected 12 months, got %d", len(months)) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +func TestMonths_StartsWithJanuary(t *testing.T) { |
| 47 | + // SQLite strftime('%m') returns "01" for January → index months[0] |
| 48 | + if months[0] != "January" { |
| 49 | + t.Errorf("expected months[0]='January', got '%s'", months[0]) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +func TestMonths_EndsWithDecember(t *testing.T) { |
| 54 | + if months[11] != "December" { |
| 55 | + t.Errorf("expected months[11]='December', got '%s'", months[11]) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func TestMonths_AllMonthsPresent(t *testing.T) { |
| 60 | + expected := []string{ |
| 61 | + "January", "February", "March", "April", "May", "June", |
| 62 | + "July", "August", "September", "October", "November", "December", |
| 63 | + } |
| 64 | + for i, want := range expected { |
| 65 | + if months[i] != want { |
| 66 | + t.Errorf("months[%d]: expected '%s', got '%s'", i, want, months[i]) |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +// --- Month index mapping (strftime returns 1-based "01".."12") --- |
| 72 | + |
| 73 | +func TestMonths_IndexMapping_StrftimeValue01_IsJanuary(t *testing.T) { |
| 74 | + // Simulates the code: val, _ := strconv.Atoi("01"); months[val-1] |
| 75 | + val, _ := strconv.Atoi("01") |
| 76 | + if months[val-1] != "January" { |
| 77 | + t.Errorf("strftime '01' → expected 'January', got '%s'", months[val-1]) |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +func TestMonths_IndexMapping_StrftimeValue12_IsDecember(t *testing.T) { |
| 82 | + val, _ := strconv.Atoi("12") |
| 83 | + if months[val-1] != "December" { |
| 84 | + t.Errorf("strftime '12' → expected 'December', got '%s'", months[val-1]) |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +func TestMonths_IndexMapping_StrftimeValue06_IsJune(t *testing.T) { |
| 89 | + val, _ := strconv.Atoi("06") |
| 90 | + if months[val-1] != "June" { |
| 91 | + t.Errorf("strftime '06' → expected 'June', got '%s'", months[val-1]) |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +// --- TimeStatistic structs (DAY, MONTH, YEAR) --- |
| 96 | + |
| 97 | +func TestTimeStatistic_DAY_HasCorrectLabel(t *testing.T) { |
| 98 | + if DAY.label != "Weekday" { |
| 99 | + t.Errorf("expected DAY.label='Weekday', got '%s'", DAY.label) |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +func TestTimeStatistic_DAY_HasCorrectFormat(t *testing.T) { |
| 104 | + if DAY.format != "%w" { |
| 105 | + t.Errorf("expected DAY.format='%%w', got '%s'", DAY.format) |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +func TestTimeStatistic_MONTH_HasCorrectLabel(t *testing.T) { |
| 110 | + if MONTH.label != "Month" { |
| 111 | + t.Errorf("expected MONTH.label='Month', got '%s'", MONTH.label) |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +func TestTimeStatistic_MONTH_HasCorrectFormat(t *testing.T) { |
| 116 | + if MONTH.format != "%m %Y" { |
| 117 | + t.Errorf("expected MONTH.format='%%m %%Y', got '%s'", MONTH.format) |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +func TestTimeStatistic_YEAR_HasCorrectLabel(t *testing.T) { |
| 122 | + if YEAR.label != "Year" { |
| 123 | + t.Errorf("expected YEAR.label='Year', got '%s'", YEAR.label) |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +func TestTimeStatistic_YEAR_HasCorrectFormat(t *testing.T) { |
| 128 | + if YEAR.format != "%Y" { |
| 129 | + t.Errorf("expected YEAR.format='%%Y', got '%s'", YEAR.format) |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +// --- Weekday index mapping (strftime '%w' returns "0".."6") --- |
| 134 | + |
| 135 | +func TestWeekdays_IndexMapping_StrftimeValue0_IsSunday(t *testing.T) { |
| 136 | + val, _ := strconv.Atoi("0") |
| 137 | + if weekdays[val] != "Sunday" { |
| 138 | + t.Errorf("strftime '0' → expected 'Sunday', got '%s'", weekdays[val]) |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +func TestWeekdays_IndexMapping_StrftimeValue6_IsSaturday(t *testing.T) { |
| 143 | + val, _ := strconv.Atoi("6") |
| 144 | + if weekdays[val] != "Saturday" { |
| 145 | + t.Errorf("strftime '6' → expected 'Saturday', got '%s'", weekdays[val]) |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | +func TestWeekdays_IndexMapping_StrftimeValue3_IsWednesday(t *testing.T) { |
| 150 | + val, _ := strconv.Atoi("3") |
| 151 | + if weekdays[val] != "Wednesday" { |
| 152 | + t.Errorf("strftime '3' → expected 'Wednesday', got '%s'", weekdays[val]) |
| 153 | + } |
| 154 | +} |
0 commit comments