コード例 #1
0
        public void SimpleCompareTestWithSegment()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.PeriodType = Element.PeriodType.duration;
            cp1.AddSegment("key1", "key1", "key1", "key1");

            cp2.PeriodType = Element.PeriodType.instant;

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper("key1", cp1);
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper("key2", cp2);

            Assert.AreEqual(-1, Compare(cuw2, cuw1), "1 sort wrong");
            Assert.AreEqual(1, Compare(cuw1, cuw2), "2 sort wrong");

            ArrayList test = new ArrayList();

            test.Add(cuw1);
            test.Add(cuw2);

            test.Sort(new SortByDurationFirst());

            Assert.AreEqual(cuw2.KeyName, ((MergedContextUnitsWrapper)test[0]).KeyName);
        }
コード例 #2
0
        public void SegVsScenarioScenarioWins()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddSegment("key1", "key1", "key1", "key1");
            cp1.PeriodType      = Element.PeriodType.duration;
            cp1.PeriodStartDate = new DateTime(2000, 1, 1);
            cp1.PeriodEndDate   = new DateTime(2000, 1, 2);

            cp2.AddScenario("key2", "key2", "key2", "key2");
            cp2.PeriodType      = Element.PeriodType.duration;
            cp2.PeriodStartDate = new DateTime(2000, 1, 1);
            cp2.PeriodEndDate   = new DateTime(2000, 1, 2);

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper("key1", cp1);
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper("key2", cp2);

            // no segments before segments
            Assert.AreEqual(-1, CompareSegments(cuw1.contextRef.Segments, cuw2.contextRef.Segments), "segments are not equal");
            Assert.AreEqual(0, CompareDates(cuw1, cuw2), "dates are not equal");

            // no scenario before scenario
            Assert.AreEqual(-1, CompareScenarios(cuw2.contextRef.Scenarios, cuw1.contextRef.Scenarios), "scenario 1 sort wrong");

            Assert.AreEqual(-1, Compare(cuw2, cuw1), "1 sort wrong");
            Assert.AreEqual(1, Compare(cuw1, cuw2), "2 sort wrong");
        }
コード例 #3
0
        public void TwoSegsBeforeOneSeg()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddSegment("key1", "key1", "key1", "key1");
            cp1.AddSegment("key3", "key3", "key3", "key3");

            cp2.AddSegment("key2", "key2", "key2", "key2");

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper("key1", cp1);
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper("key2", cp2);

            // and compare them
            Assert.AreEqual(1, CompareSegments(cp2.Segments, cp1.Segments), "segment sort 1 wrong");
            Assert.AreEqual(-1, CompareSegments(cp1.Segments, cp2.Segments), "segment sort 2 wrong");

            Assert.AreEqual(1, Compare(cuw2, cuw1), "1 sort wrong");
            Assert.AreEqual(-1, Compare(cuw1, cuw2), "2 sort wrong");
        }
コード例 #4
0
        public void SimpleSegmentTest()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddSegment("key1", "key1", "key1", "key1");
            cp2.AddSegment("key2", "key2", "key2", "key2");

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper("key1", cp1);
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper("key2", cp2);

            // and compare them
            Assert.AreEqual(1, Compare(cuw2, cuw1), "1 sort wrong");
            Assert.AreEqual(-1, Compare(cuw1, cuw2), "2 sort wrong");
            Assert.AreEqual(0, Compare(cuw1, cuw1), "3 sort wrong");
        }
コード例 #5
0
        public void OneSegBeforeTwoScenarios()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddScenario("key11", "key11", "key11", "key11");
            cp1.AddScenario("key3", "key3", "key3", "key3");

            cp2.AddSegment("key1", "key1", "key1", "key1");

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper("key1", cp1);
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper("key2", cp2);

            // and compare them
            Assert.AreEqual(-1, Compare(cuw2, cuw1), "1 sort wrong");
            Assert.AreEqual(1, Compare(cuw1, cuw2), "2 sort wrong");
        }
コード例 #6
0
        public void BothHaveSegsOneWithScenario()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddSegment("key1", "key1", "key1", "key1");
            cp1.PeriodType      = Element.PeriodType.duration;
            cp1.PeriodStartDate = new DateTime(2000, 1, 1);
            cp1.PeriodEndDate   = new DateTime(2000, 1, 2);

            cp1.AddScenario("key1", "key1", "key1", "key1");

            cp2.AddSegment("key1", "key1", "key1", "key1");
            cp2.PeriodType      = Element.PeriodType.duration;
            cp2.PeriodStartDate = new DateTime(2000, 1, 1);
            cp2.PeriodEndDate   = new DateTime(2000, 1, 2);

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper("key1", cp1);
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper("key2", cp2);

            Assert.AreEqual(-1, Compare(cuw2, cuw1), "1 sort wrong");
            Assert.AreEqual(1, Compare(cuw1, cuw2), "2 sort wrong");
        }
コード例 #7
0
        public void BothHaveSegsAndScenariosCheckDates()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddSegment("key1", "key1", "key1", "key1");
            cp1.AddScenario("key9", "key9", "key9", "key9");
            cp1.PeriodType      = Element.PeriodType.duration;
            cp1.PeriodStartDate = new DateTime(2000, 1, 1);
            cp1.PeriodEndDate   = new DateTime(2000, 1, 2);

            cp2.AddSegment("key1", "key1", "key1", "key1");
            cp2.AddScenario("key2", "key2", "key2", "key2");
            cp2.PeriodType      = Element.PeriodType.duration;
            cp2.PeriodStartDate = new DateTime(2000, 1, 1);
            cp2.PeriodEndDate   = new DateTime(2000, 1, 3);

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper("key1", cp1);
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper("key2", cp2);

            // and compare them - no scen should be first
            Assert.AreEqual(-1, Compare(cuw2, cuw1), "1 sort wrong");
            Assert.AreEqual(1, Compare(cuw1, cuw2), "2 sort wrong");
        }