Skip to content

Commit

Permalink
Merge pull request #1312 from robkeim/prime-factors-long
Browse files Browse the repository at this point in the history
Update prime factors to return longs
  • Loading branch information
ErikSchierboom authored Aug 22, 2019
2 parents b9d75e9 + 4fccf45 commit 8f18ac3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions exercises/prime-factors/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

public class PrimeFactors
{
public static int[] Factors(long number)
public static long[] Factors(long number)
{
var primes = new List<int>();
var primes = new List<long>();
int divisor = 2;
while (number > 1)
{
Expand Down
2 changes: 1 addition & 1 deletion exercises/prime-factors/PrimeFactors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static class PrimeFactors
{
public static int[] Factors(long number)
public static long[] Factors(long number)
{
throw new NotImplementedException();
}
Expand Down
12 changes: 6 additions & 6 deletions exercises/prime-factors/PrimeFactorsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ public void No_factors()
[Fact(Skip = "Remove to run test")]
public void Prime_number()
{
Assert.Equal(new[] { 2 }, PrimeFactors.Factors(2L));
Assert.Equal(new[] { 2L }, PrimeFactors.Factors(2L));
}

[Fact(Skip = "Remove to run test")]
public void Square_of_a_prime()
{
Assert.Equal(new[] { 3, 3 }, PrimeFactors.Factors(9L));
Assert.Equal(new[] { 3L, 3L }, PrimeFactors.Factors(9L));
}

[Fact(Skip = "Remove to run test")]
public void Cube_of_a_prime()
{
Assert.Equal(new[] { 2, 2, 2 }, PrimeFactors.Factors(8L));
Assert.Equal(new[] { 2L, 2L, 2L }, PrimeFactors.Factors(8L));
}

[Fact(Skip = "Remove to run test")]
public void Product_of_primes_and_non_primes()
{
Assert.Equal(new[] { 2, 2, 3 }, PrimeFactors.Factors(12L));
Assert.Equal(new[] { 2L, 2L, 3L }, PrimeFactors.Factors(12L));
}

[Fact(Skip = "Remove to run test")]
public void Product_of_primes()
{
Assert.Equal(new[] { 5, 17, 23, 461 }, PrimeFactors.Factors(901255L));
Assert.Equal(new[] { 5L, 17L, 23L, 461L }, PrimeFactors.Factors(901255L));
}

[Fact(Skip = "Remove to run test")]
public void Factors_include_a_large_prime()
{
Assert.Equal(new[] { 11, 9539, 894119 }, PrimeFactors.Factors(93819012551L));
Assert.Equal(new[] { 11L, 9539L, 894119L }, PrimeFactors.Factors(93819012551L));
}
}
12 changes: 10 additions & 2 deletions generators/Exercises/Generators/PrimeFactors.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
using Exercism.CSharp.Output;
using System.Linq;
using Exercism.CSharp.Output;

namespace Exercism.CSharp.Exercises.Generators
{
public class PrimeFactors : GeneratorExercise
{
protected override void UpdateTestMethod(TestMethod testMethod) =>
protected override void UpdateTestMethod(TestMethod testMethod)
{
testMethod.Input["value"] = (long)testMethod.Input["value"];

if (testMethod.Expected is int[] expected)
{
testMethod.Expected = expected.Select(l => (long)l).ToArray();
}
}
}
}
1 change: 0 additions & 1 deletion generators/Output/TestClassOutput.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using Exercism.CSharp.Helpers;
Expand Down

0 comments on commit 8f18ac3

Please sign in to comment.