mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-21 09:08:57 +00:00
32 lines
682 B
Go
32 lines
682 B
Go
package com
|
|
|
|
import (
|
|
"fmt"
|
|
"sync/atomic"
|
|
"testing"
|
|
|
|
"github.com/giongto35/cloud-game/v3/pkg/network"
|
|
)
|
|
|
|
type testClient struct {
|
|
NetClient
|
|
id int
|
|
c int32
|
|
}
|
|
|
|
func (t *testClient) Id() network.Uid { return network.Uid(fmt.Sprintf("%v", t.id)) }
|
|
func (t *testClient) change(n int) { atomic.AddInt32(&t.c, int32(n)) }
|
|
|
|
func TestPointerValue(t *testing.T) {
|
|
m := NewNetMap[*testClient]()
|
|
c := testClient{id: 1}
|
|
m.Add(&c)
|
|
fc, _ := m.FindBy(func(c *testClient) bool { return c.id == 1 })
|
|
c.change(100)
|
|
fc2, _ := m.Find(fc.Id().String())
|
|
|
|
expected := c.c == fc.c && c.c == fc2.c
|
|
if !expected {
|
|
t.Errorf("not expected change, o: %v != %v != %v", c.c, fc.c, fc2.c)
|
|
}
|
|
}
|