mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-20 00:42:49 +08:00
Some checks are pending
Test / test (1.20, macos-13) (push) Waiting to run
Test / test (1.20, macos-latest) (push) Waiting to run
Test / test (1.20, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.20, ubuntu-latest) (push) Waiting to run
Test / test (1.20, windows-latest) (push) Waiting to run
Test / test (1.21, macos-13) (push) Waiting to run
Test / test (1.21, macos-latest) (push) Waiting to run
Test / test (1.21, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.21, ubuntu-latest) (push) Waiting to run
Test / test (1.21, windows-latest) (push) Waiting to run
Test / test (1.22, macos-13) (push) Waiting to run
Test / test (1.22, macos-latest) (push) Waiting to run
Test / test (1.22, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.22, ubuntu-latest) (push) Waiting to run
Test / test (1.22, windows-latest) (push) Waiting to run
Test / test (1.23, macos-13) (push) Waiting to run
Test / test (1.23, macos-latest) (push) Waiting to run
Test / test (1.23, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.23, ubuntu-latest) (push) Waiting to run
Test / test (1.23, windows-latest) (push) Waiting to run
Test / test (1.24, macos-13) (push) Waiting to run
Test / test (1.24, macos-latest) (push) Waiting to run
Test / test (1.24, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.24, ubuntu-latest) (push) Waiting to run
Test / test (1.24, windows-latest) (push) Waiting to run
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
50 lines
955 B
Go
50 lines
955 B
Go
package xsync
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
func TestMapOfLoadOrStoreFn(t *testing.T) {
|
|
const numEntries = 1000
|
|
m := NewMap[string, int]()
|
|
for i := 0; i < numEntries; i++ {
|
|
v, loaded := m.LoadOrStoreFn(strconv.Itoa(i), func() int {
|
|
return i
|
|
})
|
|
if loaded {
|
|
t.Fatalf("value not computed for %d", i)
|
|
}
|
|
if v != i {
|
|
t.Fatalf("values do not match for %d: %v", i, v)
|
|
}
|
|
}
|
|
for i := 0; i < numEntries; i++ {
|
|
v, loaded := m.LoadOrStoreFn(strconv.Itoa(i), func() int {
|
|
return i
|
|
})
|
|
if !loaded {
|
|
t.Fatalf("value not loaded for %d", i)
|
|
}
|
|
if v != i {
|
|
t.Fatalf("values do not match for %d: %v", i, v)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMapOfLoadOrStoreFn_FunctionCalledOnce(t *testing.T) {
|
|
m := NewMap[int, int]()
|
|
for i := 0; i < 100; {
|
|
m.LoadOrStoreFn(i, func() (v int) {
|
|
v, i = i, i+1
|
|
return v
|
|
})
|
|
}
|
|
m.Range(func(k, v int) bool {
|
|
if k != v {
|
|
t.Fatalf("%dth key is not equal to value %d", k, v)
|
|
}
|
|
return true
|
|
})
|
|
}
|