public List <List <Slot> > GetPossibleTimetables(Slot[] inputSlots)
        {
            var subjects = SubjectModel.Parse(inputSlots.ToList());
            Func <Slot[], List <List <Slot> > > permutator = Permutator.Run_v2_withoutConsideringWeekNumber;

            subjects = SortBySlotCount(subjects);
            var currentSlots        = subjects[0].Slots;
            var possibleCombination = permutator.Invoke(currentSlots.ToArray());
            var state = StateTable.GetStateOfDefinitelyOccupied(possibleCombination);
            int last  = subjects.Count - 1;

            for (int i = 1; i < subjects.Count; i++)
            {
                var originalSchema = new SubjectSchema(subjects[i].Slots);
                var filtrate       = StateTable.Filter(subjects[i].Slots, state);
                var newSchema      = new SubjectSchema(filtrate);
                if (!originalSchema.Equals(newSchema))
                {
                    return(null);
                }
                currentSlots.AddRange(filtrate);
                possibleCombination = permutator.Invoke(currentSlots.ToArray());
                if (i != last)
                {
                    state = StateTable.GetStateOfDefinitelyOccupied(possibleCombination);
                }
            }
            return(possibleCombination);
        }
Exemple #2
0
        private List <SubjectModel> GetInput(string raw)
        {
            var result   = new SlotParser().Parse(raw);
            var subjects = SubjectModel.Parse(result);

            return(subjects);
        }
 private SubjectModel Input3()
 {
     return(new SubjectListModel(
                SubjectModel.Parse(new HtmlSlotParser().Parse(
                                       Helper.RawStringOfTestFile("SampleData-FAM-2017-2ndSem.html"))),
                Permutator.Run_v2_withoutConsideringWeekNumber,
                new TaskRunnerForUnitTesting()).ToList()[0]);
 }
 private void InitializeExtraComponents()
 {
     _subjectModels = SubjectModel.Parse(_inputSlots);
     SelectSubjectPanel.SetDataContext(_subjectModels);
     SelectSubjectPanel.SetDrawerHost(this.DrawerHost);
     FavouriteButton.CheckedMessage   = "Added this timetable to favorites ";
     FavouriteButton.UncheckedMessage = "Removed this timetable from favorites";
 }
Exemple #5
0
        private void InitializeExtraComponents()
        {
            _subjectModels = SubjectModel.Parse(_inputSlots);
            var subjectListModel = new SubjectListModel(_subjectModels, _permutator,
                                                        new TaskRunnerForMainUi("Finding possible timetables . . ."));

            subjectListModel.NewListOfTimetablesGenerated += SubjectListModel_NewListOfTimetablesGenerated;
            SelectSubjectPanel.Initialize(subjectListModel);
            SelectSubjectPanel.SetDrawerHost(DrawerHost);
        }
        private ChooseSpecificSlotModel Input_2()
        {
            var subjectListModel = new SubjectListModel(SubjectModel.Parse(TestData.Default()), Permutator.Run_v2_withoutConsideringWeekNumber, new TaskRunnerForUnitTesting());
            var outputTimetables = new List <List <Slot> >();

            subjectListModel.NewListOfTimetablesGenerated += (sender, args) => {
                outputTimetables = (List <List <Slot> >)sender;
            };
            subjectListModel.SelectSubject("MPU3143"); //BMK2
            return(new ChooseSpecificSlotModel(subjectListModel.ToList().FindAll(x => x.IsSelected), Permutator.Run_v2_withoutConsideringWeekNumber));
        }
        public void Test_TimetableFinder_SortBySlotCount_1()
        {
            var input          = GetInput();
            var subjects       = SubjectModel.Parse(input);
            var timtableFinder = new TimetableFinder();
            var result         = timtableFinder.SortBySlotCount(subjects);

            for (int i = 0; i < result.Count; i++)
            {
                Console.WriteLine(result[i].Code + " " + result[i].Slots.Count);
            }
        }
        public void NavigateUsingArrowKeys_InitialState()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            Then Ali should see that the first subject in the list is highlighted
                ";
            var models = SubjectModel.Parse(TestData.TestSlots);
            var input  = new SubjectListModel(models);

            Assert.IsTrue(models[0].IsFocused, expectedBehaviour);
        }
        public void FilterSubject()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali search for 'ASSD'
            Then Ali shall see only one subject is visible to him
                ";
            var input = new SubjectListModel(SubjectModel.Parse(TestData.TestSlots));

            input.Search("ASSD");
            Assert.IsTrue(input.NumberOfVisibleSubject() == 1, expectedBehaviour);
        }
        public void SuggestiveText_1()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali search for 'bahsa'
            Then Ali shall see a suggestion 
                ";
            var input = new SubjectListModel(SubjectModel.Parse(TestData.TestSlots));

            input.Search("bahsa");
            Assert.IsTrue(input.IsFeedbackPanelVisible, expectedBehaviour);
        }
        public void SuggestiveText_2()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali search for 'bahsa'
            Then Ali shall see a suggestion suggesting 'Bahasa'
                ";
            var input = new SubjectListModel(SubjectModel.Parse(TestData.TestSlots));

            input.Search("bahsa");
            Assert.IsTrue(input.SuggestedText == "Bahasa", expectedBehaviour);
        }
        public void InitialState()
        {
            string behvaiour =
                @"
            Given Ali just loaded slots data (by logging in)
            Then Ali shall see only the SearchBox is visible 
                ";
            var input = new SubjectListModel(SubjectModel.Parse(TestData.TestSlots));

            Assert.IsFalse(input.IsErrorLabelVisible, behvaiour);
            Assert.IsFalse(input.IsFeedbackPanelVisible, behvaiour);
            Assert.IsFalse(input.IsHintLabelVisible, behvaiour);
        }
        public void VisibilityOfHintLabel_1()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali had type something in the search box
            Then Ali shall see the HintLabel
                ";
            var input = new SubjectListModel(SubjectModel.Parse(TestData.TestSlots));

            input.Search("something");
            Assert.IsTrue(input.IsHintLabelVisible, expectedBehaviour);
        }
