diff --git a/bin/add-practice-exercise.ps1 b/bin/add-practice-exercise.ps1 index 21ab2d6f6..16b1cabbc 100644 --- a/bin/add-practice-exercise.ps1 +++ b/bin/add-practice-exercise.ps1 @@ -39,7 +39,6 @@ $project = "${exerciseDir}/${ExerciseName}.csproj" [xml]$projectXml = Get-Content "${project}" $projectXml.Project.RemoveChild($projectXml.Project.ItemGroup[1]) $projectXml.Project.PropertyGroup.RemoveChild($projectXml.Project.PropertyGroup.SelectSingleNode("ImplicitUsings")) -$projectXml.Project.PropertyGroup.RemoveChild($projectXml.Project.PropertyGroup.SelectSingleNode("Nullable")) $projectXml.Save("${project}") # Update project packages diff --git a/exercises/concept/annalyns-infiltration/AnnalynsInfiltration.csproj b/exercises/concept/annalyns-infiltration/AnnalynsInfiltration.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/annalyns-infiltration/AnnalynsInfiltration.csproj +++ b/exercises/concept/annalyns-infiltration/AnnalynsInfiltration.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/attack-of-the-trolls/AttackOfTheTrolls.csproj b/exercises/concept/attack-of-the-trolls/AttackOfTheTrolls.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/attack-of-the-trolls/AttackOfTheTrolls.csproj +++ b/exercises/concept/attack-of-the-trolls/AttackOfTheTrolls.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/authentication-system/AuthenticationSystem.csproj b/exercises/concept/authentication-system/AuthenticationSystem.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/authentication-system/AuthenticationSystem.csproj +++ b/exercises/concept/authentication-system/AuthenticationSystem.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/beauty-salon-goes-global/BeautySalonGoesGlobal.csproj b/exercises/concept/beauty-salon-goes-global/BeautySalonGoesGlobal.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/beauty-salon-goes-global/BeautySalonGoesGlobal.csproj +++ b/exercises/concept/beauty-salon-goes-global/BeautySalonGoesGlobal.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/bird-watcher/BirdWatcher.csproj b/exercises/concept/bird-watcher/BirdWatcher.csproj index be8126449..8b75d52b0 100644 --- a/exercises/concept/bird-watcher/BirdWatcher.csproj +++ b/exercises/concept/bird-watcher/BirdWatcher.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/booking-up-for-beauty/BookingUpForBeauty.csproj b/exercises/concept/booking-up-for-beauty/BookingUpForBeauty.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/booking-up-for-beauty/BookingUpForBeauty.csproj +++ b/exercises/concept/booking-up-for-beauty/BookingUpForBeauty.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/building-telemetry/BuildingTelemetry.csproj b/exercises/concept/building-telemetry/BuildingTelemetry.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/building-telemetry/BuildingTelemetry.csproj +++ b/exercises/concept/building-telemetry/BuildingTelemetry.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/calculator-conundrum/.meta/Exemplar.cs b/exercises/concept/calculator-conundrum/.meta/Exemplar.cs index 405c4c727..325304451 100644 --- a/exercises/concept/calculator-conundrum/.meta/Exemplar.cs +++ b/exercises/concept/calculator-conundrum/.meta/Exemplar.cs @@ -2,7 +2,7 @@ public static class SimpleCalculator { - public static string Calculate(int operand1, int operand2, string operation) + public static string Calculate(int operand1, int operand2, string? operation) { int result; try diff --git a/exercises/concept/calculator-conundrum/CalculatorConundrum.cs b/exercises/concept/calculator-conundrum/CalculatorConundrum.cs index fc87406a4..e56ac5ca8 100644 --- a/exercises/concept/calculator-conundrum/CalculatorConundrum.cs +++ b/exercises/concept/calculator-conundrum/CalculatorConundrum.cs @@ -2,7 +2,7 @@ public static class SimpleCalculator { - public static string Calculate(int operand1, int operand2, string operation) + public static string Calculate(int operand1, int operand2, string? operation) { throw new NotImplementedException("Please implement the SimpleCalculator.Calculate() method"); } diff --git a/exercises/concept/calculator-conundrum/CalculatorConundrum.csproj b/exercises/concept/calculator-conundrum/CalculatorConundrum.csproj index 34a056ea9..54d543da1 100644 --- a/exercises/concept/calculator-conundrum/CalculatorConundrum.csproj +++ b/exercises/concept/calculator-conundrum/CalculatorConundrum.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/cars-assemble/CarsAssemble.csproj b/exercises/concept/cars-assemble/CarsAssemble.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/cars-assemble/CarsAssemble.csproj +++ b/exercises/concept/cars-assemble/CarsAssemble.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/developer-privileges/.meta/Exemplar.cs b/exercises/concept/developer-privileges/.meta/Exemplar.cs index d53799069..9a4a58d72 100644 --- a/exercises/concept/developer-privileges/.meta/Exemplar.cs +++ b/exercises/concept/developer-privileges/.meta/Exemplar.cs @@ -44,14 +44,14 @@ public class Authenticator //**** please do not modify the FacialFeatures class **** public class FacialFeatures { - public string EyeColor { get; set; } - public decimal PhiltrumWidth { get; set; } + public required string EyeColor { get; set; } + public required decimal PhiltrumWidth { get; set; } } //**** please do not modify the Identity class **** public class Identity { - public string Email { get; set; } - public FacialFeatures FacialFeatures { get; set; } - public IList NameAndAddress { get; set; } + public required string Email { get; set; } + public required FacialFeatures FacialFeatures { get; set; } + public required IList NameAndAddress { get; set; } } diff --git a/exercises/concept/developer-privileges/DeveloperPrivileges.cs b/exercises/concept/developer-privileges/DeveloperPrivileges.cs index eaf6906e3..76e431764 100644 --- a/exercises/concept/developer-privileges/DeveloperPrivileges.cs +++ b/exercises/concept/developer-privileges/DeveloperPrivileges.cs @@ -13,14 +13,14 @@ public class Authenticator //**** please do not modify the FacialFeatures class **** public class FacialFeatures { - public string EyeColor { get; set; } - public decimal PhiltrumWidth { get; set; } + public required string EyeColor { get; set; } + public required decimal PhiltrumWidth { get; set; } } //**** please do not modify the Identity class **** public class Identity { - public string Email { get; set; } - public FacialFeatures FacialFeatures { get; set; } - public IList NameAndAddress { get; set; } + public required string Email { get; set; } + public required FacialFeatures FacialFeatures { get; set; } + public required IList NameAndAddress { get; set; } } diff --git a/exercises/concept/developer-privileges/DeveloperPrivileges.csproj b/exercises/concept/developer-privileges/DeveloperPrivileges.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/developer-privileges/DeveloperPrivileges.csproj +++ b/exercises/concept/developer-privileges/DeveloperPrivileges.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/elons-toys/ElonsToys.csproj b/exercises/concept/elons-toys/ElonsToys.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/elons-toys/ElonsToys.csproj +++ b/exercises/concept/elons-toys/ElonsToys.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/faceid-2/.meta/Exemplar.cs b/exercises/concept/faceid-2/.meta/Exemplar.cs index 20c143543..e21b101d2 100644 --- a/exercises/concept/faceid-2/.meta/Exemplar.cs +++ b/exercises/concept/faceid-2/.meta/Exemplar.cs @@ -17,7 +17,7 @@ protected bool Equals(FacialFeatures other) return EyeColor == other.EyeColor && PhiltrumWidth.Equals(other.PhiltrumWidth); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; @@ -47,7 +47,7 @@ protected bool Equals(Identity other) return Email == other.Email && Equals(FacialFeatures, other.FacialFeatures); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; diff --git a/exercises/concept/faceid-2/Faceid2.csproj b/exercises/concept/faceid-2/Faceid2.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/faceid-2/Faceid2.csproj +++ b/exercises/concept/faceid-2/Faceid2.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/high-school-sweethearts/HighSchoolSweethearts.csproj b/exercises/concept/high-school-sweethearts/HighSchoolSweethearts.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/high-school-sweethearts/HighSchoolSweethearts.csproj +++ b/exercises/concept/high-school-sweethearts/HighSchoolSweethearts.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/hyper-optimized-telemetry/HyperOptimizedTelemetry.csproj b/exercises/concept/hyper-optimized-telemetry/HyperOptimizedTelemetry.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/hyper-optimized-telemetry/HyperOptimizedTelemetry.csproj +++ b/exercises/concept/hyper-optimized-telemetry/HyperOptimizedTelemetry.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/hyperia-forex/HyperiaForex.csproj b/exercises/concept/hyperia-forex/HyperiaForex.csproj index 0c1593de1..508bd277f 100644 --- a/exercises/concept/hyperia-forex/HyperiaForex.csproj +++ b/exercises/concept/hyperia-forex/HyperiaForex.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/hyperinflation-hits-hyperia/HyperinflationHitsHyperia.csproj b/exercises/concept/hyperinflation-hits-hyperia/HyperinflationHitsHyperia.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/hyperinflation-hits-hyperia/HyperinflationHitsHyperia.csproj +++ b/exercises/concept/hyperinflation-hits-hyperia/HyperinflationHitsHyperia.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/instruments-of-texas/.meta/Exemplar.cs b/exercises/concept/instruments-of-texas/.meta/Exemplar.cs index 9d8a76d1e..a9c1d11df 100644 --- a/exercises/concept/instruments-of-texas/.meta/Exemplar.cs +++ b/exercises/concept/instruments-of-texas/.meta/Exemplar.cs @@ -30,11 +30,11 @@ public string TestMultiplication(int x, int y) } catch (CalculationException cex) when (cex.Operand1 < 0 && cex.Operand2 < 0) { - return "Multiply failed for negative operands. " + cex.InnerException.Message; + return "Multiply failed for negative operands. " + cex.InnerException!.Message; } catch (CalculationException cex) { - return "Multiply failed for mixed or positive operands. " + cex.InnerException.Message; + return "Multiply failed for mixed or positive operands. " + cex.InnerException!.Message; } } diff --git a/exercises/concept/instruments-of-texas/InstrumentsOfTexas.csproj b/exercises/concept/instruments-of-texas/InstrumentsOfTexas.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/instruments-of-texas/InstrumentsOfTexas.csproj +++ b/exercises/concept/instruments-of-texas/InstrumentsOfTexas.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/interest-is-interesting/InterestIsInteresting.csproj b/exercises/concept/interest-is-interesting/InterestIsInteresting.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/interest-is-interesting/InterestIsInteresting.csproj +++ b/exercises/concept/interest-is-interesting/InterestIsInteresting.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/international-calling-connoisseur/InternationalCallingConnoisseur.csproj b/exercises/concept/international-calling-connoisseur/InternationalCallingConnoisseur.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/international-calling-connoisseur/InternationalCallingConnoisseur.csproj +++ b/exercises/concept/international-calling-connoisseur/InternationalCallingConnoisseur.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/land-grab-in-space/LandGrabInSpace.csproj b/exercises/concept/land-grab-in-space/LandGrabInSpace.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/land-grab-in-space/LandGrabInSpace.csproj +++ b/exercises/concept/land-grab-in-space/LandGrabInSpace.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/land-grab-in-space/LandGrabInSpaceTests.cs b/exercises/concept/land-grab-in-space/LandGrabInSpaceTests.cs index 9f64a20c6..f52580ffc 100644 --- a/exercises/concept/land-grab-in-space/LandGrabInSpaceTests.cs +++ b/exercises/concept/land-grab-in-space/LandGrabInSpaceTests.cs @@ -74,16 +74,13 @@ public void GetLongestSideReverseInsertionOrder() private Plot CreatePlot(Coord coord1, Coord coord2, Coord coord3, Coord coord4) { Type plotType = typeof(Plot); - Type[] types = new Type[] { typeof(Coord), typeof(Coord), typeof(Coord), typeof(Coord) }; - ConstructorInfo constructorInfoObj = plotType.GetConstructor(types); + Type[] types = [typeof(Coord), typeof(Coord), typeof(Coord), typeof(Coord)]; + ConstructorInfo? constructorInfoObj = plotType.GetConstructor(types); if (constructorInfoObj != null) { - return (Plot)constructorInfoObj.Invoke(new object[] { coord1, coord2, coord3, coord4 }); + return (Plot)constructorInfoObj.Invoke([coord1, coord2, coord3, coord4]); } - else - { - throw new InvalidOperationException("You need to implement a constructor for the struct Plot. The constructor must take 4 co-ordinates. No such constructor can be found."); - } + throw new InvalidOperationException("You need to implement a constructor for the struct Plot. The constructor must take 4 co-ordinates. No such constructor can be found."); } } diff --git a/exercises/concept/log-analysis/LogAnalysis.csproj b/exercises/concept/log-analysis/LogAnalysis.csproj index 34a056ea9..54d543da1 100644 --- a/exercises/concept/log-analysis/LogAnalysis.csproj +++ b/exercises/concept/log-analysis/LogAnalysis.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/log-levels/LogLevels.csproj b/exercises/concept/log-levels/LogLevels.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/log-levels/LogLevels.csproj +++ b/exercises/concept/log-levels/LogLevels.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/logs-logs-logs/LogsLogsLogs.csproj b/exercises/concept/logs-logs-logs/LogsLogsLogs.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/logs-logs-logs/LogsLogsLogs.csproj +++ b/exercises/concept/logs-logs-logs/LogsLogsLogs.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/lucians-luscious-lasagna/LuciansLusciousLasagna.csproj b/exercises/concept/lucians-luscious-lasagna/LuciansLusciousLasagna.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/lucians-luscious-lasagna/LuciansLusciousLasagna.csproj +++ b/exercises/concept/lucians-luscious-lasagna/LuciansLusciousLasagna.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/need-for-speed/NeedForSpeed.csproj b/exercises/concept/need-for-speed/NeedForSpeed.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/need-for-speed/NeedForSpeed.csproj +++ b/exercises/concept/need-for-speed/NeedForSpeed.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/object-relational-mapping/ObjectRelationalMapping.csproj b/exercises/concept/object-relational-mapping/ObjectRelationalMapping.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/object-relational-mapping/ObjectRelationalMapping.csproj +++ b/exercises/concept/object-relational-mapping/ObjectRelationalMapping.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/orm-in-one-go/OrmInOneGo.csproj b/exercises/concept/orm-in-one-go/OrmInOneGo.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/orm-in-one-go/OrmInOneGo.csproj +++ b/exercises/concept/orm-in-one-go/OrmInOneGo.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/parsing-log-files/ParsingLogFiles.csproj b/exercises/concept/parsing-log-files/ParsingLogFiles.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/parsing-log-files/ParsingLogFiles.csproj +++ b/exercises/concept/parsing-log-files/ParsingLogFiles.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/phone-number-analysis/PhoneNumberAnalysis.csproj b/exercises/concept/phone-number-analysis/PhoneNumberAnalysis.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/phone-number-analysis/PhoneNumberAnalysis.csproj +++ b/exercises/concept/phone-number-analysis/PhoneNumberAnalysis.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/red-vs-blue-darwin-style/RedVsBlueDarwinStyle.csproj b/exercises/concept/red-vs-blue-darwin-style/RedVsBlueDarwinStyle.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/red-vs-blue-darwin-style/RedVsBlueDarwinStyle.csproj +++ b/exercises/concept/red-vs-blue-darwin-style/RedVsBlueDarwinStyle.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/remote-control-cleanup/.meta/Exemplar.cs b/exercises/concept/remote-control-cleanup/.meta/Exemplar.cs index 0fd5986a8..d9023f560 100644 --- a/exercises/concept/remote-control-cleanup/.meta/Exemplar.cs +++ b/exercises/concept/remote-control-cleanup/.meta/Exemplar.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS8618 + public class RemoteControlCar { private enum SpeedUnits @@ -95,3 +97,5 @@ private void SetSpeed(Speed speed) currentSpeed = speed; } } + +#pragma warning restore CS8618 diff --git a/exercises/concept/remote-control-cleanup/RemoteControlCleanup.csproj b/exercises/concept/remote-control-cleanup/RemoteControlCleanup.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/remote-control-cleanup/RemoteControlCleanup.csproj +++ b/exercises/concept/remote-control-cleanup/RemoteControlCleanup.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/remote-control-competition/.meta/Exemplar.cs b/exercises/concept/remote-control-competition/.meta/Exemplar.cs index 8ce1b2ef6..70e892824 100644 --- a/exercises/concept/remote-control-competition/.meta/Exemplar.cs +++ b/exercises/concept/remote-control-competition/.meta/Exemplar.cs @@ -17,7 +17,7 @@ public void Drive() DistanceTravelled += 10; } - public int CompareTo(ProductionRemoteControlCar other) + public int CompareTo(ProductionRemoteControlCar? other) { if (ReferenceEquals(this, other)) return 0; if (ReferenceEquals(null, other)) return 1; diff --git a/exercises/concept/remote-control-competition/RemoteControlCompetition.cs b/exercises/concept/remote-control-competition/RemoteControlCompetition.cs index 560245751..70e892824 100644 --- a/exercises/concept/remote-control-competition/RemoteControlCompetition.cs +++ b/exercises/concept/remote-control-competition/RemoteControlCompetition.cs @@ -1,9 +1,13 @@ using System; using System.Collections.Generic; -// TODO implement the IRemoteControlCar interface +public interface IRemoteControlCar +{ + void Drive(); + int DistanceTravelled { get; } +} -public class ProductionRemoteControlCar +public class ProductionRemoteControlCar : IRemoteControlCar, IComparable { public int DistanceTravelled { get; private set; } public int NumberOfVictories { get; set; } @@ -12,9 +16,16 @@ public void Drive() { DistanceTravelled += 10; } + + public int CompareTo(ProductionRemoteControlCar? other) + { + if (ReferenceEquals(this, other)) return 0; + if (ReferenceEquals(null, other)) return 1; + return NumberOfVictories.CompareTo(other.NumberOfVictories); + } } -public class ExperimentalRemoteControlCar +public class ExperimentalRemoteControlCar : IRemoteControlCar { public int DistanceTravelled { get; private set; } @@ -28,12 +39,14 @@ public static class TestTrack { public static void Race(IRemoteControlCar car) { - throw new NotImplementedException($"Please implement the (static) TestTrack.Race() method"); + car.Drive(); } public static List GetRankedCars(ProductionRemoteControlCar prc1, ProductionRemoteControlCar prc2) { - throw new NotImplementedException($"Please implement the (static) TestTrack.GetRankedCars() method"); + var rankings = new List { prc1, prc2 }; + rankings.Sort(); + return rankings; } } diff --git a/exercises/concept/remote-control-competition/RemoteControlCompetition.csproj b/exercises/concept/remote-control-competition/RemoteControlCompetition.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/remote-control-competition/RemoteControlCompetition.csproj +++ b/exercises/concept/remote-control-competition/RemoteControlCompetition.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/roll-the-die/RollTheDie.csproj b/exercises/concept/roll-the-die/RollTheDie.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/roll-the-die/RollTheDie.csproj +++ b/exercises/concept/roll-the-die/RollTheDie.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/secure-munchester-united/SecureMunchesterUnited.csproj b/exercises/concept/secure-munchester-united/SecureMunchesterUnited.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/secure-munchester-united/SecureMunchesterUnited.csproj +++ b/exercises/concept/secure-munchester-united/SecureMunchesterUnited.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/squeaky-clean/SqueakyClean.csproj b/exercises/concept/squeaky-clean/SqueakyClean.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/squeaky-clean/SqueakyClean.csproj +++ b/exercises/concept/squeaky-clean/SqueakyClean.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/the-weather-in-deather/TheWeatherInDeather.csproj b/exercises/concept/the-weather-in-deather/TheWeatherInDeather.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/the-weather-in-deather/TheWeatherInDeather.csproj +++ b/exercises/concept/the-weather-in-deather/TheWeatherInDeather.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/tracks-on-tracks-on-tracks/TracksOnTracksOnTracks.csproj b/exercises/concept/tracks-on-tracks-on-tracks/TracksOnTracksOnTracks.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/tracks-on-tracks-on-tracks/TracksOnTracksOnTracks.csproj +++ b/exercises/concept/tracks-on-tracks-on-tracks/TracksOnTracksOnTracks.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/weighing-machine/WeighingMachine.csproj b/exercises/concept/weighing-machine/WeighingMachine.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/concept/weighing-machine/WeighingMachine.csproj +++ b/exercises/concept/weighing-machine/WeighingMachine.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/wizards-and-warriors-2/.meta/Exemplar.cs b/exercises/concept/wizards-and-warriors-2/.meta/Exemplar.cs index f34eab43b..eba0f8cde 100644 --- a/exercises/concept/wizards-and-warriors-2/.meta/Exemplar.cs +++ b/exercises/concept/wizards-and-warriors-2/.meta/Exemplar.cs @@ -1,3 +1,5 @@ +#pragma warning disable CS8618 + static class GameMaster { public static string Describe(Character character) @@ -44,3 +46,5 @@ enum TravelMethod Walking, Horseback } + +#pragma warning restore CS8618 diff --git a/exercises/concept/wizards-and-warriors-2/WizardsAndWarriors2.csproj b/exercises/concept/wizards-and-warriors-2/WizardsAndWarriors2.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/wizards-and-warriors-2/WizardsAndWarriors2.csproj +++ b/exercises/concept/wizards-and-warriors-2/WizardsAndWarriors2.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/concept/wizards-and-warriors/WizardsAndWarriors.csproj b/exercises/concept/wizards-and-warriors/WizardsAndWarriors.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/concept/wizards-and-warriors/WizardsAndWarriors.csproj +++ b/exercises/concept/wizards-and-warriors/WizardsAndWarriors.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/accumulate/Accumulate.csproj b/exercises/practice/accumulate/Accumulate.csproj index 48c7eb965..73826fe6c 100644 --- a/exercises/practice/accumulate/Accumulate.csproj +++ b/exercises/practice/accumulate/Accumulate.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/acronym/Acronym.csproj b/exercises/practice/acronym/Acronym.csproj index b4fd39c09..b0f97fdf7 100644 --- a/exercises/practice/acronym/Acronym.csproj +++ b/exercises/practice/acronym/Acronym.csproj @@ -3,6 +3,7 @@ net9.0 + enable true diff --git a/exercises/practice/affine-cipher/AffineCipher.csproj b/exercises/practice/affine-cipher/AffineCipher.csproj index e1a3b4466..1b40aeb20 100644 --- a/exercises/practice/affine-cipher/AffineCipher.csproj +++ b/exercises/practice/affine-cipher/AffineCipher.csproj @@ -3,6 +3,7 @@ Exe net9.0 + enable true diff --git a/exercises/practice/all-your-base/AllYourBase.csproj b/exercises/practice/all-your-base/AllYourBase.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/all-your-base/AllYourBase.csproj +++ b/exercises/practice/all-your-base/AllYourBase.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/allergies/Allergies.csproj b/exercises/practice/allergies/Allergies.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/allergies/Allergies.csproj +++ b/exercises/practice/allergies/Allergies.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/alphametics/.meta/Example.cs b/exercises/practice/alphametics/.meta/Example.cs index 7af1e1ae6..81c3622b2 100644 --- a/exercises/practice/alphametics/.meta/Example.cs +++ b/exercises/practice/alphametics/.meta/Example.cs @@ -57,7 +57,7 @@ private void ProcessOperand(string operand, long multiplyCountBy) public static class AlphameticsSolver { - private static AlphameticsEquation _equation; + private static AlphameticsEquation? _equation; public static IDictionary Solve(AlphameticsEquation equation) { @@ -77,19 +77,19 @@ private static bool IsSolution(int[] letterCountCombination) if (LetterCountHasInvalidNonZeroLetter()) return false; - return _equation.LettersWithCount.Values + return _equation!.LettersWithCount.Values .Zip(letterCountCombination, (count, solutionCount) => count * solutionCount).Sum() == 0; bool LetterCountHasInvalidNonZeroLetter() { var zeroLetterIndex = Array.IndexOf(letterCountCombination, 0); - return zeroLetterIndex != -1 && _equation.NonZeroLetters.Contains(_equation.LettersWithCount.Keys.ElementAt(zeroLetterIndex)); + return zeroLetterIndex != -1 && _equation!.NonZeroLetters.Contains(_equation.LettersWithCount.Keys.ElementAt(zeroLetterIndex)); } } private static Dictionary SolutionForLetterCount(IEnumerable letterCount) => letterCount - .Zip(_equation.LettersWithCount.Keys, (x, y) => new KeyValuePair(y, x)) + .Zip(_equation!.LettersWithCount.Keys, (x, y) => new KeyValuePair(y, x)) .ToDictionary(x => x.Key, x => x.Value); } diff --git a/exercises/practice/alphametics/Alphametics.csproj b/exercises/practice/alphametics/Alphametics.csproj index 2374c328a..5544c7f0f 100644 --- a/exercises/practice/alphametics/Alphametics.csproj +++ b/exercises/practice/alphametics/Alphametics.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/anagram/Anagram.csproj b/exercises/practice/anagram/Anagram.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/anagram/Anagram.csproj +++ b/exercises/practice/anagram/Anagram.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/armstrong-numbers/ArmstrongNumbers.csproj b/exercises/practice/armstrong-numbers/ArmstrongNumbers.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/armstrong-numbers/ArmstrongNumbers.csproj +++ b/exercises/practice/armstrong-numbers/ArmstrongNumbers.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/atbash-cipher/AtbashCipher.csproj b/exercises/practice/atbash-cipher/AtbashCipher.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/atbash-cipher/AtbashCipher.csproj +++ b/exercises/practice/atbash-cipher/AtbashCipher.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/bank-account/BankAccount.csproj b/exercises/practice/bank-account/BankAccount.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/bank-account/BankAccount.csproj +++ b/exercises/practice/bank-account/BankAccount.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/beer-song/BeerSong.csproj b/exercises/practice/beer-song/BeerSong.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/beer-song/BeerSong.csproj +++ b/exercises/practice/beer-song/BeerSong.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/binary-search-tree/.meta/Example.cs b/exercises/practice/binary-search-tree/.meta/Example.cs index a77fc35bf..34155833f 100644 --- a/exercises/practice/binary-search-tree/.meta/Example.cs +++ b/exercises/practice/binary-search-tree/.meta/Example.cs @@ -29,9 +29,9 @@ public BinarySearchTree(IEnumerable values) public int Value { get; } - public BinarySearchTree Left { get; private set; } + public BinarySearchTree? Left { get; private set; } - public BinarySearchTree Right { get; private set; } + public BinarySearchTree? Right { get; private set; } public BinarySearchTree Add(int value) { @@ -47,7 +47,7 @@ public BinarySearchTree Add(int value) return this; } - private static BinarySearchTree Add(int value, BinarySearchTree tree) + private static BinarySearchTree Add(int value, BinarySearchTree? tree) { if (tree == null) { diff --git a/exercises/practice/binary-search-tree/.meta/Generator.tpl b/exercises/practice/binary-search-tree/.meta/Generator.tpl index d7ad8d896..90f7c5599 100644 --- a/exercises/practice/binary-search-tree/.meta/Generator.tpl +++ b/exercises/practice/binary-search-tree/.meta/Generator.tpl @@ -2,11 +2,11 @@ checks = [$"Assert.Equal({string.to_int node.data}, tree.{path}Value);"] if node.left - checks = array.add_range checks (assertions node.left (path + "Left.")) + checks = array.add_range checks (assertions node.left (path + "Left?.")) end if node.right - checks = array.add_range checks (assertions node.right (path + "Right.")) + checks = array.add_range checks (assertions node.right (path + "Right?.")) end ret checks diff --git a/exercises/practice/binary-search-tree/BinarySearchTree.cs b/exercises/practice/binary-search-tree/BinarySearchTree.cs index f1a20129b..71f354de0 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTree.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTree.cs @@ -20,7 +20,7 @@ public int Value } } - public BinarySearchTree Left + public BinarySearchTree? Left { get { @@ -28,7 +28,7 @@ public BinarySearchTree Left } } - public BinarySearchTree Right + public BinarySearchTree? Right { get { diff --git a/exercises/practice/binary-search-tree/BinarySearchTree.csproj b/exercises/practice/binary-search-tree/BinarySearchTree.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTree.csproj +++ b/exercises/practice/binary-search-tree/BinarySearchTree.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs b/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs index 18698389f..1eae96771 100644 --- a/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs +++ b/exercises/practice/binary-search-tree/BinarySearchTreeTests.cs @@ -15,7 +15,7 @@ public void Insert_data_at_proper_node_smaller_number_at_left_node() { var tree = new BinarySearchTree(new[] { 4, 2 }); Assert.Equal(4, tree.Value); - Assert.Equal(2, tree.Left.Value); + Assert.Equal(2, tree.Left?.Value); } [Fact(Skip = "Remove this Skip property to run this test")] @@ -23,7 +23,7 @@ public void Insert_data_at_proper_node_same_number_at_left_node() { var tree = new BinarySearchTree(new[] { 4, 4 }); Assert.Equal(4, tree.Value); - Assert.Equal(4, tree.Left.Value); + Assert.Equal(4, tree.Left?.Value); } [Fact(Skip = "Remove this Skip property to run this test")] @@ -31,7 +31,7 @@ public void Insert_data_at_proper_node_greater_number_at_right_node() { var tree = new BinarySearchTree(new[] { 4, 5 }); Assert.Equal(4, tree.Value); - Assert.Equal(5, tree.Right.Value); + Assert.Equal(5, tree.Right?.Value); } [Fact(Skip = "Remove this Skip property to run this test")] @@ -39,12 +39,12 @@ public void Can_create_complex_tree() { var tree = new BinarySearchTree(new[] { 4, 2, 6, 1, 3, 5, 7 }); Assert.Equal(4, tree.Value); - Assert.Equal(2, tree.Left.Value); - Assert.Equal(1, tree.Left.Left.Value); - Assert.Equal(3, tree.Left.Right.Value); - Assert.Equal(6, tree.Right.Value); - Assert.Equal(5, tree.Right.Left.Value); - Assert.Equal(7, tree.Right.Right.Value); + Assert.Equal(2, tree.Left?.Value); + Assert.Equal(1, tree.Left?.Left?.Value); + Assert.Equal(3, tree.Left?.Right?.Value); + Assert.Equal(6, tree.Right?.Value); + Assert.Equal(5, tree.Right?.Left?.Value); + Assert.Equal(7, tree.Right?.Right?.Value); } [Fact(Skip = "Remove this Skip property to run this test")] diff --git a/exercises/practice/binary-search/BinarySearch.csproj b/exercises/practice/binary-search/BinarySearch.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/binary-search/BinarySearch.csproj +++ b/exercises/practice/binary-search/BinarySearch.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/binary/Binary.csproj b/exercises/practice/binary/Binary.csproj index 09fcf4d6e..5553da3b4 100644 --- a/exercises/practice/binary/Binary.csproj +++ b/exercises/practice/binary/Binary.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/bob/Bob.csproj b/exercises/practice/bob/Bob.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/bob/Bob.csproj +++ b/exercises/practice/bob/Bob.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/book-store/BookStore.csproj b/exercises/practice/book-store/BookStore.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/book-store/BookStore.csproj +++ b/exercises/practice/book-store/BookStore.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/bowling/Bowling.csproj b/exercises/practice/bowling/Bowling.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/bowling/Bowling.csproj +++ b/exercises/practice/bowling/Bowling.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/change/.meta/Example.cs b/exercises/practice/change/.meta/Example.cs index 775648083..566521e12 100644 --- a/exercises/practice/change/.meta/Example.cs +++ b/exercises/practice/change/.meta/Example.cs @@ -37,7 +37,7 @@ Dictionary> UpdateMinimalCoinsMap(Dictionary> curr return current; } - List MinimalCoins(Dictionary> current, int subTarget) + List? MinimalCoins(Dictionary> current, int subTarget) { return coins .Where(coin => coin <= subTarget) @@ -45,7 +45,7 @@ List MinimalCoins(Dictionary> current, int subTarget) ? subTargetMinimalCoins.Append(coin).ToList() : null) .Where(subTargetMinimalCoins => subTargetMinimalCoins != null) - .OrderBy(subTargetMinimalCoins => subTargetMinimalCoins.Count) + .OrderBy(subTargetMinimalCoins => subTargetMinimalCoins!.Count) .FirstOrDefault(); } } diff --git a/exercises/practice/change/Change.csproj b/exercises/practice/change/Change.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/change/Change.csproj +++ b/exercises/practice/change/Change.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/circular-buffer/CircularBuffer.csproj b/exercises/practice/circular-buffer/CircularBuffer.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/circular-buffer/CircularBuffer.csproj +++ b/exercises/practice/circular-buffer/CircularBuffer.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/clock/Clock.csproj b/exercises/practice/clock/Clock.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/clock/Clock.csproj +++ b/exercises/practice/clock/Clock.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/collatz-conjecture/CollatzConjecture.csproj b/exercises/practice/collatz-conjecture/CollatzConjecture.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/practice/collatz-conjecture/CollatzConjecture.csproj +++ b/exercises/practice/collatz-conjecture/CollatzConjecture.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/complex-numbers/ComplexNumbers.csproj b/exercises/practice/complex-numbers/ComplexNumbers.csproj index a5b5aa41c..02b41704e 100644 --- a/exercises/practice/complex-numbers/ComplexNumbers.csproj +++ b/exercises/practice/complex-numbers/ComplexNumbers.csproj @@ -3,6 +3,7 @@ net9.0 + enable true diff --git a/exercises/practice/connect/Connect.csproj b/exercises/practice/connect/Connect.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/connect/Connect.csproj +++ b/exercises/practice/connect/Connect.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/crypto-square/CryptoSquare.csproj b/exercises/practice/crypto-square/CryptoSquare.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/crypto-square/CryptoSquare.csproj +++ b/exercises/practice/crypto-square/CryptoSquare.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/custom-set/.meta/Example.cs b/exercises/practice/custom-set/.meta/Example.cs index f4f9ae718..f6273f67b 100644 --- a/exercises/practice/custom-set/.meta/Example.cs +++ b/exercises/practice/custom-set/.meta/Example.cs @@ -45,7 +45,7 @@ public CustomSet Union(CustomSet right) private int[] GetValuesFromKeys(IEnumerable keys) => keys.Select(key => items[key]).ToArray(); - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (!(obj is CustomSet other)) { diff --git a/exercises/practice/custom-set/CustomSet.csproj b/exercises/practice/custom-set/CustomSet.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/custom-set/CustomSet.csproj +++ b/exercises/practice/custom-set/CustomSet.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/darts/Darts.csproj b/exercises/practice/darts/Darts.csproj index be8126449..8b75d52b0 100644 --- a/exercises/practice/darts/Darts.csproj +++ b/exercises/practice/darts/Darts.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/diamond/Diamond.csproj b/exercises/practice/diamond/Diamond.csproj index 2bac419d2..425016c2d 100644 --- a/exercises/practice/diamond/Diamond.csproj +++ b/exercises/practice/diamond/Diamond.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/difference-of-squares/DifferenceOfSquares.csproj b/exercises/practice/difference-of-squares/DifferenceOfSquares.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/difference-of-squares/DifferenceOfSquares.csproj +++ b/exercises/practice/difference-of-squares/DifferenceOfSquares.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/diffie-hellman/DiffieHellman.csproj b/exercises/practice/diffie-hellman/DiffieHellman.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/diffie-hellman/DiffieHellman.csproj +++ b/exercises/practice/diffie-hellman/DiffieHellman.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/dnd-character/DndCharacter.csproj b/exercises/practice/dnd-character/DndCharacter.csproj index be8126449..8b75d52b0 100644 --- a/exercises/practice/dnd-character/DndCharacter.csproj +++ b/exercises/practice/dnd-character/DndCharacter.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/dominoes/Dominoes.csproj b/exercises/practice/dominoes/Dominoes.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/dominoes/Dominoes.csproj +++ b/exercises/practice/dominoes/Dominoes.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/dot-dsl/.meta/Example.cs b/exercises/practice/dot-dsl/.meta/Example.cs index 80723f973..907f4b4f3 100644 --- a/exercises/practice/dot-dsl/.meta/Example.cs +++ b/exercises/practice/dot-dsl/.meta/Example.cs @@ -10,7 +10,7 @@ public Node(string name) public string Name { get; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj == null || GetType() != obj.GetType()) return false; @@ -32,7 +32,7 @@ public Edge(string node1, string node2) public string Node1 { get; } public string Node2 { get; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj == null || GetType() != obj.GetType()) return false; @@ -55,7 +55,7 @@ public Attr(string key, string value) public string Key { get; } public string Value { get; } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj == null || GetType() != obj.GetType()) return false; diff --git a/exercises/practice/dot-dsl/DotDsl.csproj b/exercises/practice/dot-dsl/DotDsl.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/dot-dsl/DotDsl.csproj +++ b/exercises/practice/dot-dsl/DotDsl.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/dot-dsl/DotDslTests.cs b/exercises/practice/dot-dsl/DotDslTests.cs index 40adfcd09..225e25324 100644 --- a/exercises/practice/dot-dsl/DotDslTests.cs +++ b/exercises/practice/dot-dsl/DotDslTests.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using Xunit; @@ -23,7 +22,7 @@ public void Graph_with_one_node() new Node("a") }; - Assert.Equal(new[] { new Node("a") }, g.Nodes); + Assert.Equal([new Node("a")], g.Nodes); Assert.Empty(g.Edges); Assert.Empty(g.Attrs); } @@ -36,7 +35,7 @@ public void Graph_with_one_node_with_keywords() new Node("a") { { "color", "green" } } }; - Assert.Equal(new[] { new Node("a") { { "color", "green" } } }, g.Nodes); + Assert.Equal([new Node("a") { { "color", "green" } }], g.Nodes); Assert.Empty(g.Edges); Assert.Empty(g.Attrs); } @@ -50,7 +49,7 @@ public void Graph_with_one_edge() }; Assert.Empty(g.Nodes); - Assert.Equal(new[] { new Edge("a", "b") }, g.Edges); + Assert.Equal([new Edge("a", "b")], g.Edges); Assert.Empty(g.Attrs); } @@ -64,7 +63,7 @@ public void Graph_with_one_attribute() Assert.Empty(g.Nodes); Assert.Empty(g.Edges); - Assert.Equal(new[] { new Attr("foo", "1") }, g.Attrs); + Assert.Equal([new Attr("foo", "1")], g.Attrs); } [Fact(Skip = "Remove this Skip property to run this test")] @@ -82,20 +81,11 @@ public void Graph_with_attributes() { "bar", "true" } }; - Assert.Equal(new[] { new Node("a") { { "color", "green" } }, new Node("b") { { "label", "Beta!" } }, new Node("c") }, g.Nodes, EnumerableEqualityComparer.Instance); - Assert.Equal(new[] { new Edge("a", "b") { { "color", "blue" } }, new Edge("b", "c") }, g.Edges, EnumerableEqualityComparer.Instance); - Assert.Equal(new[] { new Attr("bar", "true"), new Attr("foo", "1"), new Attr("title", "Testing Attrs") }, g.Attrs, EnumerableEqualityComparer.Instance); - } - - private class EnumerableEqualityComparer : IEqualityComparer> - { - public static readonly EnumerableEqualityComparer Instance = new EnumerableEqualityComparer(); - - public bool Equals(IEnumerable x, IEnumerable y) => new HashSet(x).SetEquals(y); - - public int GetHashCode(IEnumerable obj) - { - throw new NotImplementedException("You need to implement this method."); - } + HashSet expectedNodes = [new Node("a") { { "color", "green" } }, new Node("b") { { "label", "Beta!" } }, new Node("c")]; + Assert.Equal(expectedNodes, g.Nodes.ToHashSet()); + HashSet expectedEdges = [new Edge("a", "b") { { "color", "blue" } }, new Edge("b", "c")]; + Assert.Equal(expectedEdges, g.Edges.ToHashSet()); + HashSet expectedAttrs = [new Attr("bar", "true"), new Attr("foo", "1"), new Attr("title", "Testing Attrs")]; + Assert.Equal(expectedAttrs, g.Attrs.ToHashSet()); } } \ No newline at end of file diff --git a/exercises/practice/eliuds-eggs/EliudsEggs.csproj b/exercises/practice/eliuds-eggs/EliudsEggs.csproj index c97331f70..ce2468564 100644 --- a/exercises/practice/eliuds-eggs/EliudsEggs.csproj +++ b/exercises/practice/eliuds-eggs/EliudsEggs.csproj @@ -7,6 +7,7 @@ false true + enable true diff --git a/exercises/practice/error-handling/ErrorHandling.csproj b/exercises/practice/error-handling/ErrorHandling.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/error-handling/ErrorHandling.csproj +++ b/exercises/practice/error-handling/ErrorHandling.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/etl/Etl.csproj b/exercises/practice/etl/Etl.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/etl/Etl.csproj +++ b/exercises/practice/etl/Etl.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/flatten-array/.meta/Generator.tpl b/exercises/practice/flatten-array/.meta/Generator.tpl index 02583b06b..e30030318 100644 --- a/exercises/practice/flatten-array/.meta/Generator.tpl +++ b/exercises/practice/flatten-array/.meta/Generator.tpl @@ -2,10 +2,10 @@ case (object.typeof input) when "array" if input.empty? - ret "Array.Empty()" + ret "Array.Empty()" else elements = array.join (array.each input @toarg) ", " - ret "new object[] { " + elements + " }" + ret "new object?[] { " + elements + " }" end else if input @@ -26,11 +26,11 @@ public class {{ testClass }} public void {{ test.testMethod }}() { {{- if test.input.array.empty? }} - var array = Array.Empty(); + var array = Array.Empty(); Assert.Empty({{ testedClass }}.{{ test.testedMethod }}(array)); {{- else }} - object[] array = {{ test.input.array | toarg }}; - object[] expected = {{ test.expected }}; + object?[] array = {{ test.input.array | toarg }}; + object?[] expected = {{ test.expected }}; Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}(array)); {{ end -}} } diff --git a/exercises/practice/flatten-array/FlattenArray.csproj b/exercises/practice/flatten-array/FlattenArray.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/flatten-array/FlattenArray.csproj +++ b/exercises/practice/flatten-array/FlattenArray.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/flatten-array/FlattenArrayTests.cs b/exercises/practice/flatten-array/FlattenArrayTests.cs index 51a1c0324..64ea0ede4 100644 --- a/exercises/practice/flatten-array/FlattenArrayTests.cs +++ b/exercises/practice/flatten-array/FlattenArrayTests.cs @@ -6,87 +6,87 @@ public class FlattenArrayTests [Fact] public void Empty() { - var array = Array.Empty(); + var array = Array.Empty(); Assert.Empty(FlattenArray.Flatten(array)); } [Fact(Skip = "Remove this Skip property to run this test")] public void No_nesting() { - object[] array = new object[] { 0, 1, 2 }; - object[] expected = [0, 1, 2]; + object?[] array = new object?[] { 0, 1, 2 }; + object?[] expected = [0, 1, 2]; Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Flattens_a_nested_array() { - object[] array = new object[] { new object[] { Array.Empty() } }; - object[] expected = []; + object?[] array = new object?[] { new object?[] { Array.Empty() } }; + object?[] expected = []; Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Flattens_array_with_just_integers_present() { - object[] array = new object[] { 1, new object[] { 2, 3, 4, 5, 6, 7 }, 8 }; - object[] expected = [1, 2, 3, 4, 5, 6, 7, 8]; + object?[] array = new object?[] { 1, new object?[] { 2, 3, 4, 5, 6, 7 }, 8 }; + object?[] expected = [1, 2, 3, 4, 5, 6, 7, 8]; Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Five_level_nesting() { - object[] array = new object[] { 0, 2, new object[] { new object[] { 2, 3 }, 8, 100, 4, new object[] { new object[] { new object[] { 50 } } } }, -2 }; - object[] expected = [0, 2, 2, 3, 8, 100, 4, 50, -2]; + object?[] array = new object?[] { 0, 2, new object?[] { new object?[] { 2, 3 }, 8, 100, 4, new object?[] { new object?[] { new object?[] { 50 } } } }, -2 }; + object?[] expected = [0, 2, 2, 3, 8, 100, 4, 50, -2]; Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Six_level_nesting() { - object[] array = new object[] { 1, new object[] { 2, new object[] { new object[] { 3 } }, new object[] { 4, new object[] { new object[] { 5 } } }, 6, 7 }, 8 }; - object[] expected = [1, 2, 3, 4, 5, 6, 7, 8]; + object?[] array = new object?[] { 1, new object?[] { 2, new object?[] { new object?[] { 3 } }, new object?[] { 4, new object?[] { new object?[] { 5 } } }, 6, 7 }, 8 }; + object?[] expected = [1, 2, 3, 4, 5, 6, 7, 8]; Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Null_values_are_omitted_from_the_final_result() { - object[] array = new object[] { 1, 2, null }; - object[] expected = [1, 2]; + object?[] array = new object?[] { 1, 2, null }; + object?[] expected = [1, 2]; Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Consecutive_null_values_at_the_front_of_the_list_are_omitted_from_the_final_result() { - object[] array = new object[] { null, null, 3 }; - object[] expected = [3]; + object?[] array = new object?[] { null, null, 3 }; + object?[] expected = [3]; Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Consecutive_null_values_in_the_middle_of_the_list_are_omitted_from_the_final_result() { - object[] array = new object[] { 1, null, null, 4 }; - object[] expected = [1, 4]; + object?[] array = new object?[] { 1, null, null, 4 }; + object?[] expected = [1, 4]; Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Six_level_nest_list_with_null_values() { - object[] array = new object[] { 0, 2, new object[] { new object[] { 2, 3 }, 8, new object[] { new object[] { 100 } }, null, new object[] { new object[] { null } } }, -2 }; - object[] expected = [0, 2, 2, 3, 8, 100, -2]; + object?[] array = new object?[] { 0, 2, new object?[] { new object?[] { 2, 3 }, 8, new object?[] { new object?[] { 100 } }, null, new object?[] { new object?[] { null } } }, -2 }; + object?[] expected = [0, 2, 2, 3, 8, 100, -2]; Assert.Equal(expected, FlattenArray.Flatten(array)); } [Fact(Skip = "Remove this Skip property to run this test")] public void All_values_in_nested_list_are_null() { - object[] array = new object[] { null, new object[] { new object[] { new object[] { null } } }, null, null, new object[] { new object[] { null, null }, null }, null }; - object[] expected = []; + object?[] array = new object?[] { null, new object?[] { new object?[] { new object?[] { null } } }, null, null, new object?[] { new object?[] { null, null }, null }, null }; + object?[] expected = []; Assert.Equal(expected, FlattenArray.Flatten(array)); } } diff --git a/exercises/practice/food-chain/FoodChain.csproj b/exercises/practice/food-chain/FoodChain.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/food-chain/FoodChain.csproj +++ b/exercises/practice/food-chain/FoodChain.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/forth/Forth.csproj b/exercises/practice/forth/Forth.csproj index 2374c328a..5544c7f0f 100644 --- a/exercises/practice/forth/Forth.csproj +++ b/exercises/practice/forth/Forth.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/game-of-life/GameOfLife.csproj b/exercises/practice/game-of-life/GameOfLife.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/game-of-life/GameOfLife.csproj +++ b/exercises/practice/game-of-life/GameOfLife.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/gigasecond/Gigasecond.csproj b/exercises/practice/gigasecond/Gigasecond.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/gigasecond/Gigasecond.csproj +++ b/exercises/practice/gigasecond/Gigasecond.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/go-counting/GoCounting.csproj b/exercises/practice/go-counting/GoCounting.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/go-counting/GoCounting.csproj +++ b/exercises/practice/go-counting/GoCounting.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/grade-school/GradeSchool.csproj b/exercises/practice/grade-school/GradeSchool.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/grade-school/GradeSchool.csproj +++ b/exercises/practice/grade-school/GradeSchool.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/grains/Grains.csproj b/exercises/practice/grains/Grains.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/grains/Grains.csproj +++ b/exercises/practice/grains/Grains.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/grep/.meta/Example.cs b/exercises/practice/grep/.meta/Example.cs index 7b20619f3..ff19ede7c 100644 --- a/exercises/practice/grep/.meta/Example.cs +++ b/exercises/practice/grep/.meta/Example.cs @@ -6,12 +6,7 @@ public static class Grep { - private class Line - { - public int Number { get; set; } - public string Text { get; set; } - public string File { get; set; } - } + private record Line(string File, int Number, string Text); [Flags] private enum Flags @@ -69,7 +64,7 @@ private static IEnumerable FindMatchingLines(string pattern, Flags flags, .Where(isMatch); } - private static Line CreateLine(string file, int index, string text) => new Line { File = file, Number = index + 1, Text = text }; + private static Line CreateLine(string file, int index, string text) => new(file, index + 1, text); private static string FormatMatchingFile(string file) => $"{file}"; @@ -87,20 +82,13 @@ private static string FormatMatchingLine(Flags flags, string[] files, Line line) var printLineNumbers = flags.HasFlag(Flags.PrintLineNumbers); var printFileName = files.Length > 1; - if (printLineNumbers && printFileName) - { - return $"{line.File}:{line.Number}:{line.Text}"; - } - if (printLineNumbers && !printFileName) + return printLineNumbers switch { - return $"{line.Number}:{line.Text}"; - } - if (!printLineNumbers && printFileName) - { - return $"{line.File}:{line.Text}"; - } - - return $"{line.Text}"; + true when printFileName => $"{line.File}:{line.Number}:{line.Text}", + true when !printFileName => $"{line.Number}:{line.Text}", + false when printFileName => $"{line.File}:{line.Text}", + _ => $"{line.Text}" + }; } private static string FormatMatchingLines(string pattern, Flags flags, string[] files) diff --git a/exercises/practice/grep/Grep.csproj b/exercises/practice/grep/Grep.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/grep/Grep.csproj +++ b/exercises/practice/grep/Grep.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/hamming/Hamming.csproj b/exercises/practice/hamming/Hamming.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/hamming/Hamming.csproj +++ b/exercises/practice/hamming/Hamming.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/hangman/Hangman.csproj b/exercises/practice/hangman/Hangman.csproj index c3258489c..7f50231b9 100644 --- a/exercises/practice/hangman/Hangman.csproj +++ b/exercises/practice/hangman/Hangman.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/hangman/HangmanTests.cs b/exercises/practice/hangman/HangmanTests.cs index e8d17505a..b9d978711 100644 --- a/exercises/practice/hangman/HangmanTests.cs +++ b/exercises/practice/hangman/HangmanTests.cs @@ -49,8 +49,10 @@ public void Initial_state_has_no_guessed_chars() public void Guess_changes_state() { var hangman = new Hangman("foo"); - HangmanState actual = null; + HangmanState? actual = null; hangman.StateObservable.Subscribe(x => actual = x); + + Assert.NotNull(actual); var initial = actual; // +--x-> @@ -64,8 +66,10 @@ public void Guess_changes_state() public void Wrong_guess_decrements_remaining_guesses() { var hangman = new Hangman("foo"); - HangmanState actual = null; + HangmanState? actual = null; hangman.StateObservable.Subscribe(x => actual = x); + + Assert.NotNull(actual); var initial = actual; // +--x-> diff --git a/exercises/practice/hello-world/HelloWorld.csproj b/exercises/practice/hello-world/HelloWorld.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/hello-world/HelloWorld.csproj +++ b/exercises/practice/hello-world/HelloWorld.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/hexadecimal/Hexadecimal.csproj b/exercises/practice/hexadecimal/Hexadecimal.csproj index 09fcf4d6e..5553da3b4 100644 --- a/exercises/practice/hexadecimal/Hexadecimal.csproj +++ b/exercises/practice/hexadecimal/Hexadecimal.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/high-scores/HighScores.csproj b/exercises/practice/high-scores/HighScores.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/high-scores/HighScores.csproj +++ b/exercises/practice/high-scores/HighScores.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/house/House.csproj b/exercises/practice/house/House.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/house/House.csproj +++ b/exercises/practice/house/House.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/isbn-verifier/IsbnVerifier.csproj b/exercises/practice/isbn-verifier/IsbnVerifier.csproj index 30782f122..8df4cb678 100644 --- a/exercises/practice/isbn-verifier/IsbnVerifier.csproj +++ b/exercises/practice/isbn-verifier/IsbnVerifier.csproj @@ -3,6 +3,7 @@ Exe net9.0 + enable true diff --git a/exercises/practice/isogram/Isogram.csproj b/exercises/practice/isogram/Isogram.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/isogram/Isogram.csproj +++ b/exercises/practice/isogram/Isogram.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/killer-sudoku-helper/KillerSudokuHelper.csproj b/exercises/practice/killer-sudoku-helper/KillerSudokuHelper.csproj index be8126449..8b75d52b0 100644 --- a/exercises/practice/killer-sudoku-helper/KillerSudokuHelper.csproj +++ b/exercises/practice/killer-sudoku-helper/KillerSudokuHelper.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/kindergarten-garden/KindergartenGarden.csproj b/exercises/practice/kindergarten-garden/KindergartenGarden.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/kindergarten-garden/KindergartenGarden.csproj +++ b/exercises/practice/kindergarten-garden/KindergartenGarden.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/knapsack/Knapsack.csproj b/exercises/practice/knapsack/Knapsack.csproj index c97331f70..ce2468564 100644 --- a/exercises/practice/knapsack/Knapsack.csproj +++ b/exercises/practice/knapsack/Knapsack.csproj @@ -7,6 +7,7 @@ false true + enable true diff --git a/exercises/practice/largest-series-product/LargestSeriesProduct.csproj b/exercises/practice/largest-series-product/LargestSeriesProduct.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/largest-series-product/LargestSeriesProduct.csproj +++ b/exercises/practice/largest-series-product/LargestSeriesProduct.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/leap/Leap.csproj b/exercises/practice/leap/Leap.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/leap/Leap.csproj +++ b/exercises/practice/leap/Leap.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/ledger/Ledger.csproj b/exercises/practice/ledger/Ledger.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/ledger/Ledger.csproj +++ b/exercises/practice/ledger/Ledger.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/linked-list/.meta/Example.cs b/exercises/practice/linked-list/.meta/Example.cs index ecd4479c4..9c2da8c96 100644 --- a/exercises/practice/linked-list/.meta/Example.cs +++ b/exercises/practice/linked-list/.meta/Example.cs @@ -1,6 +1,6 @@ public class Deque { - private Element head; + private Element? head; public void Push(T value) { @@ -10,7 +10,7 @@ public void Push(T value) } else { - var last = head.Next; + var last = head.Next!; var e = new Element(value, last, head); last.Prev = e; head.Next = e; @@ -19,27 +19,27 @@ public void Push(T value) public T Pop() { - head = head.Next; + head = head?.Next; return Shift(); } public void Unshift(T value) { Push(value); - head = head.Next; + head = head?.Next; } public T Shift() { - var value = head.Value; - var last = head.Next; + var value = head!.Value; + var last = head.Next!; if (last == head) head = null; else { last.Prev = head.Prev; - head.Prev.Next = last; + head.Prev!.Next = last; head = head.Prev; } @@ -49,10 +49,10 @@ public T Shift() private class Element { public readonly T Value; - public Element Next; - public Element Prev; + public Element? Next; + public Element? Prev; - public Element(T value, Element next = null, Element prev = null) + public Element(T value, Element? next = null, Element? prev = null) { Value = value; Next = next ?? this; diff --git a/exercises/practice/linked-list/LinkedList.csproj b/exercises/practice/linked-list/LinkedList.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/linked-list/LinkedList.csproj +++ b/exercises/practice/linked-list/LinkedList.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/list-ops/ListOps.csproj b/exercises/practice/list-ops/ListOps.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/list-ops/ListOps.csproj +++ b/exercises/practice/list-ops/ListOps.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/luhn/Luhn.csproj b/exercises/practice/luhn/Luhn.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/luhn/Luhn.csproj +++ b/exercises/practice/luhn/Luhn.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/markdown/.meta/Example.cs b/exercises/practice/markdown/.meta/Example.cs index e0e2107dc..e5520715b 100644 --- a/exercises/practice/markdown/.meta/Example.cs +++ b/exercises/practice/markdown/.meta/Example.cs @@ -39,7 +39,7 @@ private static string ParseText(this string markdown, bool list) return list ? textHtml : textHtml.WrapInTag(ParagraphTag); } - private static Tuple ParseHeader(this string markdown, bool list) + private static Tuple? ParseHeader(this string markdown, bool list) { var headerNumber = markdown @@ -56,7 +56,7 @@ private static Tuple ParseHeader(this string markdown, bool list) return Tuple.Create(false, html); } - private static Tuple ParseLineItem(this string markdown, bool list) + private static Tuple? ParseLineItem(this string markdown, bool list) { if (!markdown.StartsWith(ListItemMarkdown)) return null; @@ -105,4 +105,4 @@ public static string Parse(string markdown) return list ? html + ClosingTag(ListTag) : html; } -} \ No newline at end of file +} diff --git a/exercises/practice/markdown/Markdown.csproj b/exercises/practice/markdown/Markdown.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/markdown/Markdown.csproj +++ b/exercises/practice/markdown/Markdown.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/matching-brackets/MatchingBrackets.csproj b/exercises/practice/matching-brackets/MatchingBrackets.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/matching-brackets/MatchingBrackets.csproj +++ b/exercises/practice/matching-brackets/MatchingBrackets.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/matrix/Matrix.csproj b/exercises/practice/matrix/Matrix.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/matrix/Matrix.csproj +++ b/exercises/practice/matrix/Matrix.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/meetup/Meetup.csproj b/exercises/practice/meetup/Meetup.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/meetup/Meetup.csproj +++ b/exercises/practice/meetup/Meetup.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/minesweeper/Minesweeper.csproj b/exercises/practice/minesweeper/Minesweeper.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/minesweeper/Minesweeper.csproj +++ b/exercises/practice/minesweeper/Minesweeper.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/nth-prime/NthPrime.csproj b/exercises/practice/nth-prime/NthPrime.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/nth-prime/NthPrime.csproj +++ b/exercises/practice/nth-prime/NthPrime.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/nucleotide-count/NucleotideCount.csproj b/exercises/practice/nucleotide-count/NucleotideCount.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/nucleotide-count/NucleotideCount.csproj +++ b/exercises/practice/nucleotide-count/NucleotideCount.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/ocr-numbers/OcrNumbers.csproj b/exercises/practice/ocr-numbers/OcrNumbers.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/ocr-numbers/OcrNumbers.csproj +++ b/exercises/practice/ocr-numbers/OcrNumbers.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/octal/Octal.csproj b/exercises/practice/octal/Octal.csproj index 09fcf4d6e..5553da3b4 100644 --- a/exercises/practice/octal/Octal.csproj +++ b/exercises/practice/octal/Octal.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/palindrome-products/PalindromeProducts.csproj b/exercises/practice/palindrome-products/PalindromeProducts.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/palindrome-products/PalindromeProducts.csproj +++ b/exercises/practice/palindrome-products/PalindromeProducts.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/pangram/Pangram.csproj b/exercises/practice/pangram/Pangram.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/pangram/Pangram.csproj +++ b/exercises/practice/pangram/Pangram.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/parallel-letter-frequency/ParallelLetterFrequency.csproj b/exercises/practice/parallel-letter-frequency/ParallelLetterFrequency.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/parallel-letter-frequency/ParallelLetterFrequency.csproj +++ b/exercises/practice/parallel-letter-frequency/ParallelLetterFrequency.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/pascals-triangle/PascalsTriangle.csproj b/exercises/practice/pascals-triangle/PascalsTriangle.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/pascals-triangle/PascalsTriangle.csproj +++ b/exercises/practice/pascals-triangle/PascalsTriangle.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/perfect-numbers/PerfectNumbers.csproj b/exercises/practice/perfect-numbers/PerfectNumbers.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/perfect-numbers/PerfectNumbers.csproj +++ b/exercises/practice/perfect-numbers/PerfectNumbers.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/phone-number/PhoneNumber.csproj b/exercises/practice/phone-number/PhoneNumber.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/phone-number/PhoneNumber.csproj +++ b/exercises/practice/phone-number/PhoneNumber.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/pig-latin/PigLatin.csproj b/exercises/practice/pig-latin/PigLatin.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/pig-latin/PigLatin.csproj +++ b/exercises/practice/pig-latin/PigLatin.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/poker/Poker.csproj b/exercises/practice/poker/Poker.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/poker/Poker.csproj +++ b/exercises/practice/poker/Poker.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/pov/.meta/Example.cs b/exercises/practice/pov/.meta/Example.cs index 4a2f612f9..5c0cabf91 100644 --- a/exercises/practice/pov/.meta/Example.cs +++ b/exercises/practice/pov/.meta/Example.cs @@ -10,9 +10,14 @@ public Tree(string value, params Tree[] children) public string Value { get; } public Tree[] Children { get; } - public bool Equals(Tree other) - => Value.Equals(other.Value) && + public bool Equals(Tree? other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + + return Value.Equals(other.Value) && Children.OrderBy(child => child.Value).SequenceEqual(other.Children.OrderBy(child => child.Value)); + } } public class TreeCrumb @@ -38,23 +43,31 @@ public static class Pov { public static Tree FromPov(Tree graph, string value) { - var zipper = FindNode(value, GraphToZipper(graph)); + var zipper = GraphToZipper(graph); if (zipper == null) throw new ArgumentException(); + + var node = FindNode(value, zipper); + if (node == null) + throw new ArgumentException(); - return ChangeParent(zipper); + return ChangeParent(node); } public static IEnumerable PathTo(string value1, string value2, Tree graph) { - var zipper = FindNode(value2, GraphToZipper(FromPov(graph, value1))); + var zipper = GraphToZipper(FromPov(graph, value1)); if (zipper == null) throw new ArgumentException(); - return ZipperToPath(zipper); + var node = FindNode(value2, zipper); + if (node == null) + throw new ArgumentException(); + + return ZipperToPath(node); } - private static TreeZipper GraphToZipper(Tree graph) + private static TreeZipper? GraphToZipper(Tree graph) { if (graph == null) return null; @@ -64,10 +77,10 @@ private static TreeZipper GraphToZipper(Tree graph) private static IEnumerable ZipperToPath(TreeZipper zipper) { - return zipper?.Crumbs.Select(c => c.Value).Reverse().Concat(new[] { zipper.Focus.Value }); + return zipper.Crumbs.Select(c => c.Value).Reverse().Concat(new[] { zipper.Focus.Value }); } - private static TreeZipper GoDown(TreeZipper zipper) + private static TreeZipper? GoDown(TreeZipper zipper) { if (zipper == null || !zipper.Focus.Children.Any()) return null; @@ -80,7 +93,7 @@ private static TreeZipper GoDown(TreeZipper zipper) return new TreeZipper(children.First(), new[] { newCrumb }.Concat(zipper.Crumbs)); } - private static TreeZipper GoRight(TreeZipper zipper) + private static TreeZipper? GoRight(TreeZipper zipper) { if (zipper == null || !zipper.Crumbs.Any() || !zipper.Crumbs.First().Right.Any()) return null; @@ -93,7 +106,7 @@ private static TreeZipper GoRight(TreeZipper zipper) return new TreeZipper(firstCrumb.Right.First(), new[] { newCrumb }.Concat(crumbs.Skip(1))); } - private static TreeZipper FindNode(string value, TreeZipper zipper) + private static TreeZipper? FindNode(string value, TreeZipper? zipper) { if (zipper == null || zipper.Focus.Value.CompareTo(value) == 0) return zipper; @@ -103,9 +116,6 @@ private static TreeZipper FindNode(string value, TreeZipper zipper) private static Tree ChangeParent(TreeZipper zipper) { - if (zipper == null) - return null; - if (!zipper.Crumbs.Any()) return zipper.Focus; diff --git a/exercises/practice/pov/Pov.csproj b/exercises/practice/pov/Pov.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/pov/Pov.csproj +++ b/exercises/practice/pov/Pov.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/prime-factors/PrimeFactors.csproj b/exercises/practice/prime-factors/PrimeFactors.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/prime-factors/PrimeFactors.csproj +++ b/exercises/practice/prime-factors/PrimeFactors.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/protein-translation/ProteinTranslation.csproj b/exercises/practice/protein-translation/ProteinTranslation.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/protein-translation/ProteinTranslation.csproj +++ b/exercises/practice/protein-translation/ProteinTranslation.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/proverb/Proverb.csproj b/exercises/practice/proverb/Proverb.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/proverb/Proverb.csproj +++ b/exercises/practice/proverb/Proverb.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/pythagorean-triplet/PythagoreanTriplet.csproj b/exercises/practice/pythagorean-triplet/PythagoreanTriplet.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/pythagorean-triplet/PythagoreanTriplet.csproj +++ b/exercises/practice/pythagorean-triplet/PythagoreanTriplet.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/queen-attack/QueenAttack.csproj b/exercises/practice/queen-attack/QueenAttack.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/queen-attack/QueenAttack.csproj +++ b/exercises/practice/queen-attack/QueenAttack.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/rail-fence-cipher/RailFenceCipher.csproj b/exercises/practice/rail-fence-cipher/RailFenceCipher.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/rail-fence-cipher/RailFenceCipher.csproj +++ b/exercises/practice/rail-fence-cipher/RailFenceCipher.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/raindrops/Raindrops.csproj b/exercises/practice/raindrops/Raindrops.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/raindrops/Raindrops.csproj +++ b/exercises/practice/raindrops/Raindrops.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/rational-numbers/RationalNumbers.csproj b/exercises/practice/rational-numbers/RationalNumbers.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/rational-numbers/RationalNumbers.csproj +++ b/exercises/practice/rational-numbers/RationalNumbers.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/react/.meta/Example.cs b/exercises/practice/react/.meta/Example.cs index 9004ef247..f475ee47a 100644 --- a/exercises/practice/react/.meta/Example.cs +++ b/exercises/practice/react/.meta/Example.cs @@ -25,8 +25,11 @@ public ComputeCell CreateComputeCell(IEnumerable producers, Func Changed; + public override event EventHandler? Changed; public override int Value { @@ -107,7 +110,7 @@ public ComputeCell(int id, IEnumerable producers, Func compute } public override int Value { get; set; } - public override event EventHandler Changed; + public override event EventHandler? Changed; public void Recompute() { diff --git a/exercises/practice/react/React.csproj b/exercises/practice/react/React.csproj index 7b04d6762..f39ce9954 100644 --- a/exercises/practice/react/React.csproj +++ b/exercises/practice/react/React.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/rectangles/Rectangles.csproj b/exercises/practice/rectangles/Rectangles.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/rectangles/Rectangles.csproj +++ b/exercises/practice/rectangles/Rectangles.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/resistor-color-duo/ResistorColorDuo.csproj b/exercises/practice/resistor-color-duo/ResistorColorDuo.csproj index fdd0e59e0..c0cd30d09 100644 --- a/exercises/practice/resistor-color-duo/ResistorColorDuo.csproj +++ b/exercises/practice/resistor-color-duo/ResistorColorDuo.csproj @@ -2,6 +2,7 @@ net9.0 false + enable true diff --git a/exercises/practice/resistor-color-trio/ResistorColorTrio.csproj b/exercises/practice/resistor-color-trio/ResistorColorTrio.csproj index 13329d6f9..3f97a1ab2 100644 --- a/exercises/practice/resistor-color-trio/ResistorColorTrio.csproj +++ b/exercises/practice/resistor-color-trio/ResistorColorTrio.csproj @@ -2,6 +2,7 @@ net9.0 false + enable true diff --git a/exercises/practice/resistor-color/ResistorColor.csproj b/exercises/practice/resistor-color/ResistorColor.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/resistor-color/ResistorColor.csproj +++ b/exercises/practice/resistor-color/ResistorColor.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/rest-api/.meta/Example.cs b/exercises/practice/rest-api/.meta/Example.cs index 68004dc8f..f60e09a41 100644 --- a/exercises/practice/rest-api/.meta/Example.cs +++ b/exercises/practice/rest-api/.meta/Example.cs @@ -84,14 +84,14 @@ public class RestApi public RestApi(string database) { - users = JsonSerializer.Deserialize>(database); + users = JsonSerializer.Deserialize>(database)!; } - public string Get(string url, string payload = null) + public string Get(string url, string? payload = null) { if (payload != null) { - var values = JsonSerializer.Deserialize>>(payload); + var values = JsonSerializer.Deserialize>>(payload)!; var requestedUsers = values["users"]; return JsonSerializer.Serialize(users.Where(x => requestedUsers.Contains(x.name))); } @@ -104,22 +104,22 @@ public string Post(string url, string payload) if (url == "/add") { var values = JsonSerializer.Deserialize>(payload); - var newUser = new User(values["user"]); + var newUser = new User(values!["user"]); users.Add(newUser); return JsonSerializer.Serialize(newUser); } else if (url == "/iou") { - var values = JsonSerializer.Deserialize>(payload); + var values = JsonSerializer.Deserialize>(payload)!; var lender = users.First(x => x.name.Equals(values["lender"].ToString())); var borrower = users.First(x => x.name.Equals(values["borrower"].ToString())); - var amount = double.Parse(values["amount"].ToString()); + var amount = double.Parse(values["amount"].ToString()!); lender.Lend(borrower, amount); borrower.Borrow(lender, amount); return JsonSerializer.Serialize(new[] { lender, borrower }.OrderBy(x => x.name)); } - return String.Empty; + return string.Empty; } } diff --git a/exercises/practice/rest-api/RestApi.cs b/exercises/practice/rest-api/RestApi.cs index 34403d207..6d86f608b 100644 --- a/exercises/practice/rest-api/RestApi.cs +++ b/exercises/practice/rest-api/RestApi.cs @@ -7,7 +7,7 @@ public RestApi(string database) throw new NotImplementedException("You need to implement this method."); } - public string Get(string url, string payload = null) + public string Get(string url, string? payload = null) { throw new NotImplementedException("You need to implement this method."); } diff --git a/exercises/practice/rest-api/RestApi.csproj b/exercises/practice/rest-api/RestApi.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/practice/rest-api/RestApi.csproj +++ b/exercises/practice/rest-api/RestApi.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/reverse-string/.articles/performance/code/Benchmark.csproj b/exercises/practice/reverse-string/.articles/performance/code/Benchmark.csproj index 7b8066878..b2010410c 100644 --- a/exercises/practice/reverse-string/.articles/performance/code/Benchmark.csproj +++ b/exercises/practice/reverse-string/.articles/performance/code/Benchmark.csproj @@ -6,6 +6,7 @@ enable enable Performance + enable true diff --git a/exercises/practice/reverse-string/ReverseString.csproj b/exercises/practice/reverse-string/ReverseString.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/reverse-string/ReverseString.csproj +++ b/exercises/practice/reverse-string/ReverseString.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/rna-transcription/RnaTranscription.csproj b/exercises/practice/rna-transcription/RnaTranscription.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/rna-transcription/RnaTranscription.csproj +++ b/exercises/practice/rna-transcription/RnaTranscription.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/robot-name/.meta/Example.cs b/exercises/practice/robot-name/.meta/Example.cs index e15b800b8..919cdabe1 100644 --- a/exercises/practice/robot-name/.meta/Example.cs +++ b/exercises/practice/robot-name/.meta/Example.cs @@ -10,7 +10,7 @@ public class Robot public Robot() { - Reset(); + Name = GenerateName(); } private static string GenerateName() diff --git a/exercises/practice/robot-name/RobotName.csproj b/exercises/practice/robot-name/RobotName.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/robot-name/RobotName.csproj +++ b/exercises/practice/robot-name/RobotName.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/robot-simulator/RobotSimulator.csproj b/exercises/practice/robot-simulator/RobotSimulator.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/robot-simulator/RobotSimulator.csproj +++ b/exercises/practice/robot-simulator/RobotSimulator.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/roman-numerals/RomanNumerals.csproj b/exercises/practice/roman-numerals/RomanNumerals.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/roman-numerals/RomanNumerals.csproj +++ b/exercises/practice/roman-numerals/RomanNumerals.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/rotational-cipher/RotationalCipher.csproj b/exercises/practice/rotational-cipher/RotationalCipher.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/rotational-cipher/RotationalCipher.csproj +++ b/exercises/practice/rotational-cipher/RotationalCipher.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/run-length-encoding/RunLengthEncoding.csproj b/exercises/practice/run-length-encoding/RunLengthEncoding.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/run-length-encoding/RunLengthEncoding.csproj +++ b/exercises/practice/run-length-encoding/RunLengthEncoding.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/saddle-points/SaddlePoints.csproj b/exercises/practice/saddle-points/SaddlePoints.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/saddle-points/SaddlePoints.csproj +++ b/exercises/practice/saddle-points/SaddlePoints.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/satellite/.meta/Example.cs b/exercises/practice/satellite/.meta/Example.cs index 7aa521222..d9a1f742a 100644 --- a/exercises/practice/satellite/.meta/Example.cs +++ b/exercises/practice/satellite/.meta/Example.cs @@ -1,11 +1,11 @@ using System; using System.Linq; -public record Tree(char Value, Tree Left, Tree Right); +public record Tree(char Value, Tree? Left, Tree? Right); public static class Satellite { - public static Tree TreeFromTraversals(char[] preOrder, char[] inOrder) + public static Tree? TreeFromTraversals(char[] preOrder, char[] inOrder) { if (preOrder.Length != inOrder.Length) throw new ArgumentException("Traversals must have the same length"); if (!preOrder.Order().SequenceEqual(inOrder.Order())) throw new ArgumentException("Traversals must be consistent"); @@ -15,7 +15,7 @@ public static Tree TreeFromTraversals(char[] preOrder, char[] inOrder) return TreeFromTraversals(preOrder, inOrder, ref preOrderIndex, 0, preOrder.Length - 1); } - private static Tree TreeFromTraversals(char[] preOrder, char[] inOrder, ref int preOrderIndex, int left, int right) + private static Tree? TreeFromTraversals(char[] preOrder, char[] inOrder, ref int preOrderIndex, int left, int right) { if (left > right) return null; diff --git a/exercises/practice/satellite/Satellite.cs b/exercises/practice/satellite/Satellite.cs index 1015c99f7..8868feeb1 100644 --- a/exercises/practice/satellite/Satellite.cs +++ b/exercises/practice/satellite/Satellite.cs @@ -1,10 +1,10 @@ using System; -public record Tree(char Value, Tree Left, Tree Right); +public record Tree(char Value, Tree? Left, Tree? Right); public static class Satellite { - public static Tree TreeFromTraversals(char[] preOrder, char[] inOrder) + public static Tree? TreeFromTraversals(char[] preOrder, char[] inOrder) { throw new NotImplementedException("You need to implement this method."); } diff --git a/exercises/practice/satellite/Satellite.csproj b/exercises/practice/satellite/Satellite.csproj index bffca349b..8c2df9cd7 100644 --- a/exercises/practice/satellite/Satellite.csproj +++ b/exercises/practice/satellite/Satellite.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/say/.meta/Example.cs b/exercises/practice/say/.meta/Example.cs index b89f72663..e9ce4648b 100644 --- a/exercises/practice/say/.meta/Example.cs +++ b/exercises/practice/say/.meta/Example.cs @@ -32,10 +32,10 @@ private static IEnumerable Parts(long number) var thousands = Thousands(thousandsCount); var hundreds = Hundreds(remainder); - return new[] { billions, millions, thousands, hundreds }.Where(x => x != null); + return new[] { billions, millions, thousands, hundreds }.Where(x => x != null).Cast(); } - private static string Bases(long number) + private static string? Bases(long number) { var values = new[] { @@ -63,7 +63,7 @@ private static string Bases(long number) return number > 0 && number <= values.Length ? values[number - 1] : null; } - private static string Tens(long number) + private static string? Tens(long number) { if (number < 20L) { @@ -92,7 +92,7 @@ private static string Tens(long number) return $"{countStr}{basesStr}"; } - private static string Hundreds(long number) + private static string? Hundreds(long number) { if (number < 100L) { @@ -108,15 +108,15 @@ private static string Hundreds(long number) return $"{bases} hundred{tensStr}"; } - private static string Chunk(string str, long number) + private static string? Chunk(string str, long number) { var hundreds = Hundreds(number); return hundreds == null ? null : $"{hundreds} {str}"; } - private static string Thousands(long number) => Chunk("thousand", number); - private static string Millions(long number) => Chunk("million", number); - private static string Billions(long number) => Chunk("billion", number); + private static string? Thousands(long number) => Chunk("thousand", number); + private static string? Millions(long number) => Chunk("million", number); + private static string? Billions(long number) => Chunk("billion", number); private static Tuple Counts(long number) { @@ -131,4 +131,4 @@ private static Tuple Counts(long number) return Tuple.Create(billionsCount, millionsCount, thousandsCount, thousandsRemainder); } -} \ No newline at end of file +} diff --git a/exercises/practice/say/Say.csproj b/exercises/practice/say/Say.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/say/Say.csproj +++ b/exercises/practice/say/Say.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/scale-generator/ScaleGenerator.csproj b/exercises/practice/scale-generator/ScaleGenerator.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/scale-generator/ScaleGenerator.csproj +++ b/exercises/practice/scale-generator/ScaleGenerator.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/scrabble-score/ScrabbleScore.csproj b/exercises/practice/scrabble-score/ScrabbleScore.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/scrabble-score/ScrabbleScore.csproj +++ b/exercises/practice/scrabble-score/ScrabbleScore.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/secret-handshake/SecretHandshake.csproj b/exercises/practice/secret-handshake/SecretHandshake.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/secret-handshake/SecretHandshake.csproj +++ b/exercises/practice/secret-handshake/SecretHandshake.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/series/Series.csproj b/exercises/practice/series/Series.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/series/Series.csproj +++ b/exercises/practice/series/Series.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/sgf-parsing/.meta/Example.cs b/exercises/practice/sgf-parsing/.meta/Example.cs index 12b4ebb08..66e7e155d 100644 --- a/exercises/practice/sgf-parsing/.meta/Example.cs +++ b/exercises/practice/sgf-parsing/.meta/Example.cs @@ -14,12 +14,15 @@ public SgfTree(IDictionary data, params SgfTree[] children) Children = children; } - public bool Equals(SgfTree other) + public bool Equals(SgfTree? other) { + if (other == null) + return false; + var otherData = other.Data; foreach (var d in Data) - if (!d.Value.SequenceEqual(otherData.Where(od => od.Key == d.Key)?.FirstOrDefault().Value)) + if (!d.Value.SequenceEqual(otherData.Where(od => od.Key == d.Key)?.FirstOrDefault().Value ?? [])) return false; if (Children != null) @@ -93,4 +96,4 @@ private static SgfTree NodesToTree(IEnumerable> pr return new SgfTree(properties.First(), NodesToTree(properties.Skip(1), trees)); } -} \ No newline at end of file +} diff --git a/exercises/practice/sgf-parsing/SgfParsing.csproj b/exercises/practice/sgf-parsing/SgfParsing.csproj index b50f77bd0..b0d0bd802 100644 --- a/exercises/practice/sgf-parsing/SgfParsing.csproj +++ b/exercises/practice/sgf-parsing/SgfParsing.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/sieve/Sieve.csproj b/exercises/practice/sieve/Sieve.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/sieve/Sieve.csproj +++ b/exercises/practice/sieve/Sieve.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/simple-cipher/SimpleCipher.csproj b/exercises/practice/simple-cipher/SimpleCipher.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/simple-cipher/SimpleCipher.csproj +++ b/exercises/practice/simple-cipher/SimpleCipher.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/simple-linked-list/.meta/Example.cs b/exercises/practice/simple-linked-list/.meta/Example.cs index ba5e08b6b..e9a606443 100644 --- a/exercises/practice/simple-linked-list/.meta/Example.cs +++ b/exercises/practice/simple-linked-list/.meta/Example.cs @@ -5,11 +5,11 @@ public class SimpleLinkedList : IEnumerable { private class Node { - public T Value { get; set; } - public Node Next { get; set; } + public required T Value { get; set; } + public Node? Next { get; set; } } - private Node head; + private Node? _head; public SimpleLinkedList() { } @@ -24,25 +24,25 @@ public SimpleLinkedList(params T[] values) public void Push(T value) { - var node = new Node { Value = value, Next = this.head }; - this.head = node; + var node = new Node { Value = value, Next = this._head }; + this._head = node; this.Count++; } public T Pop() { - if (this.head == null) { + if (this._head == null) { throw new InvalidOperationException("List is empty!"); } - var value = head.Value; - head = head.Next; + var value = _head.Value; + _head = _head.Next; this.Count--; return value; } public IEnumerator GetEnumerator() { - var current = this.head; + var current = this._head; while(current != null) { yield return current.Value; current = current.Next; @@ -50,4 +50,4 @@ public IEnumerator GetEnumerator() } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); -} \ No newline at end of file +} diff --git a/exercises/practice/simple-linked-list/SimpleLinkedList.csproj b/exercises/practice/simple-linked-list/SimpleLinkedList.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/simple-linked-list/SimpleLinkedList.csproj +++ b/exercises/practice/simple-linked-list/SimpleLinkedList.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/simple-linked-list/SimpleLinkedListTests.cs b/exercises/practice/simple-linked-list/SimpleLinkedListTests.cs index 3d78d198d..376ee37a7 100644 --- a/exercises/practice/simple-linked-list/SimpleLinkedListTests.cs +++ b/exercises/practice/simple-linked-list/SimpleLinkedListTests.cs @@ -16,8 +16,9 @@ public void Empty_list_has_no_elements() public void Count_cannot_be_changed_from_the_outside() { var count = typeof(SimpleLinkedList<>).GetProperty("Count"); - Assert.True(count?.GetGetMethod().IsPublic); - Assert.False(count?.GetSetMethod(true).IsPublic); + Assert.NotNull(count); + Assert.True(count.GetGetMethod() is { IsPublic: true }); + Assert.False(count.GetSetMethod(true) is { IsPublic: true }); } [Fact(Skip = "Remove this Skip property to run this test")] @@ -56,16 +57,17 @@ public void Elements_pop_back_in_lifo_order() private static SimpleLinkedList CreateSimpleLinkedList(int value) { var type = typeof(SimpleLinkedList<>).MakeGenericType(typeof(int)); - var constructor = type.GetConstructor(new Type[] { typeof(int) }); - return (SimpleLinkedList)constructor?.Invoke(new object[]{ value }) - ?? CreateSimpleLinkedList(new int[] { value }); + var constructor = type.GetConstructor([typeof(int)]); + return (SimpleLinkedList?)constructor?.Invoke([value]) + ?? CreateSimpleLinkedList([value]); } private static SimpleLinkedList CreateSimpleLinkedList(params int[] values) { var type = typeof(SimpleLinkedList<>).MakeGenericType(typeof(int)); - var constructor = type.GetConstructor(new Type[]{typeof(int[])}); - return (SimpleLinkedList)constructor.Invoke(new object[]{ values }); + var constructor = type.GetConstructor([typeof(int[])]); + Assert.NotNull(constructor); + return (SimpleLinkedList)constructor.Invoke([values]); } [Fact(Skip = "Remove this Skip property to run this test")] @@ -114,4 +116,4 @@ public void Roundtrip() var enumerable = Assert.IsAssignableFrom>(list); Assert.Equal(values.Reverse(), enumerable); } -} \ No newline at end of file +} diff --git a/exercises/practice/space-age/SpaceAge.csproj b/exercises/practice/space-age/SpaceAge.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/space-age/SpaceAge.csproj +++ b/exercises/practice/space-age/SpaceAge.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/spiral-matrix/SpiralMatrix.csproj b/exercises/practice/spiral-matrix/SpiralMatrix.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/practice/spiral-matrix/SpiralMatrix.csproj +++ b/exercises/practice/spiral-matrix/SpiralMatrix.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/square-root/SquareRoot.csproj b/exercises/practice/square-root/SquareRoot.csproj index 3214d97dc..8b9b0b9c0 100644 --- a/exercises/practice/square-root/SquareRoot.csproj +++ b/exercises/practice/square-root/SquareRoot.csproj @@ -7,6 +7,7 @@ false true + enable true diff --git a/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.cs b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.cs index 84169e52c..f4cb9e1ef 100644 --- a/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.cs +++ b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.cs @@ -8,8 +8,13 @@ public enum State Invalid } -public class TicTacToe(string[] rows) +public class TicTacToe { + public TicTacToe(string[] rows) + { + throw new NotImplementedException("Please implement this constructor"); + } + public State State { get diff --git a/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.csproj b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.csproj index 063306774..b1f643db5 100644 --- a/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.csproj +++ b/exercises/practice/state-of-tic-tac-toe/StateOfTicTacToe.csproj @@ -2,6 +2,7 @@ net9.0 false + enable true diff --git a/exercises/practice/strain/Strain.csproj b/exercises/practice/strain/Strain.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/strain/Strain.csproj +++ b/exercises/practice/strain/Strain.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/sublist/Sublist.csproj b/exercises/practice/sublist/Sublist.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/sublist/Sublist.csproj +++ b/exercises/practice/sublist/Sublist.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/sum-of-multiples/SumOfMultiples.csproj b/exercises/practice/sum-of-multiples/SumOfMultiples.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/sum-of-multiples/SumOfMultiples.csproj +++ b/exercises/practice/sum-of-multiples/SumOfMultiples.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/tournament/.meta/Example.cs b/exercises/practice/tournament/.meta/Example.cs index d505c464e..bc3e2e975 100644 --- a/exercises/practice/tournament/.meta/Example.cs +++ b/exercises/practice/tournament/.meta/Example.cs @@ -69,8 +69,7 @@ private void AddResult(string team1, string team2, Outcome outcome) private void AddTeamOutcome(string team, Outcome outcome) { - TeamResult teamResult; - if (this.teams.TryGetValue(team, out teamResult)) { + if (this.teams.TryGetValue(team, out var teamResult)) { teamResult.AddOutcome(outcome); } else { teamResult = new TeamResult(); diff --git a/exercises/practice/tournament/Tournament.csproj b/exercises/practice/tournament/Tournament.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/tournament/Tournament.csproj +++ b/exercises/practice/tournament/Tournament.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/transpose/Transpose.csproj b/exercises/practice/transpose/Transpose.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/transpose/Transpose.csproj +++ b/exercises/practice/transpose/Transpose.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/tree-building/TreeBuilding.csproj b/exercises/practice/tree-building/TreeBuilding.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/tree-building/TreeBuilding.csproj +++ b/exercises/practice/tree-building/TreeBuilding.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/triangle/Triangle.csproj b/exercises/practice/triangle/Triangle.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/triangle/Triangle.csproj +++ b/exercises/practice/triangle/Triangle.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/trinary/Trinary.csproj b/exercises/practice/trinary/Trinary.csproj index 09fcf4d6e..5553da3b4 100644 --- a/exercises/practice/trinary/Trinary.csproj +++ b/exercises/practice/trinary/Trinary.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/twelve-days/TwelveDays.csproj b/exercises/practice/twelve-days/TwelveDays.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/twelve-days/TwelveDays.csproj +++ b/exercises/practice/twelve-days/TwelveDays.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/two-bucket/TwoBucket.csproj b/exercises/practice/two-bucket/TwoBucket.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/two-bucket/TwoBucket.csproj +++ b/exercises/practice/two-bucket/TwoBucket.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/two-fer/TwoFer.csproj b/exercises/practice/two-fer/TwoFer.csproj index 53f95ed2a..7625d0c3c 100644 --- a/exercises/practice/two-fer/TwoFer.csproj +++ b/exercises/practice/two-fer/TwoFer.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/variable-length-quantity/VariableLengthQuantity.csproj b/exercises/practice/variable-length-quantity/VariableLengthQuantity.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/variable-length-quantity/VariableLengthQuantity.csproj +++ b/exercises/practice/variable-length-quantity/VariableLengthQuantity.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/word-count/WordCount.csproj b/exercises/practice/word-count/WordCount.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/word-count/WordCount.csproj +++ b/exercises/practice/word-count/WordCount.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/word-search/WordSearch.csproj b/exercises/practice/word-search/WordSearch.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/word-search/WordSearch.csproj +++ b/exercises/practice/word-search/WordSearch.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/wordy/Wordy.csproj b/exercises/practice/wordy/Wordy.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/wordy/Wordy.csproj +++ b/exercises/practice/wordy/Wordy.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/yacht/Yacht.csproj b/exercises/practice/yacht/Yacht.csproj index be6641331..f569a5985 100644 --- a/exercises/practice/yacht/Yacht.csproj +++ b/exercises/practice/yacht/Yacht.csproj @@ -3,6 +3,7 @@ Exe net9.0 + enable true diff --git a/exercises/practice/zebra-puzzle/.meta/Example.cs b/exercises/practice/zebra-puzzle/.meta/Example.cs index 9ea564de7..1e87e0b13 100644 --- a/exercises/practice/zebra-puzzle/.meta/Example.cs +++ b/exercises/practice/zebra-puzzle/.meta/Example.cs @@ -108,11 +108,11 @@ public static Nationality OwnsZebra() return solution.Nationalities[Array.IndexOf(solution.Pets, Pet.Zebra)]; } - private static bool IsIndexMatch(T1[] values1, T1 value1, T2[] values2, T2 value2) => values2[Array.IndexOf(values1, value1)].Equals(value2); + private static bool IsIndexMatch(T1[] values1, T1 value1, T2[] values2, T2 value2) => values2[Array.IndexOf(values1, value1)]!.Equals(value2); private static bool IsAdjacentMatch(T1[] values1, T1 value1, T2[] values2, T2 value2) { var index = Array.IndexOf(values1, value1); - return (index > 0 && values2[index - 1].Equals(value2)) || (index < values2.Length - 1 && values2[index + 1].Equals(value2)); + return (index > 0 && values2[index - 1]!.Equals(value2)) || (index < values2.Length - 1 && values2[index + 1]!.Equals(value2)); } } \ No newline at end of file diff --git a/exercises/practice/zebra-puzzle/ZebraPuzzle.csproj b/exercises/practice/zebra-puzzle/ZebraPuzzle.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/zebra-puzzle/ZebraPuzzle.csproj +++ b/exercises/practice/zebra-puzzle/ZebraPuzzle.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/zipper/.meta/Example.cs b/exercises/practice/zipper/.meta/Example.cs index f3451371b..019c863b7 100644 --- a/exercises/practice/zipper/.meta/Example.cs +++ b/exercises/practice/zipper/.meta/Example.cs @@ -4,7 +4,7 @@ public class BinTree : IEquatable { - public BinTree(int value, BinTree left, BinTree right) + public BinTree(int value, BinTree? left, BinTree? right) { Value = value; Left = left; @@ -16,10 +16,10 @@ public BinTree(BinTree tree) : this(tree.Value, tree.Left, tree.Right) } public int Value { get; } - public BinTree Left { get; } - public BinTree Right { get; } + public BinTree? Left { get; } + public BinTree? Right { get; } - public bool Equals(BinTree other) + public bool Equals(BinTree? other) { if (other == null || !Equals(Value, other.Value)) return false; @@ -36,26 +36,26 @@ public bool Equals(BinTree other) public abstract class BinTreeCrumb { - public BinTreeCrumb(int value, BinTree tree) + public BinTreeCrumb(int value, BinTree? tree) { Value = value; Tree = tree; } public int Value { get; } - public BinTree Tree { get; } + public BinTree? Tree { get; } } public class BinTreeLeftCrumb : BinTreeCrumb { - public BinTreeLeftCrumb(int value, BinTree tree) : base(value, tree) + public BinTreeLeftCrumb(int value, BinTree? tree) : base(value, tree) { } } public class BinTreeRightCrumb : BinTreeCrumb { - public BinTreeRightCrumb(int value, BinTree tree) : base(value, tree) + public BinTreeRightCrumb(int value, BinTree? tree) : base(value, tree) { } } @@ -63,11 +63,11 @@ public BinTreeRightCrumb(int value, BinTree tree) : base(value, tree) public class Zipper : IEquatable { private readonly int value; - private readonly BinTree left; - private readonly BinTree right; + private readonly BinTree? left; + private readonly BinTree? right; private readonly List crumbs; - public Zipper(int value, BinTree left, BinTree right, List crumbs) + public Zipper(int value, BinTree? left, BinTree? right, List crumbs) { this.value = value; this.left = left; @@ -79,11 +79,11 @@ public Zipper(int value, BinTree left, BinTree right, List crumbs) public Zipper SetValue(int newValue) => new Zipper(newValue, left, right, crumbs); - public Zipper SetLeft(BinTree binTree) => new Zipper(value, binTree, right, crumbs); + public Zipper SetLeft(BinTree? binTree) => new Zipper(value, binTree, right, crumbs); - public Zipper SetRight(BinTree binTree) => new Zipper(value, left, binTree, crumbs); + public Zipper SetRight(BinTree? binTree) => new Zipper(value, left, binTree, crumbs); - public Zipper Left() + public Zipper? Left() { if (left == null) return null; @@ -92,7 +92,7 @@ public Zipper Left() return new Zipper(left.Value, left.Left, left.Right, newCrumbs); } - public Zipper Right() + public Zipper? Right() { if (right == null) return null; @@ -101,7 +101,7 @@ public Zipper Right() return new Zipper(right.Value, right.Left, right.Right, newCrumbs); } - public Zipper Up() + public Zipper? Up() { if (crumbs.Count == 0) return null; @@ -133,7 +133,7 @@ public BinTree ToTree() return tree; } - public bool Equals(Zipper other) + public bool Equals(Zipper? other) { if (other == null) return false; diff --git a/exercises/practice/zipper/.meta/Generator.tpl b/exercises/practice/zipper/.meta/Generator.tpl index 86c262085..10b3cef8c 100644 --- a/exercises/practice/zipper/.meta/Generator.tpl +++ b/exercises/practice/zipper/.meta/Generator.tpl @@ -45,7 +45,7 @@ end }} for op in $0 call = to_call op - calls = string.append calls $".{call}" + calls = string.append calls $"?.{call}" end ret calls diff --git a/exercises/practice/zipper/Zipper.cs b/exercises/practice/zipper/Zipper.cs index 29b063cb9..b0edd015a 100644 --- a/exercises/practice/zipper/Zipper.cs +++ b/exercises/practice/zipper/Zipper.cs @@ -2,14 +2,14 @@ public class BinTree { - public BinTree(int value, BinTree left, BinTree right) + public BinTree(int value, BinTree? left, BinTree? right) { throw new NotImplementedException("You need to implement this method."); } public int Value { get; } - public BinTree Left { get; } - public BinTree Right { get; } + public BinTree? Left { get; } + public BinTree? Right { get; } } public class Zipper @@ -24,27 +24,27 @@ public Zipper SetValue(int newValue) throw new NotImplementedException("You need to implement this method."); } - public Zipper SetLeft(BinTree binTree) + public Zipper SetLeft(BinTree? binTree) { throw new NotImplementedException("You need to implement this method."); } - public Zipper SetRight(BinTree binTree) + public Zipper SetRight(BinTree? binTree) { throw new NotImplementedException("You need to implement this method."); } - public Zipper Left() + public Zipper? Left() { throw new NotImplementedException("You need to implement this method."); } - public Zipper Right() + public Zipper? Right() { throw new NotImplementedException("You need to implement this method."); } - public Zipper Up() + public Zipper? Up() { throw new NotImplementedException("You need to implement this method."); } diff --git a/exercises/practice/zipper/Zipper.csproj b/exercises/practice/zipper/Zipper.csproj index 06c91ac7a..590e2b629 100644 --- a/exercises/practice/zipper/Zipper.csproj +++ b/exercises/practice/zipper/Zipper.csproj @@ -2,6 +2,7 @@ net9.0 + enable true diff --git a/exercises/practice/zipper/ZipperTests.cs b/exercises/practice/zipper/ZipperTests.cs index ae90ddc17..e19a57a6b 100644 --- a/exercises/practice/zipper/ZipperTests.cs +++ b/exercises/practice/zipper/ZipperTests.cs @@ -7,7 +7,7 @@ public void Data_is_retained() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.ToTree(); + var actual = sut?.ToTree(); var expected = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); Assert.Equal(expected, actual); } @@ -17,7 +17,7 @@ public void Left_right_and_value() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().Right().Value(); + var actual = sut?.Left()?.Right()?.Value(); var expected = 3; Assert.Equal(expected, actual); } @@ -27,7 +27,7 @@ public void Dead_end() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().Left(); + var actual = sut?.Left()?.Left(); Assert.Null(actual); } @@ -36,7 +36,7 @@ public void Tree_from_deep_focus() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().Right().ToTree(); + var actual = sut?.Left()?.Right()?.ToTree(); var expected = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); Assert.Equal(expected, actual); } @@ -46,7 +46,7 @@ public void Traversing_up_from_top() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Up(); + var actual = sut?.Up(); Assert.Null(actual); } @@ -55,7 +55,7 @@ public void Left_right_and_up() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().Up().Right().Up().Left().Right().Value(); + var actual = sut?.Left()?.Up()?.Right()?.Up()?.Left()?.Right()?.Value(); var expected = 3; Assert.Equal(expected, actual); } @@ -65,7 +65,7 @@ public void Test_ability_to_descend_multiple_levels_and_return() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().Right().Up().Up().Value(); + var actual = sut?.Left()?.Right()?.Up()?.Up()?.Value(); var expected = 1; Assert.Equal(expected, actual); } @@ -75,7 +75,7 @@ public void Set_value() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().SetValue(5).ToTree(); + var actual = sut?.Left()?.SetValue(5)?.ToTree(); var expected = new BinTree(1, new BinTree(5, null, new BinTree(3, null, null)), new BinTree(4, null, null)); Assert.Equal(expected, actual); } @@ -85,7 +85,7 @@ public void Set_value_after_traversing_up() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().Right().Up().SetValue(5).ToTree(); + var actual = sut?.Left()?.Right()?.Up()?.SetValue(5)?.ToTree(); var expected = new BinTree(1, new BinTree(5, null, new BinTree(3, null, null)), new BinTree(4, null, null)); Assert.Equal(expected, actual); } @@ -95,7 +95,7 @@ public void Set_left_with_leaf() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().SetLeft(new BinTree(5, null, null)).ToTree(); + var actual = sut?.Left()?.SetLeft(new BinTree(5, null, null))?.ToTree(); var expected = new BinTree(1, new BinTree(2, new BinTree(5, null, null), new BinTree(3, null, null)), new BinTree(4, null, null)); Assert.Equal(expected, actual); } @@ -105,7 +105,7 @@ public void Set_right_with_null() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().SetRight(null).ToTree(); + var actual = sut?.Left()?.SetRight(null)?.ToTree(); var expected = new BinTree(1, new BinTree(2, null, null), new BinTree(4, null, null)); Assert.Equal(expected, actual); } @@ -115,7 +115,7 @@ public void Set_right_with_subtree() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.SetRight(new BinTree(6, new BinTree(7, null, null), new BinTree(8, null, null))).ToTree(); + var actual = sut?.SetRight(new BinTree(6, new BinTree(7, null, null), new BinTree(8, null, null)))?.ToTree(); var expected = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(6, new BinTree(7, null, null), new BinTree(8, null, null))); Assert.Equal(expected, actual); } @@ -125,7 +125,7 @@ public void Set_value_on_deep_focus() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().Right().SetValue(5).ToTree(); + var actual = sut?.Left()?.Right()?.SetValue(5)?.ToTree(); var expected = new BinTree(1, new BinTree(2, null, new BinTree(5, null, null)), new BinTree(4, null, null)); Assert.Equal(expected, actual); } @@ -135,8 +135,8 @@ public void Different_paths_to_same_zipper() { var tree = new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)); var sut = Zipper.FromTree(tree); - var actual = sut.Left().Up().Right(); - var expected = Zipper.FromTree(new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null))).Right(); + var actual = sut?.Left()?.Up()?.Right(); + var expected = Zipper.FromTree(new BinTree(1, new BinTree(2, null, new BinTree(3, null, null)), new BinTree(4, null, null)))?.Right(); Assert.Equal(expected, actual); } }