Skip to content

Commit 9add11d

Browse files
committed
remove . import and cover cache.New with tests
1 parent c2b6c99 commit 9add11d

4 files changed

+17
-9
lines changed

cache/cache_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ package cache
33
import "testing"
44

55
func TestCache(t *testing.T) {
6+
t.Run("New", func(t *testing.T) {
7+
c := New[string, int]()
8+
c.Store("k1", 1)
9+
v, loaded := c.Load("k1")
10+
assertEqual(t, 1, v)
11+
assertEqual(t, true, loaded)
12+
})
13+
614
t.Run("LoadOrStore", func(t *testing.T) {
715
var c Cache[string, int]
816
v, loaded := c.LoadOrStore("k1", 1)

memoize_with_cache_bench_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"math"
66
"testing"
77

8-
. "github.com/emad-elsaid/memoize/cache"
8+
"github.com/emad-elsaid/memoize/cache"
99
)
1010

1111
func BenchmarkMemoizerWithCache(b *testing.B) {
@@ -16,7 +16,7 @@ func BenchmarkMemoizerWithCache(b *testing.B) {
1616
b.Run(name, func(b *testing.B) {
1717

1818
mem := NewWithCache(
19-
&Cache[string, int]{},
19+
cache.New[string, int](),
2020
func(k string) int { return len(k) })
2121

2222
keys := []string{}
@@ -43,7 +43,7 @@ func BenchmarkMemoizerWithCacheParallel(b *testing.B) {
4343
b.Run(name, func(b *testing.B) {
4444

4545
mem := NewWithCache(
46-
&Cache[string, int]{},
46+
cache.New[string, int](),
4747
func(k string) int { return len(k) })
4848

4949
keys := []string{}

memoize_with_cache_err_bench_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"math"
66
"testing"
77

8-
. "github.com/emad-elsaid/memoize/cache"
8+
"github.com/emad-elsaid/memoize/cache"
99
)
1010

1111
const maxKeySpace = 6
@@ -20,7 +20,7 @@ func BenchmarkMemoizerWithCacheErr(b *testing.B) {
2020
b.Run(name, func(b *testing.B) {
2121

2222
mem := NewWithCacheErr(
23-
&Cache[string, Pair[int]]{},
23+
cache.New[string, Pair[int]](),
2424
func(k string) (int, error) { return len(k), nil })
2525

2626
keys := []string{}
@@ -47,7 +47,7 @@ func BenchmarkMemoizerWithCacheErrParallel(b *testing.B) {
4747
b.Run(name, func(b *testing.B) {
4848

4949
mem := NewWithCacheErr(
50-
&Cache[string, Pair[int]]{},
50+
cache.New[string, Pair[int]](),
5151
func(k string) (int, error) { return len(k), nil })
5252

5353
keys := []string{}

memoize_with_cache_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"sync"
55
"testing"
66

7-
. "github.com/emad-elsaid/memoize/cache"
7+
"github.com/emad-elsaid/memoize/cache"
88
)
99

1010
func TestMemoizerWithCache(t *testing.T) {
@@ -18,7 +18,7 @@ func TestMemoizerWithCache(t *testing.T) {
1818
return counters[k]
1919
}
2020

21-
mem := NewWithCache(&Cache[string, int]{}, inc)
21+
mem := NewWithCache(cache.New[string, int](), inc)
2222

2323
concurrency := 100
2424
var wg sync.WaitGroup
@@ -63,7 +63,7 @@ func TestMemoizerWithCacheErr(t *testing.T) {
6363
return counters[k], nil
6464
}
6565

66-
mem := NewWithCacheErr(&Cache[string, Pair[int]]{}, inc)
66+
mem := NewWithCacheErr(cache.New[string, Pair[int]](), inc)
6767

6868
concurrency := 100
6969
var wg sync.WaitGroup

0 commit comments

Comments
 (0)