Beispiel #1
0
        public Subject GetSubject(string path)
        {
            if (path == null)
            {
                path = "";
            }

            if (path.StartsWith(PathChar + ""))
            {
                path = path.Remove(0, 1);
            }

            string[] ids = path.Split(new char[] { PathChar });

            xbase.SchemaList <SubjectSchema> ssList = schema.Subjects;

            string        sPath = "";
            SubjectSchema ss    = null;
            Subject       subj  = null;

            for (int i = 0; i < ids.Length; i++)
            {
                string id = ids[i];
                sPath += PathChar + id;
                ss     = ssList.FindItem(id);
                if (ss == null)
                {
                    throw new XException("分析文档,不能按路径找到指定的主题。" + sPath);
                }
                ssList = ss.ChildSubjects;
            }
            subj = new Subject(ss, ids.Length, sPath);
            return(subj);
        }
        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);
        }
        public void Test_AreNotEqual_1()
        {
            var s1 = new SubjectSchema(true, false, true);
            var s2 = new SubjectSchema(false, false, true);

            Assert.IsFalse(s1.Equals(s2));
        }
        public void Test_AreEqual_2()
        {
            var s1 = new SubjectSchema(false, true, false);
            var s2 = new SubjectSchema(false, true, false);

            Assert.IsTrue(s1.Equals(s2));
        }
        public void Test_Constructor_PassedInEmptyList()
        {
            var s = new SubjectSchema(new List <Slot>());

            Assert.IsFalse(s.GotLecture);
            Assert.IsFalse(s.GotTutorial);
            Assert.IsFalse(s.GotPractical);
        }
        public void Test_ConstructorForUnitTesting()
        {
            var s = new SubjectSchema(true, false, true);

            Assert.IsTrue(s.GotLecture);
            Assert.IsFalse(s.GotTutorial);
            Assert.IsTrue(s.GotPractical);
        }
        public void Test_Constructor_3()
        {
            var s = new SubjectSchema(TestData.GetSlotsByName(TestData.Subjects.FluidMechanicsI));

            Assert.AreEqual("UEME2123", s.SubjectCode);
            Assert.IsTrue(s.GotLecture);
            Assert.IsTrue(s.GotTutorial);
            Assert.IsTrue(s.GotPractical);
        }
        public void Test_Constructor_2()
        {
            var s = new SubjectSchema(TestData.GetSlotsByName(TestData.Subjects.ArtCraftAndDesign));

            Assert.AreEqual("MPU34072", s.SubjectCode);
            Assert.IsTrue(s.GotLecture);
            Assert.IsFalse(s.GotTutorial);
            Assert.IsFalse(s.GotPractical);
        }
        public void Test_Constructor_1()
        {
            var s = new SubjectSchema(TestData.GetSlotsByName(TestData.Subjects.AdvancedStructuralSteelDesign));

            Assert.AreEqual("UEMX4313", s.SubjectCode);
            Assert.IsTrue(s.GotLecture);
            Assert.IsTrue(s.GotTutorial);
            Assert.IsFalse(s.GotPractical);
        }
Beispiel #10
0
        public List <Subject> GetChildSubject()
        {
            List <Subject> ret = new List <Subject>();

            for (int i = 0; i < schema.ChildSubjects.Count; i++)
            {
                SubjectSchema ss  = schema.ChildSubjects[i];
                Subject       sub = new Subject(ss, level + 1, path + DataDoc.PathChar + ss.Id);
                ret.Add(sub);
            }
            return(ret);
        }
        public void Test_ConformsTo_2()
        {
            var targetSchema = new SubjectSchema(new List <Slot>()
            {
                TestData.GetSlot(167), TestData.GetSlot(171), TestData.GetSlot(207)
            });
            var schemaToBeValidated = new SubjectSchema(new List <Slot>()
            {
                TestData.GetSlot(167), TestData.GetSlot(171), TestData.GetSlot(207)
            });
            string result = schemaToBeValidated.ConformsTo(targetSchema);

            Assert.IsTrue(result == null);
        }
Beispiel #12
0
        private void BuildSubjectCatalog(xbase.ObjCatelog catalog, SubjectSchema subjectSchema)
        {
            catalog.Id          = subjectSchema.Id;
            catalog.Title       = subjectSchema.Title;
            catalog.Description = subjectSchema.Description;
            catalog.ObjType     = typeof(Subject).Name;

            for (int i = 0; i < subjectSchema.ChildSubjects.Count; i++)
            {
                xbase.ObjCatelog childCate = new xbase.ObjCatelog();
                childCate.Path = catalog.Path + PathChar + subjectSchema.ChildSubjects[i].Id;
                catalog.Children.Add(childCate);
                BuildSubjectCatalog(childCate, subjectSchema.ChildSubjects[i]);
            }
        }
        public void Test_ConformsTo_1()
        {
            var targetSchema = new SubjectSchema(new List <Slot>()
            {
                TestData.GetSlot(167), TestData.GetSlot(171), TestData.GetSlot(207)
            });
            var schemaToBeValidated = new SubjectSchema(new List <Slot>()
            {
                TestData.GetSlot(167), TestData.GetSlot(171)
            });
            string result = schemaToBeValidated.ConformsTo(targetSchema);

            Console.WriteLine(result);
            Assert.IsTrue(result.Contains("At least one TUTORIAL is needed"));
        }
Beispiel #14
0
 public Subject(SubjectSchema schema, int level, string path)
 {
     this.schema = schema;
     this.level  = level;
     this.path   = path;
 }