/// <summary> /// 位图测试 /// </summary> /// <param name="client"></param> /// <returns></returns> internal static bool TestCase(AutoCSer.CacheServer.Client client) { #region 创建名称为 Bitmap 的位图缓存 AutoCSer.CacheServer.DataStructure.Bitmap bitmap = client.GetOrCreateDataStructure <AutoCSer.CacheServer.DataStructure.Bitmap>("Bitmap").Value; if (bitmap == null) { return(false); } #endregion #region 设置第 3 个位,返回设置前的位状态 false AutoCSer.CacheServer.ReturnValue <bool> bit = bitmap.Set(3); if (bit.Type != AutoCSer.CacheServer.ReturnType.Success || bit.Value) { return(false); } #endregion #region 第 5 个位取反,返回取反后的结果 true bit = bitmap.SetNegate(5); if (!bit.Value) { return(false); } #endregion #region 获取第 3 个位,结果为 true bit = bitmap.Get(3); if (!bit.Value) { return(false); } #endregion #region 清除第 5 个位,返回清除前的位状态 true bit = bitmap.Clear(5); if (!bit.Value) { return(false); } #endregion #region 第 3 个位取反,返回取反后的结果 false bit = bitmap.SetNegate(3); if (bit.Type != AutoCSer.CacheServer.ReturnType.Success || bit.Value) { return(false); } #endregion #region 获取第 5 个位,结果为 false bit = bitmap.Get(5); if (bit.Type != AutoCSer.CacheServer.ReturnType.Success || bit.Value) { return(false); } #endregion return(true); }
/// <summary> /// 测试回调 /// </summary> /// <param name="value"></param> private void getCallback(AutoCSer.CacheServer.ReturnValue <Binary <int> > value) { if (value.Get().Type != AutoCSer.CacheServer.ReturnType.Success) { ++errorCount; } getCallback(); }
/// <summary> /// 测试回调 /// </summary> /// <param name="value"></param> protected void getCallback(AutoCSer.CacheServer.ReturnValue <int> value) { if (value.Type != AutoCSer.CacheServer.ReturnType.Success) { ++errorCount; } getCallback(); }
/// <summary> /// 哈希表测试 /// </summary> /// <param name="client"></param> /// <returns></returns> internal static bool TestCase(AutoCSer.CacheServer.Client client) { #region 创建名称为 HashSet 的哈希表缓存 HashSet <int> hashSet = client.GetOrCreateDataStructure <HashSet <int> >("HashSet").Value; if (hashSet == null) { return(false); } #endregion #region 添加值为 9 的数据 AutoCSer.CacheServer.ReturnValue <bool> isAdd = hashSet.Add(9); if (!isAdd.Value) { return(false); } #endregion #region 判断是否存在值为 9 的数据 AutoCSer.CacheServer.ReturnValue <bool> isValue = hashSet.Contains(9); if (!isValue.Value) { return(false); } #endregion #region 获取哈希表数据数量 AutoCSer.CacheServer.ReturnValue <int> count = hashSet.Count; if (count.Value != 1) { return(false); } #endregion #region 除值为 9 的数据 AutoCSer.CacheServer.ReturnValue <bool> isRemove = hashSet.Remove(9); if (!isRemove.Value) { return(false); } count = hashSet.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } #endregion return(true); }
/// <summary> /// 字典测试(短路径) /// </summary> /// <param name="dictionary"></param> /// <returns></returns> internal static bool TestCase(AutoCSer.CacheServer.ShortPath.Dictionary <int, int> dictionary) { #region dictionary[1] = 9; AutoCSer.CacheServer.ReturnValue <bool> isSet = dictionary.Set(1, 9); if (!isSet.Value) { return(false); } #endregion #region 判断关键字 1 是否存在 AutoCSer.CacheServer.ReturnValue <bool> isKey = dictionary.ContainsKey(1); if (!isKey.Value) { return(false); } #endregion #region 获取关键字为 1 的数据 AutoCSer.CacheServer.ReturnValue <int> value = dictionary.Get(1); if (value.Value != 9) { return(false); } #endregion #region 获取字典数据数量 AutoCSer.CacheServer.ReturnValue <int> count = dictionary.Count; if (count.Value != 1) { return(false); } #endregion #region 除关键字为 1 的数据 AutoCSer.CacheServer.ReturnValue <bool> isRemove = dictionary.Remove(1); if (!isRemove.Value) { return(false); } count = dictionary.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } #endregion return(true); }
/// <summary> /// 数组测试(短路径) /// </summary> /// <param name="array"></param> /// <returns></returns> internal static bool TestCase(AutoCSer.CacheServer.ShortPath.Array <int> array) { #region array[1] = 9; AutoCSer.CacheServer.ReturnValue <bool> isSet = array.Set(1, 9); if (!isSet.Value) { return(false); } #endregion #region 获取索引为 1 的数据 AutoCSer.CacheServer.ReturnValue <int> value = array.Get(1); if (value.Value != 9) { return(false); } #endregion #region 获取数组已使用长度 AutoCSer.CacheServer.ReturnValue <int> count = array.Count; if (count.Value != 2) { return(false); } #endregion #region 清除所有数据 AutoCSer.CacheServer.ReturnValue <bool> isClear = array.Clear(); if (!isClear.Value) { return(false); } count = array.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } #endregion return(true); }
/// <summary> /// 锁测试 /// </summary> /// <param name="client"></param> /// <returns></returns> internal static bool TestCase(AutoCSer.CacheServer.Client client) { #region 创建名称为 Lock 的锁缓存 AutoCSer.CacheServer.DataStructure.Lock Lock = client.GetOrCreateDataStructure <AutoCSer.CacheServer.DataStructure.Lock>("Lock").Value; if (Lock == null) { return(false); } #endregion #region 步等待申请锁,锁超时为 5 秒 AutoCSer.CacheServer.ReturnValue <AutoCSer.CacheServer.Lock.Manager> manager = Lock.GetEnter(5 * 1000); if (manager.Value == null) { return(false); } #endregion using (manager.Value) { #region 尝试申请锁 AutoCSer.CacheServer.ReturnValue <AutoCSer.CacheServer.Lock.Manager> tryManager = Lock.GetTryEnter(5 * 1000); if (tryManager.Type != AutoCSer.CacheServer.ReturnType.Locked) { return(false); } #endregion } manager = Lock.GetTryEnter(5 * 1000); if (manager.Value == null) { return(false); } #region 释放锁,使用 using 也可以 manager.Value.Exit(); #endregion return(true); }
/// <summary> /// 数组测试 /// </summary> /// <param name="array"></param> /// <returns></returns> internal static bool TestCase(ValueArray <int> array) { #region array[1] = 9; AutoCSer.CacheServer.ReturnValue <bool> isSet = array.Set(1, 9); if (!isSet.Value) { return(false); } #endregion #region 获取索引为 1 的数据 AutoCSer.CacheServer.ReturnValue <int> value = array.Get(1); if (value.Value != 9) { return(false); } #endregion #region 获取索引为 1 的数字更新 AutoCSer.CacheServer.OperationUpdater.Number <int> number1 = array.GetNumberUpdater(1); #endregion #region 索引为 1 的数据 +2 value = number1 + 2; if (value.Value != 11) { return(false); } #endregion #region 索引为 1 的数据 -5 value = number1 - 5; if (value.Value != 6) { return(false); } #endregion #region 获取索引为 1 的数据 value = array.Get(1); if (value.Value != 6) { return(false); } #endregion #region 如果索引为 1 的数据小于 10 则 +5 value = number1.Add(5, number1 < 10); if (value.Value != 11) { return(false); } #endregion #region 如果索引为 1 的数据小于 10 则 +5 value = number1.Add(5, number1 < 10); if (value.Value != 11) { return(false); } #endregion #region 获取索引为 1 的数据 value = array.Get(1); if (value.Value != 11) { return(false); } #endregion #region 获取数组已使用长度 AutoCSer.CacheServer.ReturnValue <int> count = array.Count; if (count.Value != 2) { return(false); } #endregion #region 清除所有数据 AutoCSer.CacheServer.ReturnValue <bool> isClear = array.Clear(); if (!isClear.Value) { return(false); } count = array.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } #endregion return(true); }
/// <summary> /// 最小堆测试 /// </summary> /// <param name="client"></param> /// <returns></returns> internal static bool TestCase(AutoCSer.CacheServer.Client client) { #region 创建名称为 Heap 的最小堆缓存 Heap <int, int> heap = client.GetOrCreateDataStructure <Heap <int, int> >("Heap").Value; if (heap == null) { return(false); } #endregion #region 添加关键字为 6 值为 9 的数据 AutoCSer.CacheServer.ReturnValue <bool> isSet = heap.Push(6, 9); if (!isSet.Value) { return(false); } #endregion isSet = heap.Push(2, 8); if (!isSet.Value) { return(false); } isSet = heap.Push(4, 7); if (!isSet.Value) { return(false); } #region 获取数据数量 AutoCSer.CacheServer.ReturnValue <int> count = heap.Count; if (count.Value != 3) { return(false); } #endregion #region 获取堆顶关键字 AutoCSer.CacheServer.ReturnValue <int> key = heap.GetTopKey(); if (key.Value != 2) { return(false); } #endregion #region 获取堆顶数据 AutoCSer.CacheServer.ReturnValue <int> value = heap.GetTopValue(); if (value.Value != 8) { return(false); } #endregion #region 除堆顶数据 isSet = heap.PopTop(); if (!isSet.Value) { return(false); } #endregion #region 除堆顶数据并返回关键字 key = heap.GetPopTopKey(); if (key.Value != 4) { return(false); } #endregion #region 除堆顶数据并返回数据 value = heap.GetPopTopValue(); if (value.Value != 9) { return(false); } #endregion count = heap.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } return(true); }
/// <summary> /// 测试回调 /// </summary> /// <param name="value"></param> protected void setCallback(AutoCSer.CacheServer.ReturnValue <bool> value) { setCallback(value.Value); }
/// <summary> /// 数组测试 /// </summary> /// <param name="client"></param> /// <returns></returns> internal static bool TestCase(AutoCSer.CacheServer.Client client) { #region 创建名称为 Array 的数组缓存 Array <ValueDictionary <int, int> > array = client.GetOrCreateDataStructure <Array <ValueDictionary <int, int> > >("Array").Value; if (array == null) { return(false); } #endregion #region 创建或者获取子节点 ValueDictionary <int, int> dictionary = array.GetOrCreate(1).Value; if (dictionary == null) { return(false); } #endregion #region 判断第一个节点是否可用 AutoCSer.CacheServer.ReturnValue <bool> isNode = array.IsNode(1); if (!isNode.Value) { return(false); } #endregion if (!ValueDictionary.TestCase(dictionary)) { return(false); } #region 创建短路径 AutoCSer.CacheServer.ShortPath.Dictionary <int, int> shortPathDictionary = dictionary.CreateShortPath().Value; if (shortPathDictionary == null) { return(false); } #endregion if (!ValueDictionary.TestCase(shortPathDictionary)) { return(false); } #region 获取数组已使用长度 AutoCSer.CacheServer.ReturnValue <int> count = array.Count; if (count.Value != 2) { return(false); } #endregion #region 清除所有数据 AutoCSer.CacheServer.ReturnValue <bool> isClear = array.Clear(); if (!isClear.Value) { return(false); } count = array.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } #endregion return(true); }
/// <summary> /// 搜索树字典测试 /// </summary> /// <param name="client"></param> /// <returns></returns> internal static bool TestCase(AutoCSer.CacheServer.Client client) { #region 创建名称为 ValueSearchTreeDictionary 的搜索树字典缓存 ValueSearchTreeDictionary <int, int> dictionary = client.GetOrCreateDataStructure <ValueSearchTreeDictionary <int, int> >("ValueSearchTreeDictionary").Value; if (dictionary == null) { return(false); } #endregion #region dictionary[1] = 9; AutoCSer.CacheServer.ReturnValue <bool> isSet = dictionary.Set(1, 9); if (!isSet.Value) { return(false); } #endregion #region 判断关键字 1 是否存在 AutoCSer.CacheServer.ReturnValue <bool> isKey = dictionary.ContainsKey(1); if (!isKey.Value) { return(false); } #endregion #region 获取关键字为 1 的数据 AutoCSer.CacheServer.ReturnValue <int> value = dictionary.Get(1); if (value.Value != 9) { return(false); } #endregion #region 获取关键字为 1 的数字更新 AutoCSer.CacheServer.OperationUpdater.Number <int> number1 = dictionary.GetNumberUpdater(1); #endregion #region 关键字为 1 的数据 +2 value = number1 + 2; if (value.Value != 11) { return(false); } #endregion #region 关键字为 1 的数据 -5 value = number1 - 5; if (value.Value != 6) { return(false); } #endregion #region 获取关键字为 1 的数据 value = dictionary.Get(1); if (value.Value != 6) { return(false); } #endregion #region dictionary[3] = 8; isSet = dictionary.Set(3, 8); if (!isSet.Value) { return(false); } #endregion #region 获取逆序分页数据 AutoCSer.CacheServer.ReturnValue <int[]> page = dictionary.GetPageDesc(1, 10); if (page.Value == null || page.Value.Length != 2 || page.Value[0] != 8 || page.Value[1] != 6) { return(false); } #endregion #region 获取字典数据数量 AutoCSer.CacheServer.ReturnValue <int> count = dictionary.Count; if (count.Value != 2) { return(false); } #endregion #region 除关键字为 1 的数据 AutoCSer.CacheServer.ReturnValue <bool> isRemove = dictionary.Remove(1); if (!isRemove.Value) { return(false); } #endregion isRemove = dictionary.Remove(3); if (!isRemove.Value) { return(false); } count = dictionary.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } return(true); }
/// <summary> /// 链表测试 /// </summary> /// <param name="link"></param> /// <returns></returns> internal static bool TestCase(Link <int> link) { #region 链表尾部追加数据 3,链表结果为 3 AutoCSer.CacheServer.ReturnValue <bool> isSet = link.Append(3); if (!isSet.Value) { return(false); } #endregion #region 在第 1 个元素之前插入数据 1,链表结果为 1 -> 3 isSet = link.InsertBefore(0, 1); if (!isSet.Value) { return(false); } #endregion #region 在倒数第 1 个元素之前插入数据 1,链表结果为 1 -> 2 -> 3 isSet = link.InsertBefore(-1, 2); if (!isSet.Value) { return(false); } #endregion #region 在倒数第 1 个元素之后插入数据 5,链表结果为 1 -> 2 -> 3 -> 5 isSet = link.InsertAfter(-1, 5); if (!isSet.Value) { return(false); } #endregion #region 在第 3 个元素之后插入数据 4,链表结果为 1 -> 2 -> 3 -> 4 -> 5 isSet = link.InsertAfter(2, 4); if (!isSet.Value) { return(false); } #endregion #region 获取链表长度 AutoCSer.CacheServer.ReturnValue <int> count = link.Count; if (count.Value != 5) { return(false); } #endregion #region 获取第 3 个数据 AutoCSer.CacheServer.ReturnValue <int> value = link.Get(2); if (value.Value != 3) { return(false); } #endregion #region 获取倒数第 2 个数据 value = link.Get(-2); if (value.Value != 4) { return(false); } #endregion #region 弹出第一个数据,链表结果为 2 -> 3 -> 4 -> 5 value = link.Dequeue(); if (value.Value != 1) { return(false); } #endregion #region 弹出最后一个数据,链表结果为 2 -> 3 -> 4 value = link.StackPop(); if (value.Value != 5) { return(false); } #endregion #region 获取并删除第 2 个数据,链表结果为 2 -> 4 value = link.GetRemove(1); if (value.Value != 3) { return(false); } #endregion #region 除倒数第 2 个数据,链表结果为 4 AutoCSer.CacheServer.ReturnValue <bool> isRemove = link.Remove(-2); if (!isRemove.Value) { return(false); } #endregion count = link.Count; if (count.Value != 1) { return(false); } isRemove = link.Clear(); if (!isRemove.Value) { return(false); } count = link.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } return(true); }
/// <summary> /// 字典测试 /// </summary> /// <param name="dictionary"></param> /// <returns></returns> internal static bool TestCase(ValueDictionary <int, int> dictionary) { #region dictionary[1] = 9; AutoCSer.CacheServer.ReturnValue <bool> isSet = dictionary.Set(1, 9); if (!isSet.Value) { return(false); } #endregion #region 判断关键字 1 是否存在 AutoCSer.CacheServer.ReturnValue <bool> isKey = dictionary.ContainsKey(1); if (!isKey.Value) { return(false); } #endregion #region 获取关键字为 1 的数据 AutoCSer.CacheServer.ReturnValue <int> value = dictionary.Get(1); if (value.Value != 9) { return(false); } #endregion #region 获取关键字为 1 的数字更新 AutoCSer.CacheServer.OperationUpdater.Integer <int> integer = dictionary.GetIntegerUpdater(1); #endregion #region 关键字为 1 的数据 ^2 value = integer ^ 2; if (value.Value != 11) { return(false); } #endregion #region 关键字为 1 的数据 &7 value = integer & 7; if (value.Value != 3) { return(false); } #endregion #region 关键字为 1 的数据 +3 value = integer.Number + 3; if (value.Value != 6) { return(false); } #endregion #region 获取关键字为 1 的数据 value = dictionary.Get(1); if (value.Value != 6) { return(false); } #endregion #region 获取字典数据数量 AutoCSer.CacheServer.ReturnValue <int> count = dictionary.Count; if (count.Value != 1) { return(false); } #endregion #region 除关键字为 1 的数据 AutoCSer.CacheServer.ReturnValue <bool> isRemove = dictionary.Remove(1); if (!isRemove.Value) { return(false); } count = dictionary.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } #endregion return(true); }
/// <summary> /// 字典测试 /// </summary> /// <param name="client"></param> /// <returns></returns> internal static bool TestCase(AutoCSer.CacheServer.Client client) { #region 创建名称为 Dictionary 的字典缓存 Dictionary <int, Link <int> > dictionary = client.GetOrCreateDataStructure <Dictionary <int, Link <int> > >("Dictionary").Value; if (dictionary == null) { return(false); } #endregion #region 创建或者获取关键字为 1 的子节点 Link <int> link = dictionary.GetOrCreate(1).Value; if (link == null) { return(false); } #endregion #region 判断是否存在关键字为 1 的子节点 AutoCSer.CacheServer.ReturnValue <bool> isNode = dictionary.ContainsKey(1); if (!isNode.Value) { return(false); } #endregion if (!Link.TestCase(link)) { return(false); } #region 创建短路径 AutoCSer.CacheServer.ShortPath.Link <int> shortPathLink = link.CreateShortPath().Value; if (shortPathLink == null) { return(false); } #endregion if (!Link.TestCase(shortPathLink)) { return(false); } #region 获取字典数据数量 AutoCSer.CacheServer.ReturnValue <int> count = dictionary.Count; if (count.Value != 1) { return(false); } #endregion #region 除关键字为 1 的数据 AutoCSer.CacheServer.ReturnValue <bool> isRemove = dictionary.Remove(1); if (!isRemove.Value) { return(false); } count = dictionary.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } #endregion return(true); }
/// <summary> /// 搜索树字典测试 /// </summary> /// <param name="client"></param> /// <returns></returns> internal static bool TestCase(AutoCSer.CacheServer.Client client) { #region 创建名称为 SearchTreeDictionary 的搜索树字典缓存 SearchTreeDictionary <int, ValueArray <int> > dictionary = client.GetOrCreateDataStructure <SearchTreeDictionary <int, ValueArray <int> > >("SearchTreeDictionary").Value; if (dictionary == null) { return(false); } #endregion #region 创建或者获取关键字为 1 的子节点 ValueArray <int> array = dictionary.GetOrCreate(1).Value; if (array == null) { return(false); } #endregion if (!ValueArray.TestCase(array)) { return(false); } #region 创建短路径 AutoCSer.CacheServer.ShortPath.Array <int> shortPathArray = array.CreateShortPath().Value; if (shortPathArray == null) { return(false); } #endregion if (!ValueArray.TestCase(shortPathArray)) { return(false); } #region 判断关键字 1 是否存在 AutoCSer.CacheServer.ReturnValue <bool> isKey = dictionary.ContainsKey(1); if (!isKey.Value) { return(false); } #endregion #region 获取字典数据数量 AutoCSer.CacheServer.ReturnValue <int> count = dictionary.Count; if (count.Value != 1) { return(false); } #endregion #region 除关键字为 1 的数据 AutoCSer.CacheServer.ReturnValue <bool> isRemove = dictionary.Remove(1); if (!isRemove.Value) { return(false); } count = dictionary.Count; if (count.Type != AutoCSer.CacheServer.ReturnType.Success || count.Value != 0) { return(false); } #endregion return(true); }