Skip to content

Commit 4df8630

Browse files
Examples to T-Digest functions (#39)
* examples Co-authored-by: filipe oliveira <[email protected]>
1 parent dfef579 commit 4df8630

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

example_client_test.go

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,144 @@ func ExampleNewClientFromPool() {
5050
// Output: myItem exists in mytest: true
5151

5252
}
53+
54+
// exemplifies the TdCreate function
55+
func ExampleClient_TdCreate() {
56+
host := "localhost:6379"
57+
var client = redisbloom.NewClient(host, "nohelp", nil)
58+
59+
ret, err := client.TdCreate("key", 100)
60+
if err != nil {
61+
fmt.Println("Error:", err)
62+
}
63+
64+
fmt.Println(ret)
65+
// Output: OK
66+
67+
}
68+
69+
// exemplifies the TdAdd function
70+
func ExampleClient_TdAdd() {
71+
host := "localhost:6379"
72+
var client = redisbloom.NewClient(host, "nohelp", nil)
73+
74+
key := "example"
75+
ret, err := client.TdCreate(key, 100)
76+
if err != nil {
77+
fmt.Println("Error:", err)
78+
}
79+
80+
samples := map[float64]float64{1.0: 1.0, 2.0: 2.0}
81+
ret, err = client.TdAdd(key, samples)
82+
if err != nil {
83+
fmt.Println("Error:", err)
84+
}
85+
86+
fmt.Println(ret)
87+
// Output: OK
88+
89+
}
90+
91+
// exemplifies the TdMin function
92+
func ExampleClient_TdMin() {
93+
host := "localhost:6379"
94+
var client = redisbloom.NewClient(host, "nohelp", nil)
95+
96+
key := "example"
97+
_, err := client.TdCreate(key, 10)
98+
if err != nil {
99+
fmt.Println("Error:", err)
100+
}
101+
102+
samples := map[float64]float64{1.0: 1.0, 2.0: 2.0, 3.0: 3.0}
103+
_, err = client.TdAdd(key, samples)
104+
if err != nil {
105+
fmt.Println("Error:", err)
106+
}
107+
108+
min, err := client.TdMin(key)
109+
if err != nil {
110+
fmt.Println("Error:", err)
111+
}
112+
113+
fmt.Println(min)
114+
// Output: 1
115+
}
116+
117+
// exemplifies the TdMax function
118+
func ExampleClient_TdMax() {
119+
host := "localhost:6379"
120+
var client = redisbloom.NewClient(host, "nohelp", nil)
121+
122+
key := "example"
123+
_, err := client.TdCreate(key, 10)
124+
if err != nil {
125+
fmt.Println("Error:", err)
126+
}
127+
128+
samples := map[float64]float64{1.0: 1.0, 2.0: 2.0, 3.0: 3.0}
129+
_, err = client.TdAdd(key, samples)
130+
if err != nil {
131+
fmt.Println("Error:", err)
132+
}
133+
134+
max, err := client.TdMax(key)
135+
if err != nil {
136+
fmt.Println("Error:", err)
137+
}
138+
139+
fmt.Println(max)
140+
// Output: 3
141+
}
142+
143+
// exemplifies the TdQuantile function
144+
func ExampleClient_TdQuantile() {
145+
host := "localhost:6379"
146+
var client = redisbloom.NewClient(host, "nohelp", nil)
147+
148+
key := "example"
149+
_, err := client.TdCreate(key, 10)
150+
if err != nil {
151+
fmt.Println("Error:", err)
152+
}
153+
154+
samples := map[float64]float64{1.0: 1.0, 2.0: 1.0, 3.0: 1.0, 4.0: 1.0, 5.0: 1.0}
155+
_, err = client.TdAdd(key, samples)
156+
if err != nil {
157+
fmt.Println("Error:", err)
158+
}
159+
160+
ans, err := client.TdQuantile(key, 1.0)
161+
if err != nil {
162+
fmt.Println("Error:", err)
163+
}
164+
165+
fmt.Println(ans)
166+
// Output: 5
167+
}
168+
169+
// exemplifies the TdCdf function
170+
func ExampleClient_TdCdf() {
171+
host := "localhost:6379"
172+
var client = redisbloom.NewClient(host, "nohelp", nil)
173+
174+
key := "example"
175+
_, err := client.TdCreate(key, 10)
176+
if err != nil {
177+
fmt.Println("Error:", err)
178+
}
179+
180+
samples := map[float64]float64{1.0: 1.0, 2.0: 1.0, 3.0: 1.0, 4.0: 1.0, 5.0: 1.0}
181+
_, err = client.TdAdd(key, samples)
182+
if err != nil {
183+
fmt.Println("Error:", err)
184+
}
185+
186+
cdf, err := client.TdCdf(key, 1.0)
187+
if err != nil {
188+
fmt.Println("Error:", err)
189+
}
190+
191+
fmt.Println(cdf)
192+
// Output: 0.1
193+
}

0 commit comments

Comments
 (0)