File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
Algorithms.Tests/Numeric/Factorization
Algorithms/Numeric/Factorization Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 1
- using Algorithms . Numeric . Factorization ;
1
+ using Algorithms . Numeric . Factorization ;
2
2
using NUnit . Framework ;
3
3
4
4
namespace Algorithms . Tests . Numeric . Factorization
@@ -21,5 +21,27 @@ public static void PrimeNumberFactorizationFails(int p)
21
21
// Assert
22
22
Assert . IsFalse ( success ) ;
23
23
}
24
+
25
+ [ Test ]
26
+ [ TestCase ( 4 , 2 ) ]
27
+ [ TestCase ( 6 , 2 ) ]
28
+ [ TestCase ( 8 , 2 ) ]
29
+ [ TestCase ( 9 , 3 ) ]
30
+ [ TestCase ( 15 , 3 ) ]
31
+ [ TestCase ( 35 , 5 ) ]
32
+ [ TestCase ( 49 , 7 ) ]
33
+ [ TestCase ( 77 , 7 ) ]
34
+ public static void PrimeNumberFactorizationSucceeds ( int n , int expected )
35
+ {
36
+ // Arrange
37
+ var factorizer = new TrialDivisionFactorizer ( ) ;
38
+
39
+ // Act
40
+ var success = factorizer . TryFactor ( n , out var factor ) ;
41
+
42
+ // Assert
43
+ Assert . IsTrue ( success ) ;
44
+ Assert . AreEqual ( expected , factor ) ;
45
+ }
24
46
}
25
47
}
Original file line number Diff line number Diff line change 1
- using System ;
1
+ using System ;
2
2
using System . Linq ;
3
3
4
4
namespace Algorithms . Numeric . Factorization
@@ -9,7 +9,7 @@ namespace Algorithms.Numeric.Factorization
9
9
public class TrialDivisionFactorizer : IFactorizer
10
10
{
11
11
/// <summary>
12
- /// Finds a factor of a given number or returns false if it's prime.
12
+ /// Finds the smallest non trivial factor (i.e.: 1 < factor <= sqrt(<paramref name="n" />)) of a given number or returns false if it's prime.
13
13
/// </summary>
14
14
/// <param name="n">Integer to factor.</param>
15
15
/// <param name="factor">Found factor.</param>
You can’t perform that action at this time.
0 commit comments