package service import ( "math/rand" "testing" "time" ) func TestHumanRoomRobotGiftSenderLimit(t *testing.T) { activity := newRobotRoomActivity([]int64{101, 102, 103, 104}) for _, userID := range []int64{101, 102, 103, 104} { activity.markActive(userID) } markInitialHumanRoomGiftSenders(activity, []int64{101, 102, 103, 104}, 2) if got := activity.giftSenderCount(); got != 2 { t.Fatalf("gift sender count mismatch: got %d want 2", got) } if activity.markGiftSenderWithinLimit(104, 2) { t.Fatalf("gift sender limit allowed one more sender") } } func TestHumanRoomRobotNormalGiftDelayRange(t *testing.T) { rng := rand.New(rand.NewSource(1)) config := HumanRoomRobotConfig{NormalGiftIntervalMinMS: 1000, NormalGiftIntervalMaxMS: 20000} for i := 0; i < 100; i++ { delay := humanRoomRobotNormalGiftDelay(config, rng) if delay < time.Second || delay > 20*time.Second { t.Fatalf("gift delay out of range: %s", delay) } } } func TestRandomHumanRoomTargetOnlineRange(t *testing.T) { config := HumanRoomRobotConfig{RoomTargetMinOnline: 8, RoomTargetMaxOnline: 10} for i := 0; i < 100; i++ { target := randomHumanRoomTargetOnline(config) if target < 8 || target > 10 { t.Fatalf("target online out of range: %d", target) } } } func TestRandomHumanRoomTargetOnlineLegacyFixedValue(t *testing.T) { config := HumanRoomRobotConfig{RoomFullStopOnline: 10} for i := 0; i < 20; i++ { if target := randomHumanRoomTargetOnline(config); target != 10 { t.Fatalf("legacy target online mismatch: got %d want 10", target) } } }