@@ -26,28 +26,28 @@ type heapUnderTest struct {
2626 // new returns a fresh, empty heap.Interface backed by the concrete heap type.
2727 new func () heap.Interface
2828 // root reads h[0].dist from the concrete heap value.
29- root func (h heap.Interface ) float32
29+ root func (h heap.Interface ) float64
3030 // popOrder returns the distances in the order Pop yields them: ascending for minHeap,
3131 // descending for maxHeap.
32- popOrder func (sorted []float32 ) []float32
32+ popOrder func (sorted []float64 ) []float64
3333 // extreme returns the element this heap would pop next from the given contents: the minimum
3434 // for minHeap, the maximum for maxHeap. Panics on empty input (never called that way).
35- extreme func (contents []float32 ) float32
35+ extreme func (contents []float64 ) float64
3636}
3737
3838func minHeapUT () heapUnderTest {
3939 return heapUnderTest {
4040 name : "minHeap" ,
4141 new : func () heap.Interface { return newMinHeap () },
42- root : func (h heap.Interface ) float32 {
42+ root : func (h heap.Interface ) float64 {
4343 mh , _ := h .(* candidateHeap )
4444 return mh .items [0 ].dist
4545 },
46- popOrder : func (sorted []float32 ) []float32 {
47- out := append ([]float32 (nil ), sorted ... ) // sorted is ascending → min pops ascending
46+ popOrder : func (sorted []float64 ) []float64 {
47+ out := append ([]float64 (nil ), sorted ... ) // sorted is ascending → min pops ascending
4848 return out
4949 },
50- extreme : func (contents []float32 ) float32 {
50+ extreme : func (contents []float64 ) float64 {
5151 m := contents [0 ]
5252 for _ , v := range contents {
5353 if v < m {
@@ -63,18 +63,18 @@ func maxHeapUT() heapUnderTest {
6363 return heapUnderTest {
6464 name : "maxHeap" ,
6565 new : func () heap.Interface { return newMaxHeap () },
66- root : func (h heap.Interface ) float32 {
66+ root : func (h heap.Interface ) float64 {
6767 mh , _ := h .(* candidateHeap )
6868 return mh .items [0 ].dist
6969 },
70- popOrder : func (sorted []float32 ) []float32 {
71- out := make ([]float32 , len (sorted )) // sorted is ascending → max pops descending
70+ popOrder : func (sorted []float64 ) []float64 {
71+ out := make ([]float64 , len (sorted )) // sorted is ascending → max pops descending
7272 for i , v := range sorted {
7373 out [len (sorted )- 1 - i ] = v
7474 }
7575 return out
7676 },
77- extreme : func (contents []float32 ) float32 {
77+ extreme : func (contents []float64 ) float64 {
7878 m := contents [0 ]
7979 for _ , v := range contents {
8080 if v > m {
@@ -94,9 +94,9 @@ func popCandidate(t *testing.T, h heap.Interface) candidate {
9494 return c
9595}
9696
97- func popAllDists (t * testing.T , h heap.Interface ) []float32 {
97+ func popAllDists (t * testing.T , h heap.Interface ) []float64 {
9898 t .Helper ()
99- out := make ([]float32 , 0 , h .Len ())
99+ out := make ([]float64 , 0 , h .Len ())
100100 for h .Len () > 0 {
101101 out = append (out , popCandidate (t , h ).dist )
102102 }
@@ -106,7 +106,7 @@ func popAllDists(t *testing.T, h heap.Interface) []float32 {
106106func TestHeap_PushThenPopAll_YieldsOrderedDistances (t * testing.T ) {
107107 // A representative unordered input; sorted ascending is the reference the per-heap popOrder
108108 // derives its expectation from.
109- inputs := map [string ][]float32 {
109+ inputs := map [string ][]float64 {
110110 "unordered distinct" : {5 , 1 , 4 , 2 , 3 },
111111 "already ascending" : {1 , 2 , 3 , 4 },
112112 "already descending" : {4 , 3 , 2 , 1 },
@@ -134,7 +134,7 @@ func TestHeap_PushThenPopAll_YieldsOrderedDistances(t *testing.T) {
134134}
135135
136136func TestHeap_Root_IsExtremeElement (t * testing.T ) {
137- in := []float32 {5 , 1 , 4 , 2 , 3 }
137+ in := []float64 {5 , 1 , 4 , 2 , 3 }
138138
139139 for _ , ut := range []heapUnderTest {minHeapUT (), maxHeapUT ()} {
140140 t .Run (ut .name , func (t * testing.T ) {
@@ -157,9 +157,9 @@ func TestHeap_InterleavedPushPop_ReturnsCurrentExtreme(t *testing.T) {
157157 for _ , ut := range []heapUnderTest {minHeapUT (), maxHeapUT ()} {
158158 t .Run (ut .name , func (t * testing.T ) {
159159 h := ut .new ()
160- model := []float32 {}
160+ model := []float64 {}
161161
162- push := func (d float32 ) {
162+ push := func (d float64 ) {
163163 heap .Push (h , candidate {dist : d })
164164 model = append (model , d )
165165 }
@@ -194,7 +194,7 @@ func TestHeap_PreservesCandidatePayload(t *testing.T) {
194194}
195195
196196// removeFirst returns s with the first occurrence of v removed (reference-model bookkeeping).
197- func removeFirst (s []float32 , v float32 ) []float32 {
197+ func removeFirst (s []float64 , v float64 ) []float64 {
198198 for i , x := range s {
199199 if x == v {
200200 return append (s [:i :i ], s [i + 1 :]... )
@@ -204,8 +204,8 @@ func removeFirst(s []float32, v float32) []float32 {
204204}
205205
206206// ascendingSorted returns a new ascending-sorted copy of in, used as the reference ordering.
207- func ascendingSorted (in []float32 ) []float32 {
208- out := append ([]float32 (nil ), in ... )
207+ func ascendingSorted (in []float64 ) []float64 {
208+ out := append ([]float64 (nil ), in ... )
209209 for i := 1 ; i < len (out ); i ++ {
210210 for j := i ; j > 0 && out [j ] < out [j - 1 ]; j -- {
211211 out [j ], out [j - 1 ] = out [j - 1 ], out [j ]
0 commit comments