Пример #1
0
func TestMergePNCounterIsCommutative(t *testing.T) {
	c1 := pncounter.New()

	c1.Increment("foo", 1)
	c1.Increment("bar", 1)
	c1.Increment("baz", 1)

	c2 := pncounter.New()
	c2.Increment("foo", 2)
	c2.Increment("bar", 0)
	c2.Increment("baz", 1)

	c3 := c1.Merge(c2)
	c4 := c2.Merge(c1)

	if c3.Value() != c4.Value() {
		t.Errorf("Counter value missmatch:\nExpected: %v\nGot: %v", c3.Value(), c4.Value())
	}
}
Пример #2
0
func TestMergeTwoPNCounter(t *testing.T) {
	c1 := pncounter.New()

	c1.Increment("foo", 1)
	c1.Increment("bar", 1)
	c1.Increment("baz", 1)

	c2 := pncounter.New()
	c2.Increment("foo", 2)
	c2.Increment("bar", 0)
	c2.Increment("baz", 1)

	c3 := c1.Merge(c2)

	expectedValue := int64(4)

	if c3.Value() != expectedValue {
		t.Errorf("Counter value missmatch:\nExpected: %v\nGot: %v", expectedValue, c3.Value())
	}
}
Пример #3
0
func TestPNCounter(t *testing.T) {
	c := pncounter.New()

	c.Increment("foo", 4)
	c.Increment("bar", 1)
	c.Decrement("foo", 2)

	expectedValue := int64(3)

	if c.Value() != expectedValue {
		t.Errorf("Counter value missmatch:\nExpected: %v\nGot: %v", expectedValue, c.Value())
	}
}