public void Test_WeekNumber_ClashesWith_5() { var input1 = "1-7"; var input2 = "7-14"; var actual1 = WeekNumber.Parse(input1); var actual2 = WeekNumber.Parse(input2); Assert.True(actual1.IntersectWith(actual2)); }
private bool TryParseWeekAndVenue(ITokenStream ts, ref Slot resultSlot) { if (!ts.PreviousToken().IsPositiveNumberThatContainDecimalPoint() || !ts.NextToken().IsPossiblyVenuValue()) { return(false); } resultSlot.WeekNumber = WeekNumber.Parse(ts.CurrentToken().Value()); resultSlot.Venue = ts.NextToken().Value(); return(true); }
public void Test_WeekNumber_Parse_4() { var input = "1-3,7-9,11,13"; var expected = new WeekNumber(new List <int> { 1, 2, 3, 7, 8, 9, 11, 13 }); var actual = WeekNumber.Parse(input); Assert.True(expected.Equals(actual)); }
public void Test_WeekNumber_Parse_2() { var input = "1-5"; var expected = new WeekNumber(new List <int> { 1, 2, 3, 4, 5 }); var actual = WeekNumber.Parse(input); Assert.True(expected.Equals(actual)); }
public void Test_WeekNumber_Parse_5() { var input = "1-3,4,5,11-14"; var expected = new WeekNumber(new List <int> { 1, 2, 3, 4, 5, 11, 12, 13, 14 }); var actual = WeekNumber.Parse(input); Assert.True(expected.Equals(actual)); }
public void Test_TimetableRow_Add() { var input1 = new Slot(); input1.StartTime = Time.CreateTime_24HourFormat(8, 0); input1.EndTime = Time.CreateTime_24HourFormat(10, 0); input1.WeekNumber = WeekNumber.Parse("1-14"); var input2 = new Slot(); input2.StartTime = Time.CreateTime_24HourFormat(8, 0); input2.EndTime = Time.CreateTime_24HourFormat(9, 0); input2.WeekNumber = WeekNumber.Parse("2,5"); var ttr = new TimetableRow(); ttr.Add(input1); Assert.False(ttr.Add(input2)); }
public List <Slot> Parse(string html) { var result = new List <Slot>(); bool firstRowIsSkipped = false; string currentSubjectCode = ""; string currentSubjectName = ""; var doc = new HtmlDocument(); doc.LoadHtml(html); //get the subject table HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@id='overviewSector']/table"); foreach (HtmlNode table in nodes) { foreach (HtmlNode row in table.SelectNodes("tr")) { if (firstRowIsSkipped == false) //skip one row for the table header { firstRowIsSkipped = true; continue; } HtmlNodeCollection cells = row.SelectNodes("th|td"); if (cells == null) { continue; } if (cells.Count == 1) { var tokens = cells[0].InnerText.Split('-'); currentSubjectCode = tokens[0].Trim(); currentSubjectName = tokens[1].Split('[')[0].Trim().Beautify(); continue; } var slot = new Slot(); slot.Code = currentSubjectCode; slot.SubjectName = currentSubjectName; for (var k = 0; k < cells.Count; k++) { string data = cells[k].InnerText; switch (k) { case 0: if (data.IsInteger()) { slot.UID = int.Parse(data); } else { k = 4; //straight away to to parse Day } break; case 1: slot.Type = data; break; case 2: slot.Number = data; break; case 3: /*not storing this data*/ break; //class size case 4: slot.Day = Day.Parse(data); break; case 5: slot.TimePeriod = TimePeriod.Parse(data); break; case 6: /*not storing this data*/ break; //credit hour case 7: slot.WeekNumber = WeekNumber.Parse(data); break; case 8: slot.Venue = data; break; case 9: /*not storing this data*/ break; //remark } } result.Add(slot); } } return(result); }
private List <Slot> ParseAll(string html) { var result = new List <Slot>(); bool firstRowIsSkipped = false; string currentSubjectCode = ""; string currentSubjectName = ""; var doc = new HtmlDocument(); doc.LoadHtml(html); //get the subject table HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@id='overviewSector']/table"); if (nodes == null) { return(result); } foreach (HtmlNode table in nodes) { HtmlNodeCollection tableNodes = table.SelectNodes("tr") ?? table.SelectNodes("tbody")[0].SelectNodes("tr"); foreach (HtmlNode row in tableNodes) { if (firstRowIsSkipped == false) //skip one row for the table header { firstRowIsSkipped = true; continue; } HtmlNodeCollection cells = row.SelectNodes("th|td"); //select table header or table data if (cells == null) { continue; } if (cells.Count == 1) { var tokens = cells[0].InnerText.Split(new string[] { " - " }, StringSplitOptions.None); currentSubjectCode = tokens[0].Trim(); if (tokens.Length > 1) { currentSubjectName = tokens[1].Split('[')[0].Trim().Beautify(); } currentSubjectName = currentSubjectName.Replace("&", "&"); continue; } var slot = new Slot { Code = currentSubjectCode, SubjectName = currentSubjectName }; for (var k = 0; k < cells.Count; k++) { int offset = 0; if (row.GetAttributeValue("id", "").Contains("subRow")) { offset = 4; slot.UID = result.Last().UID; slot.Type = result.Last().Type; slot.Number = result.Last().Number; } string data = cells[k].InnerText.Trim(); switch (k + offset) { case 0: if (data.IsInteger()) { slot.UID = int.Parse(data); } break; case 1: slot.Type = data; break; case 2: slot.Number = data; break; case 3: /*not storing this data*/ break; //class size case 4: slot.Day = Day.Parse(data); break; case 5: slot.TimePeriod = TimePeriod.Parse(data); break; case 6: /*not storing this data*/ break; //credit hour case 7: slot.WeekNumber = WeekNumber.Parse(data); break; case 8: slot.Venue = data; break; case 9: /*not storing this data*/ break; //remark } } result.Add(slot); } } return(result); }