@@ -6,75 +6,6 @@ import (
66 "github.com/stretchr/testify/assert"
77)
88
9- func TestBenchSpy_CalculatePercentile (t * testing.T ) {
10- t .Run ("basic percentile calculations" , func (t * testing.T ) {
11- numbers := []float64 {1 , 2 , 3 , 4 , 5 }
12-
13- // Test median (50th percentile)
14- assert .Equal (t , 3.0 , CalculatePercentile (numbers , 0.5 ))
15-
16- // Test minimum (0th percentile)
17- assert .Equal (t , 1.0 , CalculatePercentile (numbers , 0 ))
18-
19- // Test maximum (100th percentile)
20- assert .Equal (t , 5.0 , CalculatePercentile (numbers , 1 ))
21- })
22-
23- t .Run ("unsorted input" , func (t * testing.T ) {
24- numbers := []float64 {5 , 2 , 1 , 4 , 3 }
25- assert .Equal (t , 3.0 , CalculatePercentile (numbers , 0.5 ))
26- })
27-
28- t .Run ("interpolation cases" , func (t * testing.T ) {
29- numbers := []float64 {1 , 2 , 3 , 4 }
30-
31- // Test 25th percentile (should interpolate between 1 and 2)
32- expected25 := 1.75
33- assert .InDelta (t , expected25 , CalculatePercentile (numbers , 0.25 ), 0.000001 )
34-
35- // Test 75th percentile (should interpolate between 3 and 4)
36- expected75 := 3.25
37- assert .InDelta (t , expected75 , CalculatePercentile (numbers , 0.75 ), 0.000001 )
38- })
39-
40- t .Run ("single element" , func (t * testing.T ) {
41- numbers := []float64 {42 }
42- assert .Equal (t , 42.0 , CalculatePercentile (numbers , 0.5 ))
43- })
44-
45- t .Run ("duplicate values" , func (t * testing.T ) {
46- numbers := []float64 {1 , 2 , 2 , 3 , 3 , 3 , 4 }
47- assert .Equal (t , 3.0 , CalculatePercentile (numbers , 0.5 ))
48- })
49-
50- t .Run ("panic on empty slice" , func (t * testing.T ) {
51- assert .Panics (t , func () {
52- CalculatePercentile ([]float64 {}, 0.5 )
53- })
54- })
55-
56- t .Run ("panic on invalid percentile - negative" , func (t * testing.T ) {
57- assert .Panics (t , func () {
58- CalculatePercentile ([]float64 {1 , 2 , 3 }, - 0.1 )
59- })
60- })
61-
62- t .Run ("panic on invalid percentile - greater than 1" , func (t * testing.T ) {
63- assert .Panics (t , func () {
64- CalculatePercentile ([]float64 {1 , 2 , 3 }, 1.1 )
65- })
66- })
67-
68- t .Run ("large dataset" , func (t * testing.T ) {
69- numbers := make ([]float64 , 1000 )
70- for i := 0 ; i < 1000 ; i ++ {
71- numbers [i ] = float64 (i )
72- }
73- // 90th percentile of 0-999 should be 899
74- assert .InDelta (t , 899.1 , CalculatePercentile (numbers , 0.9 ), 0.000001 )
75- })
76- }
77-
789func TestBenchSpy_StringSliceToFloat64Slice (t * testing.T ) {
7910 t .Run ("valid conversion" , func (t * testing.T ) {
8011 input := []string {"1.0" , "2.5" , "3.14" }
0 commit comments