-
-
Notifications
You must be signed in to change notification settings - Fork 365
Improved long data type support #1311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,90 +8,90 @@ public class SayTest | |
[Fact] | ||
public void Zero() | ||
{ | ||
Assert.Equal("zero", Say.InEnglish(0)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've now made it clear that each input value is actually a long value. Previously, an implicit conversion was taking place, but this is more clear I feel. |
||
Assert.Equal("zero", Say.InEnglish(0L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void One() | ||
{ | ||
Assert.Equal("one", Say.InEnglish(1)); | ||
Assert.Equal("one", Say.InEnglish(1L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Fourteen() | ||
{ | ||
Assert.Equal("fourteen", Say.InEnglish(14)); | ||
Assert.Equal("fourteen", Say.InEnglish(14L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Twenty() | ||
{ | ||
Assert.Equal("twenty", Say.InEnglish(20)); | ||
Assert.Equal("twenty", Say.InEnglish(20L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Twenty_two() | ||
{ | ||
Assert.Equal("twenty-two", Say.InEnglish(22)); | ||
Assert.Equal("twenty-two", Say.InEnglish(22L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void One_hundred() | ||
{ | ||
Assert.Equal("one hundred", Say.InEnglish(100)); | ||
Assert.Equal("one hundred", Say.InEnglish(100L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void One_hundred_twenty_three() | ||
{ | ||
Assert.Equal("one hundred twenty-three", Say.InEnglish(123)); | ||
Assert.Equal("one hundred twenty-three", Say.InEnglish(123L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void One_thousand() | ||
{ | ||
Assert.Equal("one thousand", Say.InEnglish(1000)); | ||
Assert.Equal("one thousand", Say.InEnglish(1000L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void One_thousand_two_hundred_thirty_four() | ||
{ | ||
Assert.Equal("one thousand two hundred thirty-four", Say.InEnglish(1234)); | ||
Assert.Equal("one thousand two hundred thirty-four", Say.InEnglish(1234L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void One_million() | ||
{ | ||
Assert.Equal("one million", Say.InEnglish(1000000)); | ||
Assert.Equal("one million", Say.InEnglish(1000000L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void One_million_two_thousand_three_hundred_forty_five() | ||
{ | ||
Assert.Equal("one million two thousand three hundred forty-five", Say.InEnglish(1002345)); | ||
Assert.Equal("one million two thousand three hundred forty-five", Say.InEnglish(1002345L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void One_billion() | ||
{ | ||
Assert.Equal("one billion", Say.InEnglish(1000000000)); | ||
Assert.Equal("one billion", Say.InEnglish(1000000000L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void A_big_number() | ||
{ | ||
Assert.Equal("nine hundred eighty-seven billion six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three", Say.InEnglish(987654321123)); | ||
Assert.Equal("nine hundred eighty-seven billion six hundred fifty-four million three hundred twenty-one thousand one hundred twenty-three", Say.InEnglish(987654321123L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Numbers_below_zero_are_out_of_range() | ||
{ | ||
Assert.Throws<ArgumentOutOfRangeException>(() => Say.InEnglish(-1)); | ||
Assert.Throws<ArgumentOutOfRangeException>(() => Say.InEnglish(-1L)); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Numbers_above_999_999_999_999_are_out_of_range() | ||
{ | ||
Assert.Throws<ArgumentOutOfRangeException>(() => Say.InEnglish(1000000000000)); | ||
Assert.Throws<ArgumentOutOfRangeException>(() => Say.InEnglish(1000000000000L)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
namespace Exercism.CSharp.Exercises.Generators | ||
using Exercism.CSharp.Output; | ||
|
||
namespace Exercism.CSharp.Exercises.Generators | ||
{ | ||
public class PrimeFactors : GeneratorExercise | ||
{ | ||
protected override void UpdateTestMethod(TestMethod testMethod) => | ||
testMethod.Input["value"] = (long)testMethod.Input["value"]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,9 @@ public class Say : GeneratorExercise | |
protected override void UpdateTestMethod(TestMethod testMethod) | ||
{ | ||
testMethod.TestedMethod = "InEnglish"; | ||
testMethod.Input["number"] = (long)testMethod.Input["number"]; | ||
|
||
if (!(testMethod.Expected is string)) | ||
if (testMethod.ExpectedIsError) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't resist a tiny cleanup :) |
||
testMethod.ExceptionThrown = typeof(ArgumentOutOfRangeException); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,16 +45,12 @@ public static dynamic ConvertJToken(JToken jToken) | |
|
||
private static dynamic ConvertJObject(JObject jObject) | ||
{ | ||
var properties = jObject.ToObject<IDictionary<string, dynamic>>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line was the main issue, as the conversion here would result in the dictionary not containing Interestingly, the new code is way easier! |
||
var properties = new Dictionary<string, dynamic>(jObject.Count, StringComparer.OrdinalIgnoreCase); | ||
|
||
for (var i = 0; i < properties.Count; i++) | ||
{ | ||
var key = properties.Keys.ElementAt(i); | ||
var value = properties[key]; | ||
properties[key] = value is JToken jToken ? ConvertJToken(jToken) : value; | ||
} | ||
foreach (var (key, value) in jObject) | ||
properties[key] = ConvertJToken(value); | ||
|
||
return new Dictionary<string, dynamic>(properties, StringComparer.OrdinalIgnoreCase); | ||
return properties; | ||
} | ||
|
||
private static dynamic ConvertJArray(JArray jArray) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now made it clear that each input value is actually a long value. Previously, an implicit conversion was taking place, but this is more clear I feel.