Beispiel #1
0
        public void OutOfRange()
        {
            Assert.Throws <ArgumentOutOfRangeException>(() => Hours.New(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => Hours.New(24));

            Assert.Throws <ArgumentOutOfRangeException>(() => Seconds.New(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => Seconds.New(60));
        }
Beispiel #2
0
        public void EqTest1()
        {
            var m1 = new Metres(1);
            var m2 = new Metres(1);
            var m3 = new Metres(2);

            var h1 = new Hours(1);
            var h2 = new Hours(1);
            var h3 = new Hours(2);

            Assert.True(m1 == m2);
            Assert.False(m1 == m3);
            //var r3 = m1 == h1;    // won't compile
        }
Beispiel #3
0
        public void OrdTest1()
        {
            var m1 = new Metres(1);
            var m2 = new Metres(2);

            var h1 = new Hours(1);
            var h2 = new Hours(1);

            Assert.True(m1 < m2);
            Assert.True(m2 > m1);
            Assert.True(m1 <= m2);
            Assert.True(m2 >= m1);

            // Mixing types
            Assert.Throws <Exception>(() => h1 > m2);
            Assert.Throws <Exception>(() => h1 < m2);
            Assert.Throws <Exception>(() => h1 >= m2);
            Assert.Throws <Exception>(() => h1 <= m2);
        }
Beispiel #4
0
        public void LinqTest()
        {
            var m1 = new Metres(1);
            var m2 = new Metres(2);

            var res = from x in m1
                      from y in m2
                      select x + y;

            Assert.True(res.Value == 3);
            Assert.True(res is Metres);

            var h1 = new Hours(1);

            // Mixing types
            Assert.Throws <Exception>(() =>
                                      from x in m1
                                      from y in h1
                                      select x + y
                                      );
        }
Beispiel #5
0
        public void ArithmeticTest()
        {
            var m1 = new Metres(8);
            var m2 = new Metres(2);

            var r1 = m1 + m2;
            var r2 = m1 - m2;
            var r3 = m1 / m2;
            var r4 = m1 * m2;

            Assert.True(r1.Value == 10);
            Assert.True(r2.Value == 6);
            Assert.True(r3.Value == 4);
            Assert.True(r4.Value == 16);

            var h1 = new Hours(1);

            // Mixing types
            Assert.Throws <Exception>(() => m1 + h1);
            Assert.Throws <Exception>(() => m1 - h1);
            Assert.Throws <Exception>(() => m1 / h1);
            Assert.Throws <Exception>(() => m1 * h1);
        }
Beispiel #6
0
        public void ArithmeticTest()
        {
            var m1 = new Metres(8);
            var m2 = new Metres(2);

            var r1 = m1 + m2;
            var r2 = m1 - m2;
            var r3 = m1 / m2;
            var r4 = m1 * m2;

            Assert.True(r1 == Metres.New(10));
            Assert.True(r2 == Metres.New(6));
            Assert.True(r3 == Metres.New(4));
            Assert.True(r4 == Metres.New(16));

            var h1 = new Hours(1);

            // Mixing types - won't now compile!  success!
            // Assert.Throws<Exception>(() => m1 + h1);
            // Assert.Throws<Exception>(() => m1 - h1);
            // Assert.Throws<Exception>(() => m1 / h1);
            // Assert.Throws<Exception>(() => m1 * h1);
        }
Beispiel #7
0
        public void OrdTest1()
        {
            var m1 = new Metres(1);
            var m2 = new Metres(2);

            var h1 = new Hours(1);
            var h2 = new Hours(1);

            Assert.True(m1 < m2);
            Assert.True(m2 > m1);
            Assert.True(m1 <= m2);
            Assert.True(m2 >= m1);

            Assert.True(m1.CompareTo(m2) < 0);
            Assert.True(m2.CompareTo(m1) > 0);
            Assert.True(m1.CompareTo(m2) <= 0);
            Assert.True(m2.CompareTo(m1) >= 0);

            // Mixing types - won't compile! success!
            // Assert.Throws<Exception>(() => h1 > m2);
            // Assert.Throws<Exception>(() => h1 < m2);
            // Assert.Throws<Exception>(() => h1 >= m2);
            // Assert.Throws<Exception>(() => h1 <= m2);
        }
Beispiel #8
0
        public void LinqTest()
        {
            var m1 = new Metres(1);
            var m2 = new Metres(2);

            var ctor = Metres.New;

            var test = ctor(1);

            Metres res = from x in m1
                         from y in m2
                         select x + y;

            Assert.True(res == Metres.New(3));

            var h1 = new Hours(1);

            // Mixing types - won't now compile!  success!
            // Assert.Throws<Exception>(() =>
            //    from x in m1
            //    from y in h1
            //    select x + y
            //      );
        }