1 package evaluation
2
3 import (
4 "fmt"
5
6 "github.com/launchdarkly/go-sdk-common/v3/ldvalue"
7 )
8
9
10
11
12
13 type bucketingTestParams struct {
14 flagOrSegmentKey string
15 salt string
16 seed ldvalue.OptionalInt
17 contextValue string
18 secondaryKey string
19 expectedBucketValue float32
20 }
21
22 func (p bucketingTestParams) description() string { return fmt.Sprintf("%+v", p) }
23
24 func makeBucketingTestParams() []bucketingTestParams {
25 return []bucketingTestParams{
26 {
27 flagOrSegmentKey: "hashKey",
28 salt: "saltyA",
29 contextValue: "userKeyA",
30 expectedBucketValue: 0.42157587,
31 },
32 {
33 flagOrSegmentKey: "hashKey",
34 salt: "saltyA",
35 contextValue: "userKeyB",
36 expectedBucketValue: 0.6708485,
37 },
38 {
39 flagOrSegmentKey: "hashKey",
40 salt: "saltyA",
41 contextValue: "userKeyC",
42 expectedBucketValue: 0.10343106,
43 },
44 }
45 }
46
47 func makeBucketingTestParamsWithNumericStringValues() []bucketingTestParams {
48 return []bucketingTestParams{
49 {
50 flagOrSegmentKey: "hashKey",
51 salt: "saltyA",
52 contextValue: "33333",
53 expectedBucketValue: 0.54771423,
54 },
55 {
56 flagOrSegmentKey: "hashKey",
57 salt: "saltyA",
58 contextValue: "99999",
59 expectedBucketValue: 0.7309658,
60 },
61 }
62 }
63
64 func makeBucketingTestParamsForExperiments() []bucketingTestParams {
65 ret := makeBucketingTestParams()
66 ret = append(ret, []bucketingTestParams{
67 {
68 flagOrSegmentKey: "hashKey",
69 salt: "saltyA",
70 contextValue: "userKeyA",
71 expectedBucketValue: 0.42157587,
72 },
73 {
74 flagOrSegmentKey: "hashKey",
75 salt: "saltyA",
76 contextValue: "userKeyB",
77 expectedBucketValue: 0.6708485,
78 },
79 {
80 flagOrSegmentKey: "hashKey",
81 salt: "saltyA",
82 contextValue: "userKeyC",
83 expectedBucketValue: 0.10343106,
84 },
85 {
86 flagOrSegmentKey: "hashKey",
87 salt: "saltyA",
88 contextValue: "userKeyA",
89 seed: ldvalue.NewOptionalInt(61),
90 expectedBucketValue: 0.09801207,
91 },
92 {
93 flagOrSegmentKey: "hashKey",
94 salt: "saltyA",
95 contextValue: "userKeyB",
96 seed: ldvalue.NewOptionalInt(61),
97 expectedBucketValue: 0.14483777,
98 },
99 {
100 flagOrSegmentKey: "hashKey",
101 salt: "saltyA",
102 contextValue: "userKeyC",
103 seed: ldvalue.NewOptionalInt(61),
104 expectedBucketValue: 0.9242641,
105 },
106 }...)
107 return ret
108 }
109
View as plain text