aboutsummaryrefslogtreecommitdiff
path: root/each_test.go
diff options
context:
space:
mode:
authorAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-04-07 21:36:40 +0300
committerAlexander Kiryukhin <a.kiryukhin@mail.ru>2022-04-07 21:36:40 +0300
commit9cd6b0fca87679e570fbdd4942e3068feb3439fa (patch)
tree557bf877d71854480f4171e9dd324cebb5606056 /each_test.go
initial
Diffstat (limited to 'each_test.go')
-rw-r--r--each_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/each_test.go b/each_test.go
new file mode 100644
index 0000000..f64e55b
--- /dev/null
+++ b/each_test.go
@@ -0,0 +1,30 @@
+package collection
+
+import (
+ "sync/atomic"
+ "testing"
+)
+
+func TestEachSync(t *testing.T) {
+ collection := []int{1, 2, 3, 4, 5, 6}
+ want := 21
+ sum := 0
+ EachSync(collection, func(v int, _ int) {
+ sum += v
+ })
+ if sum != want {
+ t.Errorf("Expected %d, got %d", want, sum)
+ }
+}
+
+func TestEach(t *testing.T) {
+ collection := []int{1, 2, 3, 4, 5, 6}
+ want := int64(21)
+ sum := int64(0)
+ Each(collection, func(v int, _ int) {
+ atomic.AddInt64(&sum, int64(v))
+ })
+ if sum != want {
+ t.Errorf("Expected %d, got %d", want, sum)
+ }
+}