Skip to content

Commit

Permalink
Merge pull request #1300 from ErikSchierboom/error-checking
Browse files Browse the repository at this point in the history
Ensure PowerShell errors are propagated
  • Loading branch information
ErikSchierboom authored Jul 8, 2019
2 parents facb1d9 + 93cbdad commit 75197cb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
4 changes: 3 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
dotnet tool install -g Cake.Tool --version 0.33.0
dotnet cake build.cake $args
dotnet cake build.cake $args

exit $LastExitCode
4 changes: 3 additions & 1 deletion copy-track-files-to-exercise.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ Get-Childitem –Path "exercises" -Directory | ForEach-Object {
$ExerciseEditorConfigPath = Join-Path $_.FullName ".editorconfig"

Set-Content -Path $ExerciseEditorConfigPath $ExerciseEditorConfigSettings
}
}

exit $LastExitCode
8 changes: 4 additions & 4 deletions exercises/diffie-hellman/DiffieHellmanTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public void Key_exchange()
var g = new BigInteger(5);
var alicePrivateKey = DiffieHellman.PrivateKey(p);
var bobPrivateKey = DiffieHellman.PrivateKey(p);
var alicePublicKey = DiffieHellman.PublicKey(p,G,AlicePrivateKey);
var bobPublicKey = DiffieHellman.PublicKey(p,G,BobPrivateKey);
var secretA = DiffieHellman.Secret(p,BobPublicKey,AlicePrivateKey);
var secretB = DiffieHellman.Secret(p,AlicePublicKey,BobPrivateKey);
var alicePublicKey = DiffieHellman.PublicKey(p, g, alicePrivateKey);
var bobPublicKey = DiffieHellman.PublicKey(p, g, bobPrivateKey);
var secretA = DiffieHellman.Secret(p, bobPublicKey, alicePrivateKey);
var secretB = DiffieHellman.Secret(p, alicePublicKey, bobPrivateKey);
Assert.Equal(secretA, secretB);
}
}
12 changes: 7 additions & 5 deletions exercises/dnd-character/DndCharacterTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file was auto-generated based on version 1.1.0 of the canonical data.

using System.Collections.Generic;
using System.Linq;
using Xunit;

Expand Down Expand Up @@ -144,7 +145,8 @@ public void Each_ability_is_only_calculated_once()
[Fact(Skip = "Remove to run test")]
public void Random_ability_is_distributed_correctly()
{
var expectedDistribution = new Dictionary<int, int>() {
var expectedDistribution = new Dictionary<int, int>
{
[3] = 1, [4] = 4,
[5] = 10, [6] = 21,
[7] = 38, [8] = 62,
Expand All @@ -155,18 +157,18 @@ public void Random_ability_is_distributed_correctly()
[17] = 54, [18] = 21
};
var actualDistribution = new Dictionary<int, int>();
var times = 100;
const int PossibleCombinationsCount = 6*6*6*6; // 4d6
const int times = 100;
const int possibleCombinationsCount = 6*6*6*6; // 4d6
for (var i = 3; i <= 18; i++)
actualDistribution[i] = 0;
for (var i = 0; i < times * PossibleCombinationsCount; i++)
for (var i = 0; i < times * possibleCombinationsCount; i++)
{
var ability = DndCharacter.Ability();
actualDistribution[ability]++;
}
int min(int expected) => (int)(expected * (times * 0.8));
int max(int expected) => (int)(expected * (times * 1.2));
foreach (var k in idealDistribution.Keys)
foreach (var k in expectedDistribution.Keys)
Assert.InRange(actualDistribution[k], min(expectedDistribution[k]), max(expectedDistribution[k]));
}
}
3 changes: 2 additions & 1 deletion generators/Exercises/Generators/DiffieHellman.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Numerics;
using System.Text;
using Exercism.CSharp.Helpers;
using Exercism.CSharp.Output;
using Exercism.CSharp.Output.Rendering;
using Humanizer;
Expand Down Expand Up @@ -96,7 +97,7 @@ private static dynamic ConvertKeyExchangeInput(dynamic input, TestMethod testMet
case long l:
return new BigInteger(l);
case string str:
return new UnescapedValue($"{testMethod.TestedClass}.{str.Pascalize()}");
return new UnescapedValue($"{testMethod.TestedClass}.{char.ToUpper(str[0]) + str.Substring(1)}");
default:
return input;
}
Expand Down
22 changes: 15 additions & 7 deletions generators/Exercises/Generators/DndCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private string RenderAssertForAbilityProperty(TestMethod testMethod)
return assert.ToString();
}

private void UpdateTestMethodForCharacterProperty(TestMethod testMethod)
private void UpdateTestMethodForCharacterProperty(TestMethod testMethod)
=> testMethod.Assert = RenderAssertForCharacterProperty(testMethod);

private string RenderAssertForCharacterProperty(TestMethod testMethod)
Expand Down Expand Up @@ -86,7 +86,8 @@ private static void AddTestMethodForDistribution(TestClass testClass)
[Fact(Skip = ""Remove to run test"")]
public void Random_ability_is_distributed_correctly()
{
var expectedDistribution = new Dictionary<int, int>() {
var expectedDistribution = new Dictionary<int, int>
{
[3] = 1, [4] = 4,
[5] = 10, [6] = 21,
[7] = 38, [8] = 62,
Expand All @@ -97,23 +98,30 @@ public void Random_ability_is_distributed_correctly()
[17] = 54, [18] = 21
};
var actualDistribution = new Dictionary<int, int>();
var times = 100;
const int PossibleCombinationsCount = 6*6*6*6; // 4d6
const int times = 100;
const int possibleCombinationsCount = 6*6*6*6; // 4d6
for (var i = 3; i <= 18; i++)
actualDistribution[i] = 0;
for (var i = 0; i < times * PossibleCombinationsCount; i++)
for (var i = 0; i < times * possibleCombinationsCount; i++)
{
var ability = DndCharacter.Ability();
actualDistribution[ability]++;
}
int min(int expected) => (int)(expected * (times * 0.8));
int max(int expected) => (int)(expected * (times * 1.2));
foreach (var k in idealDistribution.Keys)
foreach (var k in expectedDistribution.Keys)
Assert.InRange(actualDistribution[k], min(expectedDistribution[k]), max(expectedDistribution[k]));
}");
}

protected override void UpdateNamespaces(ISet<string> namespaces)
=> namespaces.Add(typeof(System.Linq.Enumerable).Namespace);
{
namespaces.Add(typeof(Enumerable).Namespace);
namespaces.Add(typeof(Dictionary<int, int>).Namespace);
}
}
}
4 changes: 3 additions & 1 deletion update-docs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ git submodule init
git submodule update --remote

.\bin\fetch-configlet
.\bin\configlet generate . -p problem-specifications $args
.\bin\configlet generate . -p problem-specifications $args

exit $LastExitCode

0 comments on commit 75197cb

Please sign in to comment.