package cafegame import "testing" func TestSourceToName(t *testing.T) { cases := map[int]string{ SourceYGX: "云更新", SourceWWDS: "网维大师", SourceYLY: "易乐游", SourceMTGX: "马蹄更新", SourceStory: "蘑菇", SourceGoodGame: "盖伦", SourceHaoSiJi: "好司机", SourceFast: "火箭", SourceWfGame: "WF游戏", 999: "", // 未知来源 } for id, want := range cases { if got := SourceToName(id); got != want { t.Errorf("SourceToName(%d) = %q, want %q", id, got, want) } } } func TestGetSourceAll(t *testing.T) { all := GetSourceAll() if len(all) == 0 { t.Fatal("GetSourceAll 不应为空") } for _, id := range all { if SourceToName(id) == "" { t.Errorf("来源 %d 无对应名称", id) } } } func TestGameStatusConstants(t *testing.T) { if GameStatusStart != 1 || GameStatusStop != 0 { t.Errorf("游戏状态常量错误: start=%d stop=%d", GameStatusStart, GameStatusStop) } } func TestIsAllNumberHandle(t *testing.T) { if !IsAllNumberHandle("12345") { t.Error("纯数字应通过") } if IsAllNumberHandle("12a45") { t.Error("含字母应不通过") } if IsAllNumberHandle("") { t.Error("空串应不通过") } }