Skip to content

Commit

Permalink
Test com.Counter (#47)
Browse files Browse the repository at this point in the history
* Test com.Counter#Add()

* Test com.Counter#Reset()

* TestCounter_Reset(): check c.Reset() result

Co-authored-by: alvar <[email protected]>

---------

Co-authored-by: alvar <[email protected]>
  • Loading branch information
Al2Klimov and oxzi authored Sep 2, 2024
1 parent 54b737a commit 15703e6
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions com/counter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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")
}

func TestCounter_Reset(t *testing.T) {
var c Counter

c.Add(42)
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")

c.Add(23)
require.Equal(t, uint64(23), c.Val(), "unexpected new value")
require.Equal(t, uint64(65), c.Total(), "unexpected new total")
}

0 comments on commit 15703e6

Please sign in to comment.