-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIsPositive.cs
65 lines (59 loc) · 2.53 KB
/
IsPositive.cs
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
namespace AssertLibrary
{
using System.Diagnostics;
using System.Globalization;
public static partial class Assert
{
/// <summary>
/// Asserts that the given number is positive.
/// </summary>
/// <param name="n">Number to check if it's positive</param>
/// <param name="variableName">Variable name to include in the error message (optional)</param>
public static void IsPositive(int n, string variableName = null)
{
Check(n > 0, IsPositiveMessage(variableName));
}
/// <summary>
/// Asserts that the given number is positive.
/// </summary>
/// <param name="n">Number to check if it's positive</param>
/// <param name="variableName">Variable name to include in the error message (optional)</param>
public static void IsPositive(long n, string variableName = null)
{
Check(n > 0, IsPositiveMessage(variableName));
}
/// <summary>
/// Asserts that the given number is positive.
/// </summary>
/// <param name="n">Number to check if it's positive</param>
/// <param name="variableName">Variable name to include in the error message (optional)</param>
public static void IsPositive(float n, string variableName = null)
{
Check(n > 0, IsPositiveMessage(variableName));
}
/// <summary>
/// Asserts that the given integer is positive.
/// </summary>
/// <param name="n">Number to check if it's positive</param>
/// <param name="variableName">Variable name to include in the error message (optional)</param>
public static void IsPositive(double n, string variableName = null)
{
Check(n > 0, IsPositiveMessage(variableName));
}
/// <summary>
/// Asserts that the given number is positive.
/// </summary>
/// <param name="n">Number to check if it's positive</param>
/// <param name="variableName">Variable name to include in the error message (optional)</param>
public static void IsPositive(decimal n, string variableName = null)
{
Check(n > 0, IsPositiveMessage(variableName));
}
private static string IsPositiveMessage(string variableName)
{
return variableName == null ?
"Should be positive at this point." :
string.Format(CultureInfo.CurrentCulture, "\"{0}\" should be positive at this point.", variableName);
}
}
}