This is an automated email from the ASF dual-hosted git repository.
placave pushed a commit to branch cpc-sketch
in repository https://gitbox.apache.org/repos/asf/datasketches-go.git
The following commit(s) were added to refs/heads/cpc-sketch by this push:
new 15817bc Continue adding CPC tests
15817bc is described below
commit 15817bcfdd332358d8937d72c0f9a5a7de3c89df
Author: Pierre Lacave <[email protected]>
AuthorDate: Wed Sep 4 10:17:53 2024 +0200
Continue adding CPC tests
---
cpc/cpc_sketch.go | 3 ++
cpc/cpc_sketch_test.go | 85 +++++++++++++++++++++++++++++++++++++-------------
2 files changed, 67 insertions(+), 21 deletions(-)
diff --git a/cpc/cpc_sketch.go b/cpc/cpc_sketch.go
index 23e54ee..179e62f 100644
--- a/cpc/cpc_sketch.go
+++ b/cpc/cpc_sketch.go
@@ -122,6 +122,9 @@ func (c *CpcSketch) UpdateCharSlice(datum []byte) error {
}
func (c *CpcSketch) UpdateString(datum string) error {
+ if len(datum) == 0 {
+ return nil
+ }
// get a slice to the string data (avoiding a copy to heap)
return c.UpdateByteSlice(unsafe.Slice(unsafe.StringData(datum),
len(datum)))
}
diff --git a/cpc/cpc_sketch_test.go b/cpc/cpc_sketch_test.go
index b4c787f..335c109 100644
--- a/cpc/cpc_sketch_test.go
+++ b/cpc/cpc_sketch_test.go
@@ -83,28 +83,71 @@ func TestCPCCheckEstimatesWithMerge(t *testing.T) {
assert.True(t, est <= ub)
}
+func TestCPCCheckCornerCaseUpdates(t *testing.T) {
+ lgK := 4
+ sk, err := NewCpcSketch(lgK, CpcDefaultUpdateSeed)
+ assert.NoError(t, err)
+ err = sk.UpdateFloat64(0.0)
+ assert.NoError(t, err)
+ err = sk.UpdateFloat64(-0.0)
+ assert.NoError(t, err)
+ assert.Equal(t, sk.GetEstimate(), float64(1))
+ err = sk.UpdateString("")
+ assert.NoError(t, err)
+ assert.Equal(t, sk.GetEstimate(), float64(1))
+}
+
/*
- @Test
- public void checkEstimatesWithMerge() {
+@Test
+ public void checkCornerCaseUpdates() {
final int lgK = 4;
- final CpcSketch sk1 = new CpcSketch(lgK);
- final CpcSketch sk2 = new CpcSketch(lgK);
- final int n = 1 << lgK;
- for (int i = 0; i < n; i++ ) {
- sk1.update(i);
- sk2.update(i + n);
- }
- final CpcUnion union = new CpcUnion(lgK);
- union.update(sk1);
- union.update(sk2);
- final CpcSketch result = union.getResult();
- final double est = result.getEstimate();
- final double lb = result.getLowerBound(2);
- final double ub = result.getUpperBound(2);
- assertTrue(lb >= 0);
- assertTrue(lb <= est);
- assertTrue(est <= ub);
- assertTrue(result.validate());
- println(result.toString(true));
+ final CpcSketch sk = new CpcSketch(lgK);
+ sk.update(0.0);
+ sk.update(-0.0);
+ int est = (int) Math.round(sk.getEstimate());
+ assertEquals(est, 1);
+ String s = null;
+ sk.update(s);
+ s = "";
+ sk.update(s);
+ est = (int) Math.round(sk.getEstimate());
+ assertEquals(est, 1);
+
+ byte[] barr = null;
+ sk.update(barr);
+ est = (int) Math.round(sk.getEstimate());
+ assertEquals(est, 1);
+ barr = new byte[0];
+ sk.update(barr);
+ est = (int) Math.round(sk.getEstimate());
+ assertEquals(est, 1);
+
+ char[] carr = null;
+ sk.update(carr);
+ est = (int) Math.round(sk.getEstimate());
+ assertEquals(est, 1);
+ carr = new char[0];
+ sk.update(carr);
+ est = (int) Math.round(sk.getEstimate());
+ assertEquals(est, 1);
+
+ int[] iarr = null;
+ sk.update(iarr);
+ est = (int) Math.round(sk.getEstimate());
+ assertEquals(est, 1);
+ iarr = new int[0];
+ sk.update(iarr);
+ est = (int) Math.round(sk.getEstimate());
+ assertEquals(est, 1);
+
+ long[] larr = null;
+ sk.update(larr);
+ est = (int) Math.round(sk.getEstimate());
+ assertEquals(est, 1);
+ larr = new long[0];
+ sk.update(larr);
+ est = (int) Math.round(sk.getEstimate());
+ assertEquals(est, 1);
}
+
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]