1
- // Copyright (c) Six Labors.
1
+ // Copyright (c) Six Labors.
2
2
// Licensed under the Six Labors Split License.
3
3
4
4
namespace SixLabors . ImageSharp . Tests ;
@@ -14,15 +14,15 @@ public class RationalTests
14
14
[ Fact ]
15
15
public void AreEqual ( )
16
16
{
17
- var r1 = new Rational ( 3 , 2 ) ;
18
- var r2 = new Rational ( 3 , 2 ) ;
17
+ Rational r1 = new ( 3 , 2 ) ;
18
+ Rational r2 = new ( 3 , 2 ) ;
19
19
20
20
Assert . Equal ( r1 , r2 ) ;
21
21
Assert . True ( r1 == r2 ) ;
22
22
23
- var r3 = new Rational ( 7.55 ) ;
24
- var r4 = new Rational ( 755 , 100 ) ;
25
- var r5 = new Rational ( 151 , 20 ) ;
23
+ Rational r3 = new ( 7.55 ) ;
24
+ Rational r4 = new ( 755 , 100 ) ;
25
+ Rational r5 = new ( 151 , 20 ) ;
26
26
27
27
Assert . Equal ( r3 , r4 ) ;
28
28
Assert . Equal ( r4 , r5 ) ;
@@ -34,23 +34,30 @@ public void AreEqual()
34
34
[ Fact ]
35
35
public void AreNotEqual ( )
36
36
{
37
- var first = new Rational ( 0 , 100 ) ;
38
- var second = new Rational ( 100 , 100 ) ;
37
+ Rational first = new ( 0 , 100 ) ;
38
+ Rational second = new ( 100 , 100 ) ;
39
39
40
40
Assert . NotEqual ( first , second ) ;
41
41
Assert . True ( first != second ) ;
42
42
}
43
43
44
44
/// <summary>
45
- /// Tests the correct FromDouble(0) .
45
+ /// Tests known out-of-range values .
46
46
/// </summary>
47
- [ Fact ]
48
- public void FromDouble0Non0Denominator ( )
47
+ /// <param name="value">The input value.</param>
48
+ /// <param name="numerator">The expected numerator.</param>
49
+ /// <param name="denominator">The expected denominator.</param>
50
+ [ Theory ]
51
+ [ InlineData ( 0 , 0 , 1 ) ]
52
+ [ InlineData ( double . NaN , 0 , 0 ) ]
53
+ [ InlineData ( double . PositiveInfinity , 1 , 0 ) ]
54
+ [ InlineData ( double . NegativeInfinity , 1 , 0 ) ]
55
+ public void FromDoubleOutOfRange ( double value , uint numerator , uint denominator )
49
56
{
50
- var r = Rational . FromDouble ( 0 ) ;
57
+ Rational r = Rational . FromDouble ( value ) ;
51
58
52
- Assert . Equal ( 0 , r . Numerator ) ;
53
- Assert . Equal ( 1 , r . Denominator ) ;
59
+ Assert . Equal ( numerator , r . Numerator ) ;
60
+ Assert . Equal ( denominator , r . Denominator ) ;
54
61
}
55
62
56
63
/// <summary>
@@ -59,7 +66,7 @@ public void FromDouble0Non0Denominator()
59
66
[ Fact ]
60
67
public void ConstructorAssignsProperties ( )
61
68
{
62
- var rational = new Rational ( 7 , 55 ) ;
69
+ Rational rational = new ( 7 , 55 ) ;
63
70
Assert . Equal ( 7U , rational . Numerator ) ;
64
71
Assert . Equal ( 55U , rational . Denominator ) ;
65
72
@@ -83,15 +90,15 @@ public void ConstructorAssignsProperties()
83
90
[ Fact ]
84
91
public void Fraction ( )
85
92
{
86
- var first = new Rational ( 1.0 / 1600 ) ;
87
- var second = new Rational ( 1.0 / 1600 , true ) ;
93
+ Rational first = new ( 1.0 / 1600 ) ;
94
+ Rational second = new ( 1.0 / 1600 , true ) ;
88
95
Assert . False ( first . Equals ( second ) ) ;
89
96
}
90
97
91
98
[ Fact ]
92
99
public void ToDouble ( )
93
100
{
94
- var rational = new Rational ( 0 , 0 ) ;
101
+ Rational rational = new ( 0 , 0 ) ;
95
102
Assert . Equal ( double . NaN , rational . ToDouble ( ) ) ;
96
103
97
104
rational = new Rational ( 2 , 0 ) ;
@@ -101,7 +108,7 @@ public void ToDouble()
101
108
[ Fact ]
102
109
public void ToStringRepresentation ( )
103
110
{
104
- var rational = new Rational ( 0 , 0 ) ;
111
+ Rational rational = new ( 0 , 0 ) ;
105
112
Assert . Equal ( "[ Indeterminate ]" , rational . ToString ( ) ) ;
106
113
107
114
rational = new Rational ( double . PositiveInfinity ) ;
0 commit comments