From a0c23075944745e2c787fe6f300fd8988722aeb2 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 19 Jul 2024 17:24:31 +0200 Subject: [PATCH 1/3] Test com.Counter#Add() --- com/counter_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 com/counter_test.go diff --git a/com/counter_test.go b/com/counter_test.go new file mode 100644 index 00000000..f3402994 --- /dev/null +++ b/com/counter_test.go @@ -0,0 +1,18 @@ +package com + +import ( + "github.com/stretchr/testify/require" + "testing" +) + +func TestCounter_Add(t *testing.T) { + var c Counter + + c.Add(42) + require.Equal(t, uint64(42), c.Val(), "unexpected value") + require.Equal(t, uint64(42), c.Total(), "unexpected total") + + c.Add(23) + require.Equal(t, uint64(65), c.Val(), "unexpected new value") + require.Equal(t, uint64(65), c.Total(), "unexpected new total") +} From 9590392c1bb0aa64aecd3f9a9f822ddf23f4b34a Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 19 Jul 2024 17:27:08 +0200 Subject: [PATCH 2/3] Test com.Counter#Reset() --- com/counter_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/com/counter_test.go b/com/counter_test.go index f3402994..a9ba296d 100644 --- a/com/counter_test.go +++ b/com/counter_test.go @@ -16,3 +16,17 @@ func TestCounter_Add(t *testing.T) { require.Equal(t, uint64(65), c.Val(), "unexpected new value") require.Equal(t, uint64(65), c.Total(), "unexpected new total") } + +func TestCounter_Reset(t *testing.T) { + var c Counter + + c.Add(42) + c.Reset() + + require.Equal(t, uint64(0), c.Val(), "unexpected value") + require.Equal(t, uint64(42), c.Total(), "unexpected total") + + c.Add(23) + require.Equal(t, uint64(23), c.Val(), "unexpected new value") + require.Equal(t, uint64(65), c.Total(), "unexpected new total") +} From 3d427815db79ef16c8646cf6df2ef340a409a95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Aleksandrovi=C4=8D=20Klimov?= Date: Fri, 16 Aug 2024 17:07:54 +0200 Subject: [PATCH 3/3] TestCounter_Reset(): check c.Reset() result Co-authored-by: alvar <8402811+oxzi@users.noreply.github.com> --- com/counter_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com/counter_test.go b/com/counter_test.go index a9ba296d..c4f0b285 100644 --- a/com/counter_test.go +++ b/com/counter_test.go @@ -21,7 +21,7 @@ func TestCounter_Reset(t *testing.T) { var c Counter c.Add(42) - c.Reset() + require.Equal(t, uint64(42), c.Reset(), "unexpected reset value") require.Equal(t, uint64(0), c.Val(), "unexpected value") require.Equal(t, uint64(42), c.Total(), "unexpected total")