TestSpec_PublicAPI_ComputeObjectiveValue validates the documented behavior of ComputeObjectiveValue. Per the README it "calculates the numeric value for an issue based on its labels; returns 0 if no labels match or if the receiver is nil". Multi-label combination follows MultiLabelLogic ("max" defau
(t *testing.T)
| 92 | // Tests construct explicit mappings so they validate documented behavior rather |
| 93 | // than the contents of the built-in default mapping. |
| 94 | func TestSpec_PublicAPI_ComputeObjectiveValue(t *testing.T) { |
| 95 | // Mapping mirroring the README constants table for the relevant labels. |
| 96 | mapping := func(logic string, priorities ...string) *github.ObjectiveMapping { |
| 97 | return &github.ObjectiveMapping{ |
| 98 | // Values mirror the README constants table: bug=60, high-priority=35. |
| 99 | LabelToValue: map[string]int{ |
| 100 | "bug": github.ObjectiveValueBug, |
| 101 | "high-priority": github.ObjectiveValueHighPriority, |
| 102 | "documentation": github.ObjectiveValueDocumentation, |
| 103 | }, |
| 104 | MultiLabelLogic: logic, |
| 105 | PriorityLabels: priorities, |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | t.Run("max logic returns highest matching value (documented default)", func(t *testing.T) { |
| 110 | // README example: max of bug=60, high-priority=35 -> 60. |
| 111 | got := mapping(github.MultiLabelLogicMax).ComputeObjectiveValue([]string{"bug", "high-priority"}) |
| 112 | assert.Equal(t, 60, got, "max logic should return the highest matching value") |
| 113 | }) |
| 114 | |
| 115 | t.Run("empty MultiLabelLogic defaults to max", func(t *testing.T) { |
| 116 | got := mapping("").ComputeObjectiveValue([]string{"bug", "high-priority"}) |
| 117 | assert.Equal(t, 60, got, "empty MultiLabelLogic should behave as \"max\"") |
| 118 | }) |
| 119 | |
| 120 | t.Run("sum logic adds all matching values", func(t *testing.T) { |
| 121 | got := mapping(github.MultiLabelLogicSum).ComputeObjectiveValue([]string{"bug", "high-priority"}) |
| 122 | assert.Equal(t, 95, got, "sum logic should add matching values (60+35)") |
| 123 | }) |
| 124 | |
| 125 | t.Run("first logic uses the first prioritized match", func(t *testing.T) { |
| 126 | // SPEC_AMBIGUITY: The README describes "first" as "use the first match in |
| 127 | // priority order", but does not specify whether ordering is driven by the |
| 128 | // issue-label order or the PriorityLabels order when the two disagree. To |
| 129 | // keep this test unambiguous, the issue-label order and PriorityLabels |
| 130 | // order are aligned so both interpretations yield the same result. |
| 131 | got := mapping(github.MultiLabelLogicFirst, "high-priority", "bug"). |
| 132 | ComputeObjectiveValue([]string{"high-priority", "bug"}) |
| 133 | assert.Equal(t, 35, got, "first logic should resolve to the leading prioritized label") |
| 134 | }) |
| 135 | |
| 136 | t.Run("nil receiver returns 0", func(t *testing.T) { |
| 137 | var om *github.ObjectiveMapping |
| 138 | assert.Equal(t, 0, om.ComputeObjectiveValue([]string{"bug"}), |
| 139 | "nil receiver should return 0") |
| 140 | }) |
| 141 | |
| 142 | t.Run("no matching labels returns 0", func(t *testing.T) { |
| 143 | got := mapping(github.MultiLabelLogicMax).ComputeObjectiveValue([]string{"nonexistent"}) |
| 144 | assert.Equal(t, 0, got, "no matching labels should return 0") |
| 145 | }) |
| 146 | |
| 147 | t.Run("empty issue labels returns 0", func(t *testing.T) { |
| 148 | got := mapping(github.MultiLabelLogicMax).ComputeObjectiveValue([]string{}) |
| 149 | assert.Equal(t, 0, got, "empty issue labels should return 0") |
| 150 | }) |
| 151 |
nothing calls this directly
no test coverage detected