Skip to content

Commit dbe980e

Browse files
authored
Cleanup issues (#122)
* Enable nullable context * Update packages * Fix code style * Fix naming
1 parent dcdeda6 commit dbe980e

File tree

8 files changed

+62
-66
lines changed

8 files changed

+62
-66
lines changed

Algorithms.Tests/Algorithms.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netcoreapp2.1</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<LangVersion>default</LangVersion>
7-
<NullableContextOptions>disable</NullableContextOptions>
7+
<NullableContextOptions>enable</NullableContextOptions>
88
<CodeAnalysisRuleSet>..\stylecop.ruleset</CodeAnalysisRuleSet>
99
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1010
</PropertyGroup>
@@ -15,13 +15,13 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="coverlet.collector" Version="1.0.0">
18+
<PackageReference Include="coverlet.collector" Version="1.1.0">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
<PrivateAssets>all</PrivateAssets>
2121
</PackageReference>
22-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
2323
<PackageReference Include="nunit" Version="3.12.0" />
24-
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
24+
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
2525
</ItemGroup>
2626

2727
</Project>

Algorithms.Tests/Knapsack/DynamicProgrammingKnapsackSolverTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ public static class DynamicProgrammingKnapsackSolverTests
1111
public static void SmallSampleOfChar()
1212
{
1313
//Arrange
14-
var items = new [] { 'A', 'B', 'C' };
15-
var val = new [] { 50, 100, 130 };
16-
var wt = new [] { 10, 20, 40 };
14+
var items = new[] { 'A', 'B', 'C' };
15+
var val = new[] { 50, 100, 130 };
16+
var wt = new[] { 10, 20, 40 };
1717

1818
var capacity = 50;
1919

2020
Func<char, int> weightSelector = x => wt[Array.IndexOf(items, x)];
2121
Func<char, double> valueSelector = x => val[Array.IndexOf(items, x)];
2222

23-
var expected = new [] { 'A', 'C' };
23+
var expected = new[] { 'A', 'C' };
2424

2525

2626
//Act
@@ -37,16 +37,16 @@ public static void FSU_P01()
3737
// Data from https://people.sc.fsu.edu/~jburkardt/datasets/knapsack_01/knapsack_01.html
3838

3939
//Arrange
40-
var items = new [] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' };
41-
var val = new [] { 92, 57, 49, 68, 60, 43, 67, 84, 87, 72 };
42-
var wt = new [] { 23, 31, 29, 44, 53, 38, 63, 85, 89, 82 };
40+
var items = new[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' };
41+
var val = new[] { 92, 57, 49, 68, 60, 43, 67, 84, 87, 72 };
42+
var wt = new[] { 23, 31, 29, 44, 53, 38, 63, 85, 89, 82 };
4343

4444
var capacity = 165;
4545

4646
Func<char, int> weightSelector = x => wt[Array.IndexOf(items, x)];
4747
Func<char, double> valueSelector = x => val[Array.IndexOf(items, x)];
4848

49-
var expected = new [] { 'A', 'B', 'C', 'D', 'F' };
49+
var expected = new[] { 'A', 'B', 'C', 'D', 'F' };
5050

5151
//Act
5252
var solver = new DynamicProgrammingKnapsackSolver<char>();
@@ -63,16 +63,16 @@ public static void FSU_P07_WithNonIntegralValues()
6363
// Data from https://people.sc.fsu.edu/~jburkardt/datasets/knapsack_01/knapsack_01.html
6464

6565
//Arrange
66-
var val = new [] { 135, 139, 149, 150, 156, 163, 173, 184, 192, 201, 210, 214, 221, 229, 240 };
67-
var wt = new [] { 7.0, 7.3, 7.7, 8.0, 8.2, 8.7, 9.0, 9.4, 9.8, 10.6, 11.0, 11.3, 11.5, 11.8, 12.0 };
66+
var val = new[] { 135, 139, 149, 150, 156, 163, 173, 184, 192, 201, 210, 214, 221, 229, 240 };
67+
var wt = new[] { 7.0, 7.3, 7.7, 8.0, 8.2, 8.7, 9.0, 9.4, 9.8, 10.6, 11.0, 11.3, 11.5, 11.8, 12.0 };
6868
var items = Enumerable.Range(1, val.Count()).ToArray();
6969

7070
var capacity = 75;
7171

7272
Func<int, int> weightSelector = x => (int)(wt[Array.IndexOf(items, x)] * 10);
7373
Func<int, double> valueSelector = x => val[Array.IndexOf(items, x)];
7474

75-
var expected = new [] { 1, 3, 5, 7, 8, 9, 14, 15 };
75+
var expected = new[] { 1, 3, 5, 7, 8, 9, 14, 15 };
7676

7777

7878
//Act

Algorithms.Tests/Other/Int2BinaryTests.cs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,63 @@
1-
using System;
2-
using Algorithms.Other;
1+
using Algorithms.Other;
32
using NUnit.Framework;
43

54
namespace Algorithms.Tests.Other
65
{
76
public static class Int2BinaryTests
87
{
98
[Test]
10-
[TestCase((UInt16) 0, "0000000000000000")]
11-
[TestCase((UInt16) 0b1, "0000000000000001")]
12-
[TestCase((UInt16) 0b0001010100111000, "0001010100111000")]
13-
[TestCase((UInt16) 0b1110111100110010, "1110111100110010")]
14-
[TestCase((UInt16)(UInt16.MaxValue - 1), "1111111111111110")]
15-
[TestCase(UInt16.MaxValue , "1111111111111111")]
16-
public static void GetsBinary(UInt16 input, string expected)
9+
[TestCase((ushort)0, "0000000000000000")]
10+
[TestCase((ushort)0b1, "0000000000000001")]
11+
[TestCase((ushort)0b0001010100111000, "0001010100111000")]
12+
[TestCase((ushort)0b1110111100110010, "1110111100110010")]
13+
[TestCase((ushort)(ushort.MaxValue - 1), "1111111111111110")]
14+
[TestCase(ushort.MaxValue, "1111111111111111")]
15+
public static void GetsBinary(ushort input, string expected)
1716
{
1817
// Arrange
1918

2019
// Act
21-
var result = Int2Binary.Int2bin(input);
20+
var result = Int2Binary.Int2Bin(input);
2221

2322
// Assert
2423
Assert.AreEqual(expected, result);
2524
}
2625

2726

2827
[Test]
29-
[TestCase((UInt32)0, "00000000000000000000000000000000")]
30-
[TestCase((UInt32)0b1, "00000000000000000000000000000001")]
31-
[TestCase((UInt32)0b0001010100111000, "00000000000000000001010100111000")]
32-
[TestCase((UInt32)0b1110111100110010, "00000000000000001110111100110010")]
33-
[TestCase((UInt32)0b10101100001110101110111100110010, "10101100001110101110111100110010")]
34-
[TestCase((UInt32)(UInt32.MaxValue - 1), "11111111111111111111111111111110")]
35-
[TestCase(UInt32.MaxValue, "11111111111111111111111111111111")]
36-
public static void GetsBinary(UInt32 input, string expected)
28+
[TestCase((uint)0, "00000000000000000000000000000000")]
29+
[TestCase((uint)0b1, "00000000000000000000000000000001")]
30+
[TestCase((uint)0b0001010100111000, "00000000000000000001010100111000")]
31+
[TestCase((uint)0b1110111100110010, "00000000000000001110111100110010")]
32+
[TestCase(0b10101100001110101110111100110010, "10101100001110101110111100110010")]
33+
[TestCase((uint.MaxValue - 1), "11111111111111111111111111111110")]
34+
[TestCase(uint.MaxValue, "11111111111111111111111111111111")]
35+
public static void GetsBinary(uint input, string expected)
3736
{
3837
// Arrange
3938

4039
// Act
41-
var result = Int2Binary.Int2bin(input);
40+
var result = Int2Binary.Int2Bin(input);
4241

4342
// Assert
4443
Assert.AreEqual(expected, result);
4544
}
4645

4746
[Test]
48-
[TestCase((UInt64)0, "0000000000000000000000000000000000000000000000000000000000000000")]
49-
[TestCase((UInt64)0b1, "0000000000000000000000000000000000000000000000000000000000000001")]
50-
[TestCase((UInt64)0b0001010100111000, "0000000000000000000000000000000000000000000000000001010100111000")]
51-
[TestCase((UInt64)0b1110111100110010, "0000000000000000000000000000000000000000000000001110111100110010")]
52-
[TestCase((UInt64)0b10101100001110101110111100110010, "0000000000000000000000000000000010101100001110101110111100110010")]
53-
[TestCase((UInt64)0b1000101110100101000011010101110101010101110101001010000011111000, "1000101110100101000011010101110101010101110101001010000011111000")]
54-
[TestCase((UInt64)(UInt64.MaxValue - 1), "1111111111111111111111111111111111111111111111111111111111111110")]
55-
[TestCase(UInt64.MaxValue, "1111111111111111111111111111111111111111111111111111111111111111")]
56-
public static void GetsBinary(UInt64 input, string expected)
47+
[TestCase((ulong)0, "0000000000000000000000000000000000000000000000000000000000000000")]
48+
[TestCase((ulong)0b1, "0000000000000000000000000000000000000000000000000000000000000001")]
49+
[TestCase((ulong)0b0001010100111000, "0000000000000000000000000000000000000000000000000001010100111000")]
50+
[TestCase((ulong)0b1110111100110010, "0000000000000000000000000000000000000000000000001110111100110010")]
51+
[TestCase((ulong)0b10101100001110101110111100110010, "0000000000000000000000000000000010101100001110101110111100110010")]
52+
[TestCase(0b1000101110100101000011010101110101010101110101001010000011111000, "1000101110100101000011010101110101010101110101001010000011111000")]
53+
[TestCase((ulong.MaxValue - 1), "1111111111111111111111111111111111111111111111111111111111111110")]
54+
[TestCase(ulong.MaxValue, "1111111111111111111111111111111111111111111111111111111111111111")]
55+
public static void GetsBinary(ulong input, string expected)
5756
{
5857
// Arrange
5958

6059
// Act
61-
var result = Int2Binary.Int2bin(input);
60+
var result = Int2Binary.Int2Bin(input);
6261

6362
// Assert
6463
Assert.AreEqual(expected, result);

Algorithms/Algorithms.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<LangVersion>default</LangVersion>
6-
<NullableContextOptions>disable</NullableContextOptions>
6+
<NullableContextOptions>enable</NullableContextOptions>
77
<CodeAnalysisRuleSet>..\stylecop.ruleset</CodeAnalysisRuleSet>
88
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
99
</PropertyGroup>

Algorithms/Other/Int2Binary.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
using System;
2-
31
namespace Algorithms.Other
42
{
53
/// <summary>
64
/// Manually converts an integer of certain size to a string of the binary representation.
75
/// </summary>
8-
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1121:Use built-in type alias", Justification = "Built-in type aliases aren't as clear as concerning the amount of bits")]
96
public static class Int2Binary
107
{
118
/// <summary>
129
/// Returns string of the binary representation of given Int.
1310
/// </summary>
1411
/// <param name="input">Number to be converted.</param>
1512
/// <returns>Binary representation of input.</returns>
16-
public static string Int2bin(UInt16 input)
13+
public static string Int2Bin(ushort input)
1714
{
18-
UInt16 msb = UInt16.MaxValue / 2 + 1;
19-
String output = string.Empty;
20-
for (int i = 0; i < 16; i++)
15+
ushort msb = ushort.MaxValue / 2 + 1;
16+
var output = string.Empty;
17+
for (var i = 0; i < 16; i++)
2118
{
2219
if (input >= msb)
2320
{
@@ -40,11 +37,11 @@ public static string Int2bin(UInt16 input)
4037
/// </summary>
4138
/// <param name="input">Number to be converted.</param>
4239
/// <returns>Binary representation of input.</returns>
43-
public static string Int2bin(UInt32 input)
40+
public static string Int2Bin(uint input)
4441
{
45-
UInt32 msb = UInt32.MaxValue / 2 + 1;
46-
String output = string.Empty;
47-
for (int i = 0; i < 32; i++)
42+
var msb = uint.MaxValue / 2 + 1;
43+
var output = string.Empty;
44+
for (var i = 0; i < 32; i++)
4845
{
4946
if (input >= msb)
5047
{
@@ -67,11 +64,11 @@ public static string Int2bin(UInt32 input)
6764
/// </summary>
6865
/// <param name="input">Number to be converted.</param>
6966
/// <returns>Binary representation of input.</returns>
70-
public static string Int2bin(UInt64 input)
67+
public static string Int2Bin(ulong input)
7168
{
72-
UInt64 msb = UInt64.MaxValue / 2 + 1;
73-
String output = string.Empty;
74-
for (int i = 0; i < 64; i++)
69+
var msb = ulong.MaxValue / 2 + 1;
70+
var output = string.Empty;
71+
for (var i = 0; i < 64; i++)
7572
{
7673
if (input >= msb)
7774
{

Algorithms/Sorters/Integer/RadixSorter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class RadixSorter : IIntegerSorter
1313
/// <param name="array">Array to sort.</param>
1414
public void Sort(int[] array)
1515
{
16-
int bits = 4;
16+
var bits = 4;
1717
var b = new int[array.Length];
1818
var rshift = 0;
1919
for (var mask = ~(-1 << bits); mask != 0; mask <<= bits, rshift += bits)

DataStructures.Tests/DataStructures.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netcoreapp2.1</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<LangVersion>default</LangVersion>
7-
<NullableContextOptions>disable</NullableContextOptions>
7+
<NullableContextOptions>enable</NullableContextOptions>
88
<CodeAnalysisRuleSet>..\stylecop.ruleset</CodeAnalysisRuleSet>
99
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1010
</PropertyGroup>
@@ -15,13 +15,13 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="coverlet.collector" Version="1.0.0">
18+
<PackageReference Include="coverlet.collector" Version="1.1.0">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
<PrivateAssets>all</PrivateAssets>
2121
</PackageReference>
22-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
22+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
2323
<PackageReference Include="nunit" Version="3.12.0" />
24-
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
24+
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
2525
</ItemGroup>
2626

2727
</Project>

DataStructures/DataStructures.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<LangVersion>default</LangVersion>
6-
<NullableContextOptions>disable</NullableContextOptions>
6+
<NullableContextOptions>enable</NullableContextOptions>
77
<CodeAnalysisRuleSet>..\stylecop.ruleset</CodeAnalysisRuleSet>
88
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
99
</PropertyGroup>

0 commit comments

Comments
 (0)