Exemple #14
0
        public SubjectModel GetSubjectById(int id,
                                           [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string accessToken)
        {
            return(this.PerformOperationAndHandleExceptions(() =>
            {
                var dbContext = new TimetableContext();
                var user = this.GetUserByAccessToken(accessToken, dbContext);
                var subject = user.Subjects.FirstOrDefault(l => l.Id == id);

                var models = SubjectModel.Parse(subject);

                return models;
            }));
        }
        public void NavigatingAfterSearching_1()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali searched for 'Bahasa'
            Then Ali shall see that the FIRST matching subject in the list is highlighted
                ";
            var models = SubjectModel.Parse(TestData.TestSlots);
            var input  = new SubjectListModel(models);

            input.Search("Bahasa");
            Assert.IsTrue(models.FindAll(x => x.Name.ToLower().Contains("Bahasa".ToLower()))[0].IsFocused, expectedBehaviour);
        }
        public void ErrorLabel_1()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali search for 'some random text lol lol lol'
            Then Ali shall not see any suggestion
            And Ali shall see an error message
                ";
            var input = new SubjectListModel(SubjectModel.Parse(TestData.TestSlots));

            input.Search("some random text lol lol lol");
            Assert.IsTrue(input.IsErrorLabelVisible, expectedBehaviour);
            Assert.IsFalse(input.IsFeedbackPanelVisible, expectedBehaviour);
        }
        public void NavigatingAfterSearching_4()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali searched for the name of first subject in the list('ASSD')
            Then Ali shall see that the subject ('ASSD') is highlighted
                ";
            var models = SubjectModel.Parse(TestData.TestSlots);
            var input  = new SubjectListModel(models);

            input.Search("ASSD".ToLower());
            Assert.IsTrue(models.Find(x => x.CodeAndNameInitials.Contains("ASSD")).IsFocused
                          , expectedBehaviour);
        }
        public void NavigateUsingArrowKeys_1()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali focused the SelectSubjectPanel
            And Ali press Down arrow key
            Then Ali should see that the focus will move to the 2nd subject in the list
                ";
            var models = SubjectModel.Parse(TestData.TestSlots);
            var input  = new SubjectListModel(models);

            input.NavigateToNextSubjectCommand.Execute(null);
            Assert.IsTrue(models[1].IsFocused, expectedBehaviour);
        }
        public void NavigatingAfterSearching_2()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali searched for 'Bahasa'
            And Ali press Down Key
            Then Ali shall see that the SECOND matching subject in the list is highlighted
                ";
            var models = SubjectModel.Parse(TestData.TestSlots);
            var input  = new SubjectListModel(models);

            input.Search("Bahasa");
            input.NavigateToNextSubjectCommand.Execute(null);
            Assert.IsTrue(models.FindAll(x => x.Name.ToLower().Contains("Bahasa".ToLower()))[1].IsFocused, expectedBehaviour);
        }
        public void DisplayMode_1()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali selected 1 subject
            And Ali clicked 'Show selected subject'
            Then Ali shall only see the subject he selected just now
                ";
            var models = SubjectModel.Parse(TestData.TestSlots);

            models[0].IsSelected = true;
            var input = new SubjectListModel(models);

            input.ToggleDisplayModeCommand.Execute(null);
            Assert.IsTrue(input.NumberOfVisibleSubject() == 1, expectedBehaviour);
        }
        public void SelectSubjectByPressingEnter()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali searched for the name of first subject in the list('ASSD')
            And Ali pressed Enter  
            Then Ali shall see that the first subject in the list is selected
                ";
            var models = SubjectModel.Parse(TestData.TestSlots);
            var input  = new SubjectListModel(models, Permutator.Run_v2_withoutConsideringWeekNumber, new TaskRunnerForUnitTesting());

            input.Search("ASSD".ToLower());
            input.ToggleSelectionOnCurrentFocusedSubject();
            Assert.IsTrue(models.Find(x => x.CodeAndNameInitials.Contains("ASSD")).IsSelected
                          , expectedBehaviour);
        }
        public void Focusing_TestingForBug()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali search for random text that results in no matching subject
            And Ali press arrow keys (Up or Down)
            Then Ali shall not crash the application
                ";
            var models = SubjectModel.Parse(TestData.TestSlots);
            var input  = new SubjectListModel(models);

            input.Search("qlkehj j2f2gkjg4");
            input.NavigateToNextSubjectCommand.Execute(null);
            input.NavigateToPreviousSubjectCommand.Execute(null);
            Assert.Pass(expectedBehaviour);
        }
        public void NavigatingAfterSearching_3()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali searched for 'Bahasa'
            And Ali press Down Key
            And Ali clear the searches
            Then Ali shall see that only ONE subject in the list is highlighted
                ";
            var models = SubjectModel.Parse(TestData.TestSlots);
            var input  = new SubjectListModel(models);

            input.Search("Bahasa");
            input.NavigateToNextSubjectCommand.Execute(null);
            input.Search("");
            Assert.IsTrue(models.Count(x => x.IsFocused) == 1, expectedBehaviour);
        }
        public void DisplayMode_3()
        {
            string expectedBehaviour =
                @"
            Given Ali just loaded slots data (by logging in)
            When Ali selected 1 subject
            And Ali clicked 'Show selected subject'
            And Ali start to type something in the search box
            Then Ali shall see all the subjects 
                ";
            var models = SubjectModel.Parse(TestData.TestSlots);

            models[0].IsSelected = true;
            var input = new SubjectListModel(models);

            input.ToggleDisplayModeCommand.Execute(null);
            input.Search("");
            Assert.IsTrue(input.NumberOfVisibleSubject() == models.Count, expectedBehaviour);
        }
Exemple #25
0
        public void Test_SlotParser_3()
        {
            string text          = File.ReadAllText(TestFilePath());
            var    result        = new SlotParser().Parse(text);
            var    subjects      = SubjectModel.Parse(result);
            int    expectedCount = 39; // counted by eyes

            var c = CodesOfListedSubjects();

            Console.WriteLine("Code not foundd : ");
            foreach (var code in c)
            {
                if (subjects.All(x => x.Code != code))
                {
                    Console.WriteLine(code);
                }
            }

            Assert.AreEqual(expectedCount, subjects.Count);
        }
Exemple #26
0
        public override string Execute()
        {
            var inputSlots   = Commandee as SlotList;
            var subjects     = SubjectModel.Parse(inputSlots);
            int subjectCount = subjects.Count;

            if (subjectCount == 0)
            {
                return("No slots is loaded yet.");
            }
            int averageSlotsCountPerSubject = inputSlots.Count / subjectCount;

            (string subjectWithMostSlotCount, int maxSlotsCount)  = GetMaxSlotCount(subjects);
            (string subjectWithLeastSlotCount, int minSlotsCount) = GetMinSlotCount(subjects);
            string result = "";

            result +=
                $"Total number of subjects = {subjectCount}\n" +
                $"Average slots count per subject = {averageSlotsCountPerSubject}\n" +
                $"Max slots count = {maxSlotsCount} ({subjectWithMostSlotCount})\n" +
                $"Min slots count = {minSlotsCount} ({subjectWithLeastSlotCount})\n"
            ;
            return(result);
        }
Exemple #27
0
 private void InitializeExtraComponents()
 {
     _subjectModels = SubjectModel.Parse(_inputSlots);
     SelectSubjectPanel.SetDataContext(_subjectModels);
     SelectSubjectPanel.SetDrawerHost(this.DrawerHost);
 }
Exemple #28
0
        public static void TestForResultCorrectness(List <Slot> result)
        {
            // this is the slot result from Sample HTML.txt
            //the following expected result is obtained using pure eye sight

            var subjects = SubjectModel.Parse(result);
            List <CodeAndCount> CodeOfRelevantSubjectsAndTheirCorrespondingSlotCount = new List <CodeAndCount>();
            var a = CodeOfRelevantSubjectsAndTheirCorrespondingSlotCount;

            a.Add(new CodeAndCount("MPU3113", 4));
            a.Add(new CodeAndCount("MPU3123", 4));
            a.Add(new CodeAndCount("MPU3143", 1));
            a.Add(new CodeAndCount("MPU3173", 1));
            a.Add(new CodeAndCount("MPU32013", 1));
            a.Add(new CodeAndCount("MPU32033", 7));
            a.Add(new CodeAndCount("MPU34012", 1));
            a.Add(new CodeAndCount("MPU34012", 1));
            a.Add(new CodeAndCount("MPU34072", 1));
            a.Add(new CodeAndCount("UALB1003", 6));
            a.Add(new CodeAndCount("UALE1083", 6));
            a.Add(new CodeAndCount("UALF1003", 6));
            a.Add(new CodeAndCount("UALJ2013", 3));
            a.Add(new CodeAndCount("UALL1063", 3));
            a.Add(new CodeAndCount("UALL3033", 3));
            a.Add(new CodeAndCount("UBMM1013", 5));
            a.Add(new CodeAndCount("UECS1004", 3));
            a.Add(new CodeAndCount("UECS1013", 5));
            a.Add(new CodeAndCount("UECS1044", 3));
            a.Add(new CodeAndCount("UECS1313", 4));
            a.Add(new CodeAndCount("UECS2033", 5));
            a.Add(new CodeAndCount("UECS2083", 4));
            a.Add(new CodeAndCount("UECS2103", 5));
            a.Add(new CodeAndCount("UECS2333", 5));
            a.Add(new CodeAndCount("UECS2363", 4));
            a.Add(new CodeAndCount("UECS2373", 3));
            a.Add(new CodeAndCount("UECS3203", 3));
            a.Add(new CodeAndCount("UECS3253", 3));
            a.Add(new CodeAndCount("UECS3263", 3));
            a.Add(new CodeAndCount("UECS3273", 3));
            a.Add(new CodeAndCount("UECS3583", 1));
            a.Add(new CodeAndCount("UEEN2013", 5));
            a.Add(new CodeAndCount("UEEN3123", 3));
            a.Add(new CodeAndCount("UJLL1093", 3));
            a.Add(new CodeAndCount("UKMM1011", 3));
            a.Add(new CodeAndCount("UKMM1043", 8));

            foreach (var c in CodeOfRelevantSubjectsAndTheirCorrespondingSlotCount)
            {
                bool somethingFound = false;
                foreach (var s in subjects)
                {
                    if (s.Code == c.Code)
                    {
                        somethingFound = true;
                        if (s.Slots.Count != c.SlotCount)
                        {
                            Assert.Fail($"Expect {c.Code} have {c.SlotCount} slots but actual is {s.Slots.Count} slots");
                        }
                        break;
                    }
                }
                if (!somethingFound)
                {
                    Assert.Fail($"{c.Code} is not found!");
                }
            }
        }
 private SubjectListModel input()
 {
     return(new SubjectListModel(SubjectModel.Parse(TestData.TestSlots), Permutator.Run_v2_withoutConsideringWeekNumber, new TaskRunnerForUnitTesting()));
 }
 public void Benchmarking_SubjectModel_Parse()
 {
     Benchmark(() => {
         var result = SubjectModel.Parse(input());
     }, "SubjectModel.Parse()");
 }