コード例 #1
0
ファイル: GameDateTime.cs プロジェクト: MadAbs/smapi-mod-dump
        public int CompareTo(GameDateTime other)
        {
            if (ReferenceEquals(other, null))
            {
                return(1);
            }

            if (Year != other.Year)
            {
                return(Year.CompareTo(other.Year));
            }
            if (Season != other.Season)
            {
                return(Season.CompareTo(other.Season));
            }
            if (DayOfMonth != other.DayOfMonth)
            {
                return(DayOfMonth.CompareTo(other.DayOfMonth));
            }
            if (TimeOfDay != other.TimeOfDay)
            {
                return(TimeOfDay.CompareTo(other.TimeOfDay));
            }

            return(0);
        }
コード例 #2
0
        /// <summary>
        /// Compare two <see cref="TrainLocationTime"/> objects based on their arrival time.  Parameters which are null, or whose arrival time property is null,
        /// compare lower than any which have that property populated.
        /// </summary>
        /// <param name="x">A <see cref="TrainLocationTime"/> object, or null.</param>
        /// <param name="y">A <see cref="TrainLocationTime"/> object, or null.</param>
        /// <returns>Returns -1, 0 or 1 to indicate if x is less than, equal to or greater than y.</returns>
        public int Compare(TrainLocationTime x, TrainLocationTime y)
        {
            if (x == null)
            {
                return((y == null) ? 0 : -1);
            }
            if (y == null)
            {
                return(1);
            }

            TimeOfDay xTime = x.ArrivalTime?.Time ?? x.DepartureTime?.Time;
            TimeOfDay yTime = y.ArrivalTime?.Time ?? y.DepartureTime?.Time;

            if (xTime == null)
            {
                return(yTime != null ? -1 : 0);
            }
            if (yTime == null)
            {
                return(1);
            }

            return(xTime.CompareTo(yTime));
        }
コード例 #3
0
        public void CanCompareTimes_Object_Null()
        {
            var t = new TimeOfDay();
            var c = t.CompareTo(null);

            Assert.Equal(1, c);
        }
コード例 #4
0
        public void TestTimeOfDayCompareToInvalidTarget()
        {
            TimeOfDay      time = new TimeOfDay(0);
            DateTimeOffset now  = DateTimeOffset.Now;
            Action         test = () => time.CompareTo(now);

            test.ShouldThrow <ArgumentException>().WithMessage(Strings.TimeOfDay_InvalidCompareToTarget(now));
        }
コード例 #5
0
        public void CanCompareTimes_Object_Equal()
        {
            var t1 = new TimeOfDay(0, 0);
            var t2 = new TimeOfDay(0, 0);

            var c = t1.CompareTo((object)t2);

            Assert.Equal(0, c);
        }
コード例 #6
0
        public void CanCompareTimes_Instance_Equal()
        {
            var t1 = new TimeOfDay(0, 0);
            var t2 = new TimeOfDay(0, 0);

            var c = t1.CompareTo(t2);

            Assert.Equal(0, c);
        }
コード例 #7
0
        public void TestTimeOfDayCompareToInvalidTarget()
        {
            TimeOfDay      time      = new TimeOfDay(0);
            DateTimeOffset now       = DateTimeOffset.Now;
            Action         test      = () => time.CompareTo(now);
            var            exception = Assert.Throws <ArgumentException>(test);

            Assert.Equal(Strings.TimeOfDay_InvalidCompareToTarget(now), exception.Message);
        }
コード例 #8
0
        public void CanCompareTimes_Object_Equal()
        {
            var t1 = new TimeOfDay(0, 0);
            var t2 = new TimeOfDay(0, 0);

            var c = t1.CompareTo((object)t2);

            Assert.Equal(0, c);
        }
コード例 #9
0
        public void CanCompareTimes_Instance_After()
        {
            var t1 = new TimeOfDay(0, 1);
            var t2 = new TimeOfDay(0, 0);

            var c = t1.CompareTo(t2);

            Assert.Equal(1, c);
        }
コード例 #10
0
 public int CompareTo(TimeSlotItem other)
 {
     if (other == null)
     {
         return(1);
     }
     return(DayOfWeek == other.DayOfWeek
         ? TimeOfDay.CompareTo(other.TimeOfDay)
         : DayOfWeek.CompareTo(other.DayOfWeek));
 }
コード例 #11
0
        public int CompareTo(Timeslot other)
        {
            int result;

            // first compare days
            if ((result = Day.CompareTo(other.Day)) != 0)
            {
                return(result);
            }
            // same day - compare starts
            if ((result = _start.CompareTo(other._start)) != 0)
            {
                return(result);
            }
            // same start - compare end
            return(_end.CompareTo(other._end));
        }
コード例 #12
0
        public void CompareTo_ShouldReturnValidResult()
        {
            // Arrange.
            var targetOne   = new TimeOfDay(TimeZoneInfo.Utc, 4, 30, 0, 0);
            var targetTwo   = new TimeOfDay(TimeZoneInfo.Utc, 4, 30);
            var targetThree = new TimeOfDay(TimeZoneInfo.Utc, 4, 30, 0, 1);
            var targetFour  = new TimeOfDay(TimeZoneInfo.Utc, 4, 30, 0, 1);

            // Act.
            var resultOne   = targetOne.CompareTo(targetTwo) == 0;
            var resultTwo   = targetTwo.CompareTo(targetThree) == -1;
            var resultThree = targetTwo < targetOne;
            var resultFour  = targetThree > targetOne;
            var resultFive  = targetFour != targetThree;
            var resultSix   = targetTwo >= targetOne;

            // Assert.
            resultOne.Should().BeTrue();
            resultTwo.Should().BeTrue();
            resultThree.Should().BeFalse();
            resultFour.Should().BeTrue();
            resultFive.Should().BeFalse();
            resultSix.Should().BeTrue();
        }
コード例 #13
0
 public void CanCompareTimes_Object_Null()
 {
     var t = new TimeOfDay();
     var c = t.CompareTo(null);
     Assert.Equal(1, c);
 }
コード例 #14
0
 public void TestTimeOfDayCompareToInvalidTarget()
 {
     TimeOfDay time = new TimeOfDay(0);
     DateTimeOffset now = DateTimeOffset.Now;
     Action test = () => time.CompareTo(now);
     test.ShouldThrow<ArgumentException>().WithMessage(Strings.TimeOfDay_InvalidCompareToTarget(now));
 }