public void EditEventTest() { string commandline = "edit 0 lala project meeting 13/12 9pm"; // TODO: Initialize to an appropriate value string commandline1 = "project meeting 12/12 6pm"; NewUi ui = new NewUi(); ui.ProcessCommandline(commandline1); int index = 0; // TODO: Initialize to an appropriate value int indexExpected = 0; // TODO: Initialize to an appropriate value NewUi.EventInfo info = new NewUi.EventInfo(); // TODO: Initialize to an appropriate value NewUi.EventInfo infoExpected = new NewUi.EventInfo(); // TODO: Initialize to an appropriate value bool expected = false; // TODO: Initialize to an appropriate value bool actual; actual = Parser.EditEvent(commandline, ref index, ref info); Assert.AreEqual(indexExpected, index); Assert.AreEqual(infoExpected, info); Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); }
public void AddEventTest() { string commandline = "talk by Dr. Lim at 4pm thur alarm 3pm"; // TODO: Initialize to an appropriate value NewUi.EventInfo info = new NewUi.EventInfo(); // TODO: Initialize to an appropriate value NewUi.EventInfo infoExpected = new NewUi.EventInfo(); // TODO: Initialize to an appropriate value bool expected = true; // TODO: Initialize to an appropriate value bool actual; actual = Parser.AddEvent(commandline, ref info); Assert.AreEqual(info.eventName, "talk by Dr. Lim"); Assert.AreEqual(info.startDate.DayOfWeek, DayOfWeek.Thursday); Assert.AreEqual(info.endDate.DayOfWeek, DayOfWeek.Thursday); Assert.AreEqual(info.startTime, new DateTime(1, 1, 1, 16, 0, 0)); Assert.AreEqual(info.endTime, new DateTime(1, 1, 1, 16, 0, 0)); Assert.AreEqual(info.urgent, false); Assert.AreEqual(info.alarm, true); Assert.AreEqual(info.alarmTime, new DateTime(info.endDate.Year, info.endDate.Month, info.endDate.Day, 15, 0, 0)); Assert.AreEqual(info.freeDay, false); Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); }
public static bool EditEvent(string commandline, ref int index, ref NewUi.EventInfo info) { Debug.Assert(commandline != null, "Commandline was null in EditEvent function in Parser"); string[] words = SplitWords(commandline); int j = 0; bool found = false; if (Int32.TryParse(words[0], out index)) { j = 1; for (int i = 1; i < words.Length; i = j) { found = false; if (dateKey.Contains(words[i].ToLower()) || days.Contains(words[i].ToLower())) { j = FoundDateKey(words, i, ref info.startDate, ref info.endDate); found = INotEqualJ(i, j); } if (timeKey.Contains(words[i].ToLower()) && !found) { j = FoundTimeKey(words, i, ref info.startTime, ref info.endTime); found = INotEqualJ(i, j); } if (otherKey.Contains(words[i].ToLower()) && !found) { j = FoundOtherKey(words, i, ref info.urgent, ref info.alarm, ref info.alarmTime, ref info.freeDay, ref info.startDate, ref info.endDate); found = INotEqualJ(i, j); } else { if (char.IsDigit(words[i][0])) { if (IsTimeRelated(words, i)) { j = FoundTimeKey(words, i, ref info.startTime, ref info.endTime); } else { j = j = FoundDateKey(words, i, ref info.startDate, ref info.endDate); } } } if (i == j) { if (info.eventName == null) { info.eventName = words[j++]; } else { info.eventName += ' ' + words[j++]; } } } return(true); } else { return(false); } }
public static bool AddEvent(string commandline, ref NewUi.EventInfo info) { string[] words = SplitWords(commandline); int length = words.Length; int j = 0; bool found = false; for (int i = 0; i < length; i = j) { found = false; if (dateKey.Contains(words[i].ToLower()) || days.Contains(words[i].ToLower())) { j = FoundDateKey(words, i, ref info.startDate, ref info.endDate); found = INotEqualJ(i, j); } if (timeKey.Contains(words[i].ToLower()) && !found) { j = FoundTimeKey(words, i, ref info.startTime, ref info.endTime); found = INotEqualJ(i, j); } if (otherKey.Contains(words[i].ToLower()) && !found) { j = FoundOtherKey(words, i, ref info.urgent, ref info.alarm, ref info.alarmTime, ref info.freeDay, ref info.startDate, ref info.endDate); found = INotEqualJ(i, j); } else { if (char.IsDigit(words[i][0])) { if (IsTimeRelated(words, i)) { j = FoundTimeKey(words, i, ref info.startTime, ref info.endTime); } else { j = j = FoundDateKey(words, i, ref info.startDate, ref info.endDate); } } } if (i == j) { if (info.eventName == null) { info.eventName = words[j++]; } else { info.eventName += ' ' + words[j++]; } } } if (ValidEventInfo(ref info)) { return(true); } else { return(false); } }
private static bool ValidEventInfo(ref NewUi.EventInfo info) { bool isValid = true; if (info.startDate == empty || info.endDate.CompareTo(DateOnly(DateTime.Now)) >= 0) { if (string.IsNullOrWhiteSpace(info.eventName)) { info.eventName = "<unknown>"; } if (info.startTime == empty) { if (info.endTime != empty) { info.startTime = info.endTime; } else if (info.alarmTime != empty) { info.startTime = info.alarmTime; } else { info.endTime = EndOfDay(); } } if (info.alarm && info.alarmTime == empty) { info.alarmTime = info.startTime; } if (info.endTime == empty && info.startTime != empty) { info.endTime = info.startTime; } if (info.endDate == empty) { info.startDate = info.endDate = DateOnly(DateTime.Now); } else { if (info.startDate == empty) { info.startDate = DateOnly(DateTime.Now); } } if (info.alarm) { info.alarmTime = info.alarmTime.AddDays(info.endDate.Day - 1); info.alarmTime = info.alarmTime.AddMonths(info.endDate.Month - 1); info.alarmTime = info.alarmTime.AddYears(info.endDate.Year - 1); } } else { isValid = false; } if (info.endDate.CompareTo(info.startDate) < 0) { isValid = false; } if (info.endTime.CompareTo(info.startTime) < 0) { isValid = false; } return(isValid); }