Commit 2418fd6 1 parent bc9d3bb commit 2418fd6 Copy full SHA for 2418fd6
File tree 2 files changed +23
-3
lines changed
2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,11 @@ import (
8
8
axiprotocol "github.com/ReconfigureIO/sdaccel/axi/protocol"
9
9
)
10
10
11
+ // calculate the bin for the histogram
12
+ func CalculateIndex (sample uint32 ) uint16 {
13
+ return uint16 (sample ) >> (16 - 9 )
14
+ }
15
+
11
16
// magic identifier for exporting
12
17
func Top (
13
18
inputData uintptr ,
@@ -32,11 +37,9 @@ func Top(
32
37
for ; length > 0 ; length -- {
33
38
// First we'll pull of each sample from the channel
34
39
sample := <- inputChan
35
- // calculate the bin for the histogram
36
- index := uint16 (sample ) >> (16 - 9 )
37
40
38
41
// And increment the value in that bin
39
- histogram [uint ( index )] += 1
42
+ histogram [CalculateIndex ( sample )] += 1
40
43
}
41
44
42
45
data := make (chan uint32 )
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "testing"
5
+ "testing/quick"
6
+ )
7
+
8
+ func TestCalculateIndexDoesNotOutOfBounds (t * testing.T ) {
9
+ // Check that we never generate an index out of bounds
10
+ f := func (x uint32 ) bool {
11
+ index := CalculateIndex (x )
12
+ return index < 512
13
+ }
14
+ if err := quick .Check (f , nil ); err != nil {
15
+ t .Error (err )
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments