/// <summary> /// 去除顺序表的重复项 /// </summary> /// <param name="la"></param> static SequenceList <int> PurgeList(SequenceList <int> la) { SequenceList <int> myList = new SequenceList <int>(la.MaxSize); int j = 0; bool ifHas = false; for (int i = 0; i < la.GetLength(); i++) { j = 0; ifHas = false; while (j < la.GetLength()) { if (i != j && la[i] == la[j]) { ifHas = true; break; } j++; } if (ifHas == false) { myList.Append(la[i]); } } return(myList); }
private static void MergeListProTest() { Console.WriteLine(); Console.WriteLine(Hbb0b0.Trace.FunctionCallHelper.GetCurrentCallFunctionName(null)); Console.WriteLine(); SequenceList <int?> La = new SequenceList <int?>(3); La.Append(1); La.Append(5); La.Append(8); SequenceList <int?> Lb = new SequenceList <int?>(5); Lb.Append(1); Lb.Append(2); Lb.Append(7); Lb.Append(8); Lb.Append(9); Console.WriteLine("----Input data begin-----"); Show <int?>(La); Console.WriteLine(); Show <int?>(Lb); Console.WriteLine(); Console.WriteLine("---End-----"); SequenceList <int?> result = MergeListPro(La, Lb); Show <int?>(result); }
private static void PurgeListTest() { Console.WriteLine(); Console.WriteLine(Hbb0b0.Trace.FunctionCallHelper.GetCurrentCallFunctionName(null)); Console.WriteLine(); SequenceList <int> purgeList = new SequenceList <int>(20); purgeList.Append(1); purgeList.Append(9); purgeList.Append(7); purgeList.Append(3); purgeList.Append(2); purgeList.Append(1); purgeList.Append(3); purgeList.Append(4); purgeList.Append(3); Console.WriteLine("----Input data begin-----"); Show <int>(purgeList); Console.WriteLine(); Console.WriteLine("---End-----"); SequenceList <int> result = PurgeList(purgeList); Show <int>(result); }
/// <summary> /// 倒置顺序表 /// </summary> /// <param name="la">顺序表la</param> /// <param name="lb">顺序表lb</param> static SequenceList <int?> MergeListPro(SequenceList <int?> la, SequenceList <int?> lb) { SequenceList <int?> lc = new SequenceList <int?>(la.MaxSize + lb.MaxSize); int a = 0, b = 0; //注意:一次循环插入la,lb中各一个数据 while (a < la.GetLength() && b < lb.GetLength()) { if (la[a] < lb[b]) { lc.Append(la[a++]); } else { lc.Append(lb[b++]); } } //la 没有循环完毕,把剩余的la添加到lc中 while (a < la.GetLength()) { lc.Append(la[a++]); } //lb 没有循环完毕,把剩余的lb添加到lc中 while (b < lb.GetLength()) { lc.Append(lb[b++]); } return(lc); }
/// <summary> /// Gets the command for the specified sequence. /// </summary> /// <param name="seq">The sequence.</param> /// <returns>Command string of the specified sequence.</returns> private static string Command(SequenceList seq) { switch (seq) { case SequenceList.NoShutdown: return("shutdown /a"); case SequenceList.Shutdown: return("shutdown /f /s /t 0"); case SequenceList.Restart: return("shutdown /f /r /t 0"); case SequenceList.Sleep: return("rundll32.exe powrprof.dll,SetSuspendState 0,1,0"); case SequenceList.Hibernate: return("rundll32.exe PowrProf.dll,SetSuspendState"); case SequenceList.LogOff: return("shutdown /f /l"); case SequenceList.LockUser: return("rundll32.exe user32.dll, LockWorkStation"); } return(""); }
/// <summary> /// 显示顺序表 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="myList"></param> private static void Show <T>(SequenceList <T> myList) { Console.WriteLine(); for (int i = 0; i <= myList.Last; i++) { Console.Write(myList[i] + ",");; } }
/// <summary> ///SequenceList`1 构造函数 的测试 ///</summary> public void SequenceListConstructorTestHelper <T>() { int size = 5; // TODO: 初始化为适当的值 SequenceList <T> target = new SequenceList <T>(size); //Assert.Inconclusive("TODO: 实现用来验证目标的代码"); Assert.AreEqual(-1, target.Last); }
private void fillList() { RoomsDetection roomsDetection = new RoomsDetection(); if (_context.MovementSekv.Any()) { var movSekvList = _context.MovementSekv.ToList(); foreach (var movSekv in movSekvList) { DateTime convertedDate = DateTime.Parse(movSekv.TimeStamp); Izby izba = null; String izbaName = ""; try { izba = _context.Rooms.Where(t => t.IzbaID == movSekv.IzbyFK).First(); izbaName = izba.Nazov; } catch (Exception e) { izbaName = "Vonku"; } string alert = "NA"; if (movSekv.Upozornenie_Cas != 0) { alert = "Čas"; } else if (movSekv.Upozornenie_Hranica != 0) { alert = "Hranica"; } MovementObj movObj = new MovementObj { PohId = movSekv.PohSekvId, RoomName = izbaName, Alert = alert, LongDate = convertedDate.ToLongDateString(), Date = convertedDate.ToShortDateString(), Time = convertedDate.ToLongTimeString(), Duration = movSekv.Cas_Zotrvania, xValue = movSekv.Xhodnota, yValue = movSekv.Yhodnota }; SequenceList.Add(movObj); } fillPageWithSequence(SequenceList.Last()); } else { MovAlert = "Neexistuje žiadna sekvencia"; } SequenceList = new ObservableCollection <MovementObj>(SequenceList.Reverse()); }
public void AddAllSequences(SequenceList newSequences) { if (newSequences != null) { foreach (Sequence sequence in newSequences.listSequence) { SequenceList.Add(sequence); } } }
public static SequenceList FramesToSequenceList(List <List <Frame> > frames) { SequenceList seqList = new SequenceList(); for (int i = 0; i < frames.Count; i++) { seqList.sequences.Add(FramesToSequence(frames[i])); } return(seqList); }
/// <summary> ///Last 的测试 ///</summary> public void LastTestHelper <T>() { int size = 0; // TODO: 初始化为适当的值 SequenceList <T> target = new SequenceList <T>(size); // TODO: 初始化为适当的值 int expected = -1; // TODO: 初始化为适当的值 int actual; actual = target.Last; Assert.AreEqual(expected, actual); }
public (int, string) GetNextSequence() { var random = new Random(); var newList = SequenceList.Where(x => !UsedSequences.Contains(x)); var rnd = random.Next(0, newList.Count()); var result = newList.ToList()[rnd]; UsedSequences.Add(result); return(UsedSequences.Count - 1, result); }
/// <summary> ///IsFull 的测试 ///</summary> public void IsFullTestHelper <T>() { int size = 0; // TODO: 初始化为适当的值 SequenceList <T> target = new SequenceList <T>(size); // TODO: 初始化为适当的值 bool expected = true; // TODO: 初始化为适当的值 bool actual; actual = target.IsFull(); Assert.AreEqual(expected, actual); }
// //编写测试时,还可使用以下属性: // //使用 ClassInitialize 在运行类中的第一个测试前先运行代码 //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //使用 ClassCleanup 在运行完类中的所有测试后再运行代码 //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //使用 TestInitialize 在运行每个测试前先运行代码 //[TestInitialize()] //public void MyTestInitialize() //{ //} // //使用 TestCleanup 在运行完每个测试后运行代码 //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///MaxSize 的测试 ///</summary> public void MaxSizeTestHelper <T>() { int size = 5; // TODO: 初始化为适当的值 SequenceList <T> target = new SequenceList <T>(size); // TODO: 初始化为适当的值 int expected = 5; // TODO: 初始化为适当的值 int actual; actual = target.MaxSize; Assert.AreEqual(expected, actual); }
/// <summary> /// 倒置顺序表 /// </summary> /// <param name="sqList"></param> static SequenceList <int> ReverseList(SequenceList <int> sqList) { SequenceList <int> myList = new SequenceList <int>(sqList.MaxSize); int length = sqList.GetLength(); for (int i = 1; i <= length; i++) { myList.Append(sqList[length - i]); } return(myList); }
/// <summary> ///Data 的测试 ///</summary> public void DataTestHelper <T>() { int size = 2; // TODO: 初始化为适当的值 SequenceList <T> target = new SequenceList <T>(size); // TODO: 初始化为适当的值 T[] expected = new T[2]; // TODO: 初始化为适当的值 T[] actual; actual = target.Data; Assert.AreEqual(expected.Length, actual.Length); }
protected override void Awake() { base.Awake(); m_RegistedUIObjects = new SequenceList <GameObject> (); for (int i = 0; i < m_UIObjects.Count; i++) { var uiAvatar = m_UIObjects [i]; uiAvatar.SetActive(false); m_RegistedUIObjects.Enqueue(uiAvatar); } }
/// <summary> /// Set the sequence to the specified sequence and type to Fast. /// </summary> /// <param name="seq">The sequence to be set.</param> internal static void Set(SequenceList seq) { Log.Write("Trying to change sequence."); if (currentSequence == seq) { OnErrorEvent(seq == SequenceList.NoShutdown ? "Already unset any sequence." : "There is a sequence already set."); return; } if (currentSequence > SequenceList.NoShutdown && seq > SequenceList.NoShutdown) { OnErrorEvent("There is a sequence already set."); return; } if (seq < SequenceList.NoShutdown || seq > SequenceList.LockUser) { OnErrorEvent("Setting to an invalid sequence."); return; } Stop(); if (seq == SequenceList.NoShutdown) { currentType = SequenceType.None; Log.Write("Successfully unset current sequence."); } else { alarm = new Alarm(2000); alarm.Expire += () => { ExecuteCommand(); Reset(); }; alarm.Start(); currentType = SequenceType.Fast; if (Config.Equals("alert", "1")) { AlertBox.Show("Sequence Changed!", "Will " + seq + " in a moment.", 1800); } Log.Write("Set sequence to " + currentType + " " + seq + "."); } currentSequence = seq; OnSequenceChangeEvent(new SequenceChangeEventArgs(CurrentSequence, CurrentType)); }
/// <summary> ///IsEmpty 的测试 ///</summary> public void IsEmptyTestHelper <T>() { int size = 1; // TODO: 初始化为适当的值 SequenceList <T> target = new SequenceList <T>(size); // TODO: 初始化为适当的值 bool expected = true; // TODO: 初始化为适当的值 bool actual; actual = target.IsEmpty(); Assert.AreEqual(expected, actual); target.Append(default(T)); Assert.AreEqual(false, target.IsEmpty()); }
/// <summary> ///Append 的测试 ///</summary> public void AppendTestHelper <T>() { int size = 0; // TODO: 初始化为适当的值 SequenceList <T> target = new SequenceList <T>(size); // TODO: 初始化为适当的值 T node = default(T); // TODO: 初始化为适当的值 try { target.Append(node); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(DataStructureException)); } }
/// <summary> ///Last 的测试 ///</summary> public void LastTestHelperString() { int size = 3; // TODO: 初始化为适当的值 SequenceList <string> target = new SequenceList <string>(size); // TODO: 初始化为适当的值 int expected = -1; // TODO: 初始化为适当的值 int actual; actual = target.Last; Assert.AreEqual(expected, actual); target.Append("a"); Assert.AreEqual(0, target.Last); target.Append("b"); Assert.AreEqual(1, target.Last); }
/// <summary> ///Clear 的测试 ///</summary> public void ClearTestHelper <T>() { int size = 10; // TODO: 初始化为适当的值 SequenceList <T> target = new SequenceList <T>(size); // TODO: 初始化为适当的值 target.Append(default(T)); target.Clear(); Assert.AreEqual(-1, target.Last); Assert.AreEqual(0, target.GetLength()); //Assert.IsNull(target.Data); }
/// <summary> ///GetLength 的测试 ///</summary> public void GetLengthTestHelper <T>() { int size = 5; // TODO: 初始化为适当的值 SequenceList <T> target = new SequenceList <T>(size); // TODO: 初始化为适当的值 int expected = 0; // TODO: 初始化为适当的值 int actual; actual = target.GetLength(); Assert.AreEqual(expected, actual); target.Append(default(T)); Assert.AreEqual(1, target.GetLength()); target.Append(default(T)); Assert.AreEqual(2, target.GetLength()); }
/// <summary> ///Locate 的测试 ///</summary> public void LocateTestHelper <T>() { int size = 0; // TODO: 初始化为适当的值 SequenceList <T> target = new SequenceList <T>(size); // TODO: 初始化为适当的值 T node = default(T); // TODO: 初始化为适当的值 int expected = 0; // TODO: 初始化为适当的值 int actual; try { actual = target.Locate(node); } catch (Exception myEx) { Assert.IsInstanceOfType(myEx, typeof(DataStructureException)); } }
public void IsFullTestHelperInt() { int size = 5; // TODO: 初始化为适当的值 SequenceList <int> target = new SequenceList <int>(size); // TODO: 初始化为适当的值 bool expected = false; // TODO: 初始化为适当的值 bool actual; actual = target.IsFull(); Assert.AreEqual(expected, actual); for (int i = 0; i < size; i++) { target.Append(i); } Assert.IsTrue(target.IsFull()); }
public void Print() { var students = new Student[] { new Student { No = 1, Name = "李1", Score = 22.1 }, new Student { No = 2, Name = "李2", Score = 32.3 }, new Student { No = 3, Name = "李3", Score = 42.5 } }; var sqList = new SequenceList <Student>(students); sqList.Print(); }
public void GetIndex() { var students = new Student[] { new Student { No = 1, Name = "李1", Score = 22.1 }, new Student { No = 2, Name = "李2", Score = 32.3 }, new Student { No = 3, Name = "李3", Score = 42.5 } }; var sqList = new SequenceList <Student>(students); var index = sqList.GetIndex(students[1]); }
/// <summary> /// 合并顺序表 /// </summary> /// <param name="la"></param> /// <param name="lb"></param> static SequenceList <int?> MergeList(SequenceList <int?> la, SequenceList <int?> lb) { //合并后的表长度 length=la.MaxSize+lb.MaxSize-1 int length = la.MaxSize + lb.MaxSize; SequenceList <int?> lc = new SequenceList <int?>(length); //复制La到myList for (int i = 0; i < la.GetLength(); i++) { lc.Append(la[i]); } //Lb中的值与myList比较,如果当前值Lb[i]比myList的某个位置的值相等或等于, //那么lb[i]插入到mylist对应的位置中,否则lb[i]放到mylist的末尾。 for (int i = 0; i < lb.GetLength(); i++) { //是否找到lb[i]<=mylist[j]的标志 bool find = false; //开始查找位置 int startLocation = 0; for (int j = startLocation; j < length; j++) { if (lc[j].HasValue && lb[i] <= lc[j]) { find = true; lc.Insert(lb[i], j); startLocation = j; break; } } //如果找不到 if (!find) { lc.Append(lb[i]); } } return(lc); }
/// <summary> ///InsertAfter 的测试 ///</summary> public void InsertTestHelperString() { int size = 10; // TODO: 初始化为适当的值 SequenceList <string> target = new SequenceList <string>(size); // TODO: 初始化为适当的值 try { target.Insert("A", -1); } catch (Exception myEx) { Assert.IsInstanceOfType(myEx, typeof(DataStructureException)); } try { target.Insert("A", 10); } catch (Exception myEx) { Assert.IsInstanceOfType(myEx, typeof(DataStructureException)); } target.Append("a"); target.Append("d"); target.Append("f"); target.Insert("b", 0); target.Insert("c", 1); target.Insert("x", 4); List <string> list = new List <string>() { "b", "c", "a", "d", "x", "f" }; for (int i = 0; i < list.Count; i++) { Assert.AreEqual(list[i], target[i]); } }
/// <summary> ///Locate 的测试 ///</summary> public void LocateTestHelperString() { int size = 10; // TODO: 初始化为适当的值 SequenceList <string> target = new SequenceList <string>(size); // TODO: 初始化为适当的值 string str1 = "AAA"; string str2 = "aaa"; target.Append(str1); target.Append(str2); target.Append(str2); Assert.AreEqual(0, target.Locate(str1)); Assert.AreEqual(1, target.Locate(str2)); Assert.AreEqual(1, target.Locate("aaa")); Assert.AreEqual(-1, target.Locate("a")); }