@@ -192,6 +192,114 @@ func TestHintIsVisible(t *testing.T) {
192192 }
193193}
194194
195+ func TestGenerate (t * testing.T ) {
196+ // Create test elements
197+ elements := []* accessibility.TreeNode {
198+ {
199+ Info : & accessibility.ElementInfo {
200+ Position : image.Point {X : 10 , Y : 10 },
201+ Size : image.Point {X : 20 , Y : 20 },
202+ Role : "button" ,
203+ },
204+ },
205+ {
206+ Info : & accessibility.ElementInfo {
207+ Position : image.Point {X : 50 , Y : 10 },
208+ Size : image.Point {X : 20 , Y : 20 },
209+ Role : "link" ,
210+ },
211+ },
212+ {
213+ Info : & accessibility.ElementInfo {
214+ Position : image.Point {X : 10 , Y : 50 },
215+ Size : image.Point {X : 20 , Y : 20 },
216+ Role : "checkbox" ,
217+ },
218+ },
219+ }
220+
221+ tests := []struct {
222+ name string
223+ characters string
224+ style string
225+ maxHints int
226+ elements []* accessibility.TreeNode
227+ wantCount int
228+ wantLabels []string
229+ }{
230+ {
231+ name : "alphabet style" ,
232+ characters : "asdf" ,
233+ style : "alphabet" ,
234+ maxHints : 10 ,
235+ elements : elements ,
236+ wantCount : 3 ,
237+ wantLabels : []string {"A" , "S" , "D" },
238+ },
239+ {
240+ name : "numeric style" ,
241+ characters : "asdf" ,
242+ style : "numeric" ,
243+ maxHints : 10 ,
244+ elements : elements ,
245+ wantCount : 3 ,
246+ wantLabels : []string {"1" , "2" , "3" },
247+ },
248+ {
249+ name : "limited hints" ,
250+ characters : "asdf" ,
251+ style : "alphabet" ,
252+ maxHints : 2 ,
253+ elements : elements ,
254+ wantCount : 2 ,
255+ wantLabels : []string {"A" , "S" },
256+ },
257+ {
258+ name : "empty elements" ,
259+ characters : "asdf" ,
260+ style : "alphabet" ,
261+ maxHints : 10 ,
262+ elements : []* accessibility.TreeNode {},
263+ wantCount : 0 ,
264+ wantLabels : []string {},
265+ },
266+ }
267+
268+ for _ , tt := range tests {
269+ t .Run (tt .name , func (t * testing.T ) {
270+ generator := NewGenerator (tt .characters , tt .style , tt .maxHints )
271+ hints , err := generator .Generate (tt .elements )
272+
273+ if err != nil {
274+ t .Fatalf ("Generate() error = %v" , err )
275+ }
276+
277+ if len (hints ) != tt .wantCount {
278+ t .Errorf ("Generate() returned %d hints, want %d" , len (hints ), tt .wantCount )
279+ }
280+
281+ // Check labels
282+ for i , hint := range hints {
283+ if i < len (tt .wantLabels ) && hint .Label != tt .wantLabels [i ] {
284+ t .Errorf ("Generate() hint[%d].Label = %s, want %s" , i , hint .Label , tt .wantLabels [i ])
285+ }
286+ }
287+
288+ // Check positions are centered
289+ for i , hint := range hints {
290+ element := tt .elements [i ]
291+ expectedX := element .Info .Position .X + (element .Info .Size .X / 2 )
292+ expectedY := element .Info .Position .Y + (element .Info .Size .Y / 2 )
293+
294+ if hint .Position .X != expectedX || hint .Position .Y != expectedY {
295+ t .Errorf ("Generate() hint[%d].Position = (%d,%d), want (%d,%d)" ,
296+ i , hint .Position .X , hint .Position .Y , expectedX , expectedY )
297+ }
298+ }
299+ })
300+ }
301+ }
302+
195303func TestHintCollection (t * testing.T ) {
196304 hints := []* Hint {
197305 {Label : "a" },
0 commit comments