Files

165 lines
5.6 KiB
C#
Raw Permalink Normal View History

2023-03-12 12:32:26 +01:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using TimetableDesigner.Core;
namespace TimetableDesigner.Tests
{
[TestClass]
public class TimetableTest
{
[TestMethod]
public void CreateValidSlotTest()
{
2023-03-12 17:52:17 +01:00
TimetableSpan slot = new TimetableSpan(new TimeOnly(8, 0), new TimeOnly(9, 0));
2023-03-12 12:32:26 +01:00
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void CreateInvalidSlotTest()
{
2023-03-12 17:52:17 +01:00
TimetableSpan slot = new TimetableSpan(new TimeOnly(9, 0), new TimeOnly(8, 0));
2023-03-12 12:32:26 +01:00
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void CreateSlotWithZeroLengthTest()
{
2023-03-12 17:52:17 +01:00
TimetableSpan slot = new TimetableSpan(new TimeOnly(8, 0), new TimeOnly(8, 0));
2023-03-12 12:32:26 +01:00
Assert.Fail();
}
[TestMethod]
public void CreateModelTest()
{
TimetableTemplate model = new TimetableTemplate();
}
[TestMethod]
public void AddDayTest()
{
TimetableTemplate model = new TimetableTemplate();
2023-05-07 17:39:24 +02:00
TimetableDay day = new TimetableDay("Monday");
2023-03-12 12:32:26 +01:00
2023-05-07 17:39:24 +02:00
model.Days.Add(day);
2023-03-12 12:32:26 +01:00
Assert.AreEqual(1, model.Days.Count());
Assert.AreEqual(day, model.Days.ToList()[0]);
}
[TestMethod]
public void AddSlotTest()
{
TimetableTemplate model = new TimetableTemplate();
2023-03-12 17:52:17 +01:00
TimetableSpan slot = new TimetableSpan(new TimeOnly(8, 0), new TimeOnly(9, 0));
2023-03-12 12:32:26 +01:00
2023-05-07 17:39:24 +02:00
model.Slots.Add(slot);
2023-03-12 12:32:26 +01:00
Assert.AreEqual(1, model.Slots.Count());
2023-03-12 17:52:17 +01:00
Assert.AreEqual(new TimetableSpan(new TimeOnly(8, 0), new TimeOnly(9, 0)), model.Slots.ToList()[0]);
2023-03-12 12:32:26 +01:00
}
[TestMethod]
public void AddNoCollidingSlotsTest()
{
TimetableTemplate model = new TimetableTemplate();
2023-03-12 17:52:17 +01:00
TimetableSpan slot1 = new TimetableSpan(new TimeOnly(8, 15), new TimeOnly(9, 0));
TimetableSpan slot2 = new TimetableSpan(new TimeOnly(9, 15), new TimeOnly(10, 0));
2023-03-12 12:32:26 +01:00
2023-05-07 17:39:24 +02:00
model.Slots.Add(slot1);
model.Slots.Add(slot2);
2023-03-12 12:32:26 +01:00
Assert.AreEqual(2, model.Slots.Count());
2023-03-12 17:52:17 +01:00
Assert.AreEqual(new TimetableSpan(new TimeOnly(8, 15), new TimeOnly(9, 0)), model.Slots.ToList()[0]);
Assert.AreEqual(new TimetableSpan(new TimeOnly(9, 15), new TimeOnly(10, 0)), model.Slots.ToList()[1]);
2023-03-12 12:32:26 +01:00
}
[TestMethod]
public void AddSlotsWithoutBreakTest()
{
TimetableTemplate model = new TimetableTemplate();
2023-03-12 17:52:17 +01:00
TimetableSpan slot1 = new TimetableSpan(new TimeOnly(8, 0), new TimeOnly(9, 0));
TimetableSpan slot2 = new TimetableSpan(new TimeOnly(9, 0), new TimeOnly(10, 0));
2023-03-12 12:32:26 +01:00
2023-05-07 17:39:24 +02:00
model.Slots.Add(slot1);
model.Slots.Add(slot2);
2023-03-12 12:32:26 +01:00
Assert.AreEqual(2, model.Slots.Count());
2023-03-12 17:52:17 +01:00
Assert.AreEqual(new TimetableSpan(new TimeOnly(8, 0), new TimeOnly(9, 0)), model.Slots.ToList()[0]);
Assert.AreEqual(new TimetableSpan(new TimeOnly(9, 0), new TimeOnly(10, 0)), model.Slots.ToList()[1]);
2023-03-12 12:32:26 +01:00
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void AddCollidingSlotsTest()
{
TimetableTemplate model = new TimetableTemplate();
2023-03-12 17:52:17 +01:00
TimetableSpan slot1 = new TimetableSpan(new TimeOnly(8, 0), new TimeOnly(9, 30));
TimetableSpan slot2 = new TimetableSpan(new TimeOnly(8, 30), new TimeOnly(10, 0));
2023-03-12 12:32:26 +01:00
2023-05-07 17:39:24 +02:00
model.Slots.Add(slot1);
model.Slots.Add(slot2);
2023-03-12 12:32:26 +01:00
Assert.Fail();
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void AddBetweenCollidingSlotsTest()
{
TimetableTemplate model = new TimetableTemplate();
2023-03-12 17:52:17 +01:00
TimetableSpan slot1 = new TimetableSpan(new TimeOnly(8, 0), new TimeOnly(9, 0));
TimetableSpan slot2 = new TimetableSpan(new TimeOnly(10, 0), new TimeOnly(11, 0));
TimetableSpan slot3 = new TimetableSpan(new TimeOnly(8, 59), new TimeOnly(10, 1));
2023-03-12 12:32:26 +01:00
2023-05-07 17:39:24 +02:00
model.Slots.Add(slot1);
model.Slots.Add(slot2);
model.Slots.Add(slot3);
2023-03-12 12:32:26 +01:00
Assert.Fail();
}
[TestMethod]
public void SortSlotsTest()
{
TimetableTemplate model = new TimetableTemplate();
2023-03-12 17:52:17 +01:00
TimetableSpan slot1 = new TimetableSpan(new TimeOnly(12, 0), new TimeOnly(13, 0));
TimetableSpan slot2 = new TimetableSpan(new TimeOnly(8, 0), new TimeOnly(9, 0));
TimetableSpan slot3 = new TimetableSpan(new TimeOnly(10, 0), new TimeOnly(11, 0));
TimetableSpan slot4 = new TimetableSpan(new TimeOnly(14, 0), new TimeOnly(15, 0));
TimetableSpan slot5 = new TimetableSpan(new TimeOnly(13, 0), new TimeOnly(14, 0));
TimetableSpan slot6 = new TimetableSpan(new TimeOnly(9, 0), new TimeOnly(10, 0));
TimetableSpan slot7 = new TimetableSpan(new TimeOnly(11, 0), new TimeOnly(12, 0));
2023-03-12 12:32:26 +01:00
2023-05-07 17:39:24 +02:00
model.Slots.Add(slot1);
model.Slots.Add(slot2);
model.Slots.Add(slot3);
model.Slots.Add(slot4);
model.Slots.Add(slot5);
model.Slots.Add(slot6);
model.Slots.Add(slot7);
2023-03-12 12:32:26 +01:00
2023-03-12 17:52:17 +01:00
List<TimetableSpan> slots = model.Slots.ToList();
2023-03-12 12:32:26 +01:00
2023-03-12 17:52:17 +01:00
TimetableSpan testSlot = slots[0];
2023-03-12 12:32:26 +01:00
for (int i = 1; i < slots.Count; i++)
{
if (testSlot.To > slots[i].From)
{
Assert.Fail();
}
testSlot = slots[i];
}
}
}
}