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,20 +34,39 @@ 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
+ /// <summary>
45
+ /// Tests known out-of-range values.
46
+ /// </summary>
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 )
56
+ {
57
+ Rational r = Rational . FromDouble ( value ) ;
58
+
59
+ Assert . Equal ( numerator , r . Numerator ) ;
60
+ Assert . Equal ( denominator , r . Denominator ) ;
61
+ }
62
+
44
63
/// <summary>
45
64
/// Tests whether the Rational constructor correctly assign properties.
46
65
/// </summary>
47
66
[ Fact ]
48
67
public void ConstructorAssignsProperties ( )
49
68
{
50
- var rational = new Rational ( 7 , 55 ) ;
69
+ Rational rational = new ( 7 , 55 ) ;
51
70
Assert . Equal ( 7U , rational . Numerator ) ;
52
71
Assert . Equal ( 55U , rational . Denominator ) ;
53
72
@@ -71,15 +90,15 @@ public void ConstructorAssignsProperties()
71
90
[ Fact ]
72
91
public void Fraction ( )
73
92
{
74
- var first = new Rational ( 1.0 / 1600 ) ;
75
- var second = new Rational ( 1.0 / 1600 , true ) ;
93
+ Rational first = new ( 1.0 / 1600 ) ;
94
+ Rational second = new ( 1.0 / 1600 , true ) ;
76
95
Assert . False ( first . Equals ( second ) ) ;
77
96
}
78
97
79
98
[ Fact ]
80
99
public void ToDouble ( )
81
100
{
82
- var rational = new Rational ( 0 , 0 ) ;
101
+ Rational rational = new ( 0 , 0 ) ;
83
102
Assert . Equal ( double . NaN , rational . ToDouble ( ) ) ;
84
103
85
104
rational = new Rational ( 2 , 0 ) ;
@@ -89,7 +108,7 @@ public void ToDouble()
89
108
[ Fact ]
90
109
public void ToStringRepresentation ( )
91
110
{
92
- var rational = new Rational ( 0 , 0 ) ;
111
+ Rational rational = new ( 0 , 0 ) ;
93
112
Assert . Equal ( "[ Indeterminate ]" , rational . ToString ( ) ) ;
94
113
95
114
rational = new Rational ( double . PositiveInfinity ) ;
0 commit comments