File: ScheduledItemTest.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (144 lines) | stat: -rw-r--r-- 5,184 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using Microsoft.Reactive.Testing;
#if NUNIT
using NUnit.Framework;
using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
using TestMethodAttribute = NUnit.Framework.TestAttribute;
using TestInitializeAttribute = NUnit.Framework.SetUpAttribute;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif

namespace ReactiveTests
{
    [TestClass]
    public class ScheduledItemTest : ReactiveTest
    {
        [TestMethod]
        public void ArgumentChecking()
        {
            ReactiveAssert.Throws<ArgumentNullException>(() => new ScheduledItem<DateTimeOffset, int>(default(IScheduler), 42, (x, y) => Disposable.Empty, DateTimeOffset.Now));
            ReactiveAssert.Throws<ArgumentNullException>(() => new ScheduledItem<DateTimeOffset, int>(Scheduler.Default, 42, default(Func<IScheduler, int, IDisposable>), DateTimeOffset.Now));

            ReactiveAssert.Throws<ArgumentNullException>(() => new ScheduledItem<DateTimeOffset, int>(default(IScheduler), 42, (x, y) => Disposable.Empty, DateTimeOffset.Now, Comparer<DateTimeOffset>.Default));
            ReactiveAssert.Throws<ArgumentNullException>(() => new ScheduledItem<DateTimeOffset, int>(Scheduler.Default, 42, default(Func<IScheduler, int, IDisposable>), DateTimeOffset.Now, Comparer<DateTimeOffset>.Default));
            ReactiveAssert.Throws<ArgumentNullException>(() => new ScheduledItem<DateTimeOffset, int>(Scheduler.Default, 42, (x, y) => Disposable.Empty, DateTimeOffset.Now, default(IComparer<DateTimeOffset>)));
        }

        [TestMethod]
        public void Inequalities()
        {
            var si1 = new SI(42);
            var si2 = new SI(43);
            var si3 = new SI(42);

            Assert.IsTrue(si1 < si2);
            Assert.IsFalse(si1 < si3);
            Assert.IsTrue(si1 <= si2);
            Assert.IsTrue(si1 <= si3);
            Assert.IsTrue(si2 > si1);
            Assert.IsFalse(si3 > si1);
            Assert.IsTrue(si2 >= si1);
            Assert.IsTrue(si3 >= si1);

            Assert.IsTrue(si1.CompareTo(si2) < 0);
            Assert.IsTrue(si2.CompareTo(si1) > 0);
            Assert.IsTrue(si1.CompareTo(si1) == 0);
            Assert.IsTrue(si1.CompareTo(si3) == 0);

            Assert.IsTrue(si2 > null);
            Assert.IsTrue(si2 >= null);
            Assert.IsFalse(si2 < null);
            Assert.IsFalse(si2 <= null);
            Assert.IsTrue(null < si1);
            Assert.IsTrue(null <= si1);
            Assert.IsFalse(null > si1);
            Assert.IsFalse(null >= si1);

            Assert.IsTrue(si1.CompareTo(null) > 0);

            var si4 = new SI2(43, -1);
            var si5 = new SI2(44, -1);

            Assert.IsTrue(si4 > si1);
            Assert.IsTrue(si4 >= si1);
            Assert.IsTrue(si1 < si4);
            Assert.IsTrue(si1 <= si4);
            Assert.IsFalse(si4 > si2);
            Assert.IsTrue(si4 >= si2);
            Assert.IsFalse(si2 < si4);
            Assert.IsTrue(si2 <= si4);

            Assert.IsTrue(si5 > si4);
            Assert.IsTrue(si5 >= si4);
            Assert.IsFalse(si4 > si5);
            Assert.IsFalse(si4 >= si5);
            Assert.IsTrue(si4 < si5);
            Assert.IsTrue(si4 <= si5);
            Assert.IsFalse(si5 < si4);
            Assert.IsFalse(si5 <= si4);
        }

        [TestMethod]
        public void Equalities()
        {
            var si1 = new SI2(42, 123);
            var si2 = new SI2(42, 123);
            var si3 = new SI2(42, 321);
            var si4 = new SI2(43, 123);

#pragma warning disable 1718
            Assert.IsFalse(si1 != si1);
            Assert.IsTrue(si1 == si1);
#pragma warning restore 1718
            Assert.IsTrue(si1.Equals(si1));

            Assert.IsTrue(si1 != si2);
            Assert.IsFalse(si1 == si2);
            Assert.IsFalse(si1.Equals(si2));

            Assert.IsTrue(si1 != null);
            Assert.IsTrue(null != si1);
            Assert.IsFalse(si1 == null);
            Assert.IsFalse(null == si1);

            Assert.AreEqual(si1.GetHashCode(), si1.GetHashCode());
            Assert.AreNotEqual(si1.GetHashCode(), si2.GetHashCode());
            Assert.AreNotEqual(si1.GetHashCode(), si3.GetHashCode());
        }

        class SI : ScheduledItem<int>
        {
            public SI(int dueTime)
                : base(dueTime, Comparer<int>.Default)
            {
            }

            protected override IDisposable InvokeCore()
            {
                throw new NotImplementedException();
            }
        }

        class SI2 : ScheduledItem<int>
        {
            private readonly int _value;

            public SI2(int dueTime, int value)
                : base(dueTime, Comparer<int>.Default)
            {
                _value = value;
            }

            protected override IDisposable InvokeCore()
            {
                throw new NotImplementedException();
            }
        }
    }
}