diff --git a/Tests/Allocator.cs b/Tests/Allocator.cs index cf2c53b..d311e2d 100644 --- a/Tests/Allocator.cs +++ b/Tests/Allocator.cs @@ -55,7 +55,7 @@ public static int[] Allocate(int quantity, double[] weights) var results = new int[weights.Length]; for (int i = 0; i < weights.Length; i++) { - var allocation = (int)Math.Round(quantity * weights[i] / sumWeights, MidpointRounding.AwayFromZero); + var allocation = checked ((int)Math.Round(quantity * weights[i] / sumWeights, MidpointRounding.AwayFromZero)); residual -= allocation; results[i] = allocation; } diff --git a/Tests/Allocator_Tests.cs b/Tests/Allocator_Tests.cs index 8a5c6c2..f582972 100644 --- a/Tests/Allocator_Tests.cs +++ b/Tests/Allocator_Tests.cs @@ -420,13 +420,8 @@ public void Allocate_NegativeExample() [Fact] public void Allocate_Exceptions() { - var quantity = 0; - var weights_i = 0.0; - var sumWeights = 0.0; - var allocation = (int)Math.Round(quantity * weights_i / sumWeights, MidpointRounding.AwayFromZero); - Assert.Equal(int.MinValue, allocation); - //Assert.Throws(() => Allocator.Allocate(0, [0.0, 0.0, 0.0])); - //Assert.Throws(() => Allocator.Allocate(42, [1.0, -2.0, 1.0, 0])); + Assert.Throws(() => Allocator.Allocate(0, [0.0, 0.0, 0.0])); + Assert.Throws(() => Allocator.Allocate(42, [1.0, -2.0, 1.0, 1e-30])); } [Fact]