File: RangeTests.cs

package info (click to toggle)
nunit 2.6.4+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 13,092 kB
  • ctags: 14,310
  • sloc: cs: 87,766; xml: 5,858; cpp: 512; sh: 198; makefile: 48; ansic: 8
file content (84 lines) | stat: -rw-r--r-- 2,491 bytes parent folder | download
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
// ****************************************************************
// Copyright 2008, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org.
// ****************************************************************
using System;

namespace NUnit.Framework.Tests
{
    [TestFixture]
    public class RangeTests
    {
        static readonly string NL = Environment.NewLine;

        [Test]
        public void InRangeSucceeds()
        {
            Assert.That( 7, Is.InRange(5, 10) );
            Assert.That(0.23, Is.InRange(-1.0, 1.0));
            Assert.That(DateTime.Parse("12-December-2008"),
                Is.InRange(DateTime.Parse("1-October-2008"), DateTime.Parse("31-December-2008")));
        }


        [Test]
        public void InRangeFails()
        {
            string expectedMessage =
                "  Expected: in range (5,10)" + NL +
                "  But was:  12" + NL;

            Assert.That(
                new TestDelegate( FailingInRangeMethod ),
                Throws.TypeOf(typeof(AssertionException)).With.Message.EqualTo(expectedMessage));
        }

        private void FailingInRangeMethod()
        {
            Assert.That(12, Is.InRange(5, 10));
        }

        [Test]
        public void NotInRangeSucceeds()
        {
            Assert.That(12, Is.Not.InRange(5, 10));
            Assert.That(2.57, Is.Not.InRange(-1.0, 1.0));
        }

        [Test]
        public void NotInRangeFails()
        {
            string expectedMessage =
                "  Expected: not in range (5,10)" + NL +
                "  But was:  7" + NL;

            Assert.That(
                new TestDelegate(FailingNotInRangeMethod),
                Throws.TypeOf(typeof(AssertionException)).With.Message.EqualTo(expectedMessage));
        }

        private void FailingNotInRangeMethod()
        {
            Assert.That(7, Is.Not.InRange(5, 10));
        }

#if CLR_2_0 || CLR_4_0
        [Test]
        public void ShouldThrowExceptionIfFromIsLessThanTo()
        {
            Assert.That( 
                () => Assert.That( 12, Is.InRange( 10, 5 ) ),  
                Throws.ArgumentException );
        }
#endif

        [TestCase( 9, 9, 10 )]
        [TestCase( 10, 9, 10 )]
        [TestCase( 9, 9, 9 )]
        public void RangeBoundaryConditions(int actual, int from, int to)
        {
            Assert.That( actual, Is.InRange(from, to) );
        }
    }
}