File: LessEqualFixture.cs

package info (click to toggle)
nunit 2.6.4+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 13,092 kB
  • ctags: 14,310
  • sloc: cs: 87,766; xml: 5,858; cpp: 512; sh: 198; makefile: 48; ansic: 8
file content (164 lines) | stat: -rw-r--r-- 6,382 bytes parent folder | download | duplicates (2)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// ****************************************************************
// This is free software licensed under the NUnit license. You
// may obtain a copy of the license as well as information regarding
// copyright ownership at http://nunit.org.
// ****************************************************************

using System;

namespace NUnit.Framework.Tests
{
    [TestFixture]
    public class LessEqualFixture : MessageChecker
    {
        private readonly int i1 = 5;
        private readonly int i2 = 8;
		private readonly uint u1 = 12345678;
		private readonly uint u2 = 12345879;
		private readonly long l1 = 12345678;
		private readonly long l2 = 12345879;
		private readonly ulong ul1 = 12345678;
		private readonly ulong ul2 = 12345879;
		private readonly float f1 = 3.543F;
        private readonly float f2 = 8.543F;
        private readonly decimal de1 = 53.4M;
        private readonly decimal de2 = 83.4M;
        private readonly double d1 = 4.85948654;
        private readonly double d2 = 8.0;
        private readonly System.Enum e1 = System.Data.CommandType.StoredProcedure;
        private readonly System.Enum e2 = System.Data.CommandType.TableDirect;

        [Test]
        public void LessOrEqual()
        {
            // Test equality check for all forms
            Assert.LessOrEqual(i1, i1);
            Assert.LessOrEqual(i1, i1, "int");
            Assert.LessOrEqual(i1, i1, "{0}", "int");
			Assert.LessOrEqual(u1, u1);
			Assert.LessOrEqual(u1, u1, "uint");
			Assert.LessOrEqual(u1, u1, "{0}", "uint");
			Assert.LessOrEqual(l1, l1);
			Assert.LessOrEqual(l1, l1, "long");
			Assert.LessOrEqual(l1, l1, "{0}", "long");
			Assert.LessOrEqual(ul1, ul1);
			Assert.LessOrEqual(ul1, ul1, "ulong");
			Assert.LessOrEqual(ul1, ul1, "{0}", "ulong");
			Assert.LessOrEqual(d1, d1);
            Assert.LessOrEqual(d1, d1, "double");
            Assert.LessOrEqual(d1, d1, "{0}", "double");
            Assert.LessOrEqual(de1, de1);
            Assert.LessOrEqual(de1, de1, "decimal");
            Assert.LessOrEqual(de1, de1, "{0}", "decimal");
            Assert.LessOrEqual(f1, f1);
            Assert.LessOrEqual(f1, f1, "float");
            Assert.LessOrEqual(f1, f1, "{0}", "float");

            // Testing all forms after seeing some bugs. CFP
            Assert.LessOrEqual(i1, i2);
            Assert.LessOrEqual(i1, i2, "int");
            Assert.LessOrEqual(i1, i2, "{0}", "int");
            Assert.LessOrEqual(u1, u2);
            Assert.LessOrEqual(u1, u2, "uint");
            Assert.LessOrEqual(u1, u2, "{0}", "uint");
			Assert.LessOrEqual(l1, l2);
			Assert.LessOrEqual(l1, l2, "long");
			Assert.LessOrEqual(l1, l2, "{0}", "long");
			Assert.LessOrEqual(ul1, ul2);
			Assert.LessOrEqual(ul1, ul2, "ulong");
			Assert.LessOrEqual(ul1, ul2, "{0}", "ulong");
			Assert.LessOrEqual(d1, d2);
            Assert.LessOrEqual(d1, d2, "double");
            Assert.LessOrEqual(d1, d2, "{0}", "double");
            Assert.LessOrEqual(de1, de2);
            Assert.LessOrEqual(de1, de2, "decimal");
            Assert.LessOrEqual(de1, de2, "{0}", "decimal");
            Assert.LessOrEqual(f1, f2);
            Assert.LessOrEqual(f1, f2, "float");
            Assert.LessOrEqual(f1, f2, "{0}", "float");
        }

		[Test]
		public void MixedTypes()
		{	
			Assert.LessOrEqual( 5, 8L, "int to long");
			Assert.LessOrEqual( 5, 8.2f, "int to float" );
			Assert.LessOrEqual( 5, 8.2d, "int to double" );
			Assert.LessOrEqual( 5, 8U, "int to uint" );
			Assert.LessOrEqual( 5, 8UL, "int to ulong" );
			Assert.LessOrEqual( 5, 8M, "int to decimal" );

			Assert.LessOrEqual( 5L, 8, "long to int");
			Assert.LessOrEqual( 5L, 8.2f, "long to float" );
			Assert.LessOrEqual( 5L, 8.2d, "long to double" );
			Assert.LessOrEqual( 5L, 8U, "long to uint" );
			Assert.LessOrEqual( 5L, 8UL, "long to ulong" );
			Assert.LessOrEqual( 5L, 8M, "long to decimal" );

			Assert.LessOrEqual( 3.5f, 5, "float to int" );
			Assert.LessOrEqual( 3.5f, 8L, "float to long" );
			Assert.LessOrEqual( 3.5f, 8.2d, "float to double" );
			Assert.LessOrEqual( 3.5f, 8U, "float to uint" );
			Assert.LessOrEqual( 3.5f, 8UL, "float to ulong" );
			Assert.LessOrEqual( 3.5f, 8.2M, "float to decimal" );

			Assert.LessOrEqual( 3.5d, 5, "double to int" );
			Assert.LessOrEqual( 3.5d, 5L, "double to long" );
			Assert.LessOrEqual( 3.5d, 8.2f, "double to float" );
			Assert.LessOrEqual( 3.5d, 8U, "double to uint" );
			Assert.LessOrEqual( 3.5d, 8UL, "double to ulong" );
			Assert.LessOrEqual( 3.5d, 8.2M, "double to decimal" );
			

			Assert.LessOrEqual( 5U, 8, "uint to int" );
			Assert.LessOrEqual( 5U, 8L, "uint to long" );
			Assert.LessOrEqual( 5U, 8.2f, "uint to float" );
			Assert.LessOrEqual( 5U, 8.2d, "uint to double" );
			Assert.LessOrEqual( 5U, 8UL, "uint to ulong" );
			Assert.LessOrEqual( 5U, 8M, "uint to decimal" );
			
			Assert.LessOrEqual( 5ul, 8, "ulong to int" );
			Assert.LessOrEqual( 5UL, 8L, "ulong to long" );
			Assert.LessOrEqual( 5UL, 8.2f, "ulong to float" );
			Assert.LessOrEqual( 5UL, 8.2d, "ulong to double" );
			Assert.LessOrEqual( 5UL, 8U, "ulong to uint" );
			Assert.LessOrEqual( 5UL, 8M, "ulong to decimal" );
			
			Assert.LessOrEqual( 5M, 8, "decimal to int" );
			Assert.LessOrEqual( 5M, 8L, "decimal to long" );
			Assert.LessOrEqual( 5M, 8.2f, "decimal to float" );
			Assert.LessOrEqual( 5M, 8.2d, "decimal to double" );
			Assert.LessOrEqual( 5M, 8U, "decimal to uint" );
			Assert.LessOrEqual( 5M, 8UL, "decimal to ulong" );
		}

		[Test, ExpectedException(typeof(AssertionException))]
        public void NotLessOrEqual()
        {
			expectedMessage =
				"  Expected: less than or equal to 5" + Environment.NewLine +
				"  But was:  8" + Environment.NewLine;
			Assert.LessOrEqual(i2, i1);
        }

        [Test, ExpectedException(typeof(AssertionException))]
        public void NotLessEqualIComparable()
        {
			expectedMessage =
				"  Expected: less than or equal to StoredProcedure" + Environment.NewLine +
				"  But was:  TableDirect" + Environment.NewLine;
			Assert.LessOrEqual(e2, e1);
        }

        [Test,ExpectedException(typeof(AssertionException))]
        public void FailureMessage()
        {
			expectedMessage =
				"  Expected: less than or equal to 4" + Environment.NewLine +
				"  But was:  9" + Environment.NewLine;
            Assert.LessOrEqual(9, 4);
        }
    }
}