├── Code Contracts ├── CodeContractsDemo.Tests │ ├── CodeContractsDemo.Tests.csproj │ ├── ERPWarehouseIntegrationTest.ProductionVolumePerBinTest.g.cs │ ├── ERPWarehouseIntegrationTest.cs │ ├── Factories │ │ └── ERPWarehouseIntegrationFactory.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── PexAssemblyInfo.cs │ └── obj │ │ └── Debug │ │ ├── CodeContractsDemo.Tests.csproj.FileListAbsolute.txt │ │ ├── CodeContractsDemo.Tests.csprojResolveAssemblyReference.cache │ │ ├── CodeContractsDemo.Tests.pdb.original │ │ ├── CodeContractsDemo.Testsccrewrite.rsp │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs └── CodeContractsDemo │ ├── .vs │ └── CodeContractsDemo │ │ └── v14 │ │ └── .suo │ ├── App.config │ ├── CodeContractsDemo.csproj │ ├── CodeContractsDemo.sln │ ├── ERPIntegration.cs │ ├── Human.cs │ ├── IShapeShiftable.cs │ ├── ITeachable.cs │ ├── Program.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── bin │ └── Debug │ │ ├── CodeContracts │ │ ├── CodeContractsDemo.Contracts.dll │ │ └── CodeContractsDemo.Contracts.pdb │ │ ├── CodeContractsDemo.XML │ │ ├── CodeContractsDemo.XML.old │ │ ├── CodeContractsDemo.exe │ │ ├── CodeContractsDemo.exe.config │ │ ├── CodeContractsDemo.pdb │ │ ├── CodeContractsDemo.vshost.exe │ │ ├── CodeContractsDemo.vshost.exe.config │ │ └── CodeContractsDemo.vshost.exe.manifest │ └── obj │ └── Debug │ ├── CodeContractsDemo.csproj.FileListAbsolute.txt │ ├── CodeContractsDemo.csprojResolveAssemblyReference.cache │ ├── CodeContractsDemo.exe │ ├── CodeContractsDemo.pdb │ ├── CodeContractsDemo.pdb.original │ ├── CodeContractsDemo.rewritten │ ├── CodeContractsDemoccdocgen.rsp │ ├── CodeContractsDemoccrefgen.rsp │ ├── CodeContractsDemoccrewrite.rsp │ ├── Decl │ ├── CodeContractsDemo.exe │ ├── CodeContractsDemo.pdb │ └── CodeContractsDemocccheck.rsp │ ├── DesignTimeResolveAssemblyReferences.cache │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs ├── README.md └── cover.png /Code Contracts/CodeContractsDemo.Tests/CodeContractsDemo.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {92CF44B7-E6BB-48B6-A23A-F161CAB1EFE8} 7 | Library 8 | Properties 9 | CodeContractsDemo.Tests 10 | CodeContractsDemo.Tests 11 | v4.5.2 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | True 20 | Full 21 | 22 | 23 | true 24 | full 25 | false 26 | bin\Debug\ 27 | DEBUG;TRACE 28 | prompt 29 | 4 30 | 31 | 32 | pdbonly 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | 39 | 40 | 41 | False 42 | ..\..\..\..\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Pex\Microsoft.ExtendedReflection.Reasoning.dll 43 | 44 | 45 | ..\..\..\..\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Pex\Microsoft.Pex.Framework.dll 46 | 47 | 48 | 49 | 50 | 51 | {7A9FEEDE-4DD3-4251-A6ED-0C5104AEC115} 52 | CodeContractsDemo 53 | 54 | 55 | 56 | 57 | 58 | ERPWarehouseIntegrationTest.cs 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | False 81 | 82 | 83 | False 84 | 85 | 86 | False 87 | 88 | 89 | False 90 | 91 | 92 | 93 | 94 | 95 | 96 | 103 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/ERPWarehouseIntegrationTest.ProductionVolumePerBinTest.g.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/ERPWarehouseIntegrationTest.ProductionVolumePerBinTest.g.cs -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/ERPWarehouseIntegrationTest.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/ERPWarehouseIntegrationTest.cs -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/Factories/ERPWarehouseIntegrationFactory.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/Factories/ERPWarehouseIntegrationFactory.cs -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/Properties/AssemblyInfo.cs -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/Properties/PexAssemblyInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/Properties/PexAssemblyInfo.cs -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/obj/Debug/CodeContractsDemo.Tests.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo.Tests\obj\Debug\CodeContractsDemo.Tests.csprojResolveAssemblyReference.cache 2 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/obj/Debug/CodeContractsDemo.Tests.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/obj/Debug/CodeContractsDemo.Tests.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/obj/Debug/CodeContractsDemo.Tests.pdb.original: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/obj/Debug/CodeContractsDemo.Tests.pdb.original -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/obj/Debug/CodeContractsDemo.Testsccrewrite.rsp: -------------------------------------------------------------------------------- 1 | /level:4 /nologo /rewrite "/framework:v4.5.2" /throwonfailure "/resolvedPaths:C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\bin\Debug\CodeContractsDemo.exe;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Pex\Microsoft.ExtendedReflection.Reasoning.dll;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Pex\Microsoft.Pex.Framework.dll;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\mscorlib.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Core.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.dll" "/libpaths:C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\bin\Debug\;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Pex\;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\;C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\bin\Debug\CodeContracts;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Pex\CodeContracts;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\CodeContracts;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\CodeContracts;C:\Program Files (x86)\Microsoft\Contracts\Contracts\.NETFramework\v4.5 " "CodeContractsDemo.Tests.dll" 2 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo.Tests/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo.Tests/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/.vs/CodeContractsDemo/v14/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/.vs/CodeContractsDemo/v14/.suo -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/CodeContractsDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7A9FEEDE-4DD3-4251-A6ED-0C5104AEC115} 8 | Exe 9 | Properties 10 | CodeContractsDemo 11 | CodeContractsDemo 12 | v4.6 13 | 512 14 | true 15 | 1 16 | 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | True 28 | False 29 | True 30 | False 31 | False 32 | False 33 | True 34 | True 35 | True 36 | True 37 | True 38 | True 39 | True 40 | True 41 | False 42 | True 43 | True 44 | True 45 | False 46 | False 47 | False 48 | False 49 | True 50 | False 51 | True 52 | False 53 | True 54 | False 55 | False 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | False 64 | False 65 | True 66 | True 67 | Full 68 | Build 69 | 0 70 | false 71 | bin\Debug\CodeContractsDemo.XML 72 | 73 | 74 | AnyCPU 75 | pdbonly 76 | true 77 | bin\Release\ 78 | TRACE 79 | prompt 80 | 4 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 111 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/CodeContractsDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeContractsDemo", "CodeContractsDemo.csproj", "{7A9FEEDE-4DD3-4251-A6ED-0C5104AEC115}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeContractsDemo.Tests", "..\CodeContractsDemo.Tests\CodeContractsDemo.Tests.csproj", "{92CF44B7-E6BB-48B6-A23A-F161CAB1EFE8}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {7A9FEEDE-4DD3-4251-A6ED-0C5104AEC115}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {7A9FEEDE-4DD3-4251-A6ED-0C5104AEC115}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {7A9FEEDE-4DD3-4251-A6ED-0C5104AEC115}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {7A9FEEDE-4DD3-4251-A6ED-0C5104AEC115}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {92CF44B7-E6BB-48B6-A23A-F161CAB1EFE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {92CF44B7-E6BB-48B6-A23A-F161CAB1EFE8}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {92CF44B7-E6BB-48B6-A23A-F161CAB1EFE8}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {92CF44B7-E6BB-48B6-A23A-F161CAB1EFE8}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/ERPIntegration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.Contracts; 4 | using System.IO; 5 | using System.Linq; 6 | 7 | namespace CodeContractsDemoProject 8 | { 9 | /// 10 | /// ERP Warehouse Integration Class to manage the cutting of steel volume and available bin quantities 11 | /// 12 | public class ERPWarehouseIntegration 13 | { 14 | public ERPWarehouseIntegration() 15 | { 16 | //CalculatedCuttingFactor = factor; 17 | } 18 | /// 19 | /// The maximum bin quantity for bins 20 | /// 21 | public int MaxBinQuantity { get; private set; } 22 | /// 23 | /// The current bin quantity available 24 | /// 25 | public int CurrentBinQuantity { get; private set; } 26 | /// 27 | /// The new valid cutting factor calculated by ProductionVolumePerBin 28 | /// 29 | public int CalculatedCuttingFactor { get; private set; } = 0; 30 | 31 | /* 32 | public int QuantityRequired { get; private set; } 33 | public int BinCount { get; private set; } 34 | 35 | public void CompleteBinPreparation(int quantityRequired) 36 | { 37 | QuantityRequired = quantityRequired; 38 | int available = BinQtyAvailable(); 39 | Contract.Assume(QuantityRequired <= available, "Quantity required exceeds available bin quantity"); 40 | } 41 | 42 | public void ProcessBin(string bin) 43 | { 44 | Contract.Requires(bin != null); 45 | Contract.Assert(!Contract.Exists(ProcessedBins(), 46 | x => string.Compare(x, bin, true) == 0), 47 | "Bin " + bin + " already processed"); 48 | 49 | // Process bin and add to Processed Bins colection 50 | } 51 | 52 | private List ProcessedBins() 53 | { 54 | List oBinsProcessed = new List(); 55 | oBinsProcessed.Add("A12"); 56 | oBinsProcessed.Add("CD25"); 57 | oBinsProcessed.Add("ZX4R"); 58 | oBinsProcessed.Add("A11"); 59 | 60 | return oBinsProcessed; 61 | } 62 | 63 | 64 | public void CutSteelNoScrap(int volumeSteel, int factor) 65 | { 66 | Contract.Ensures(volumeSteel != 0, "The volume of steel can't be zero"); 67 | Contract.Ensures(Contract.OldValue(volumeSteel) 68 | == CutSteel(volumeSteel, factor) + volumeSteel, 69 | "The factor used will result in scrap. Please modify the cutting factor."); 70 | 71 | // Process steel to cut 72 | } 73 | */ 74 | 75 | /// 76 | /// Calculate the production volume of steel per bin 77 | /// 78 | /// 79 | /// 80 | /// Bin Volume less Remainder 81 | public int ProductionVolumePerBin(int binVolume, int factor) 82 | { 83 | Contract.Requires(IsEven(binVolume), 84 | "Invalid bin volume entered"); 85 | Contract.Requires(factor > 1, 86 | "The supplied cutting factor must be more than the value 1."); 87 | Contract.Requires(binVolume > factor, 88 | "The cutting factor cannot be greater than the bin volume"); 89 | Contract.Ensures(Contract.Result() == binVolume, 90 | "The factor used will result in scrap. Please modify the cutting factor."); 91 | 92 | int remainder = CutSteel(binVolume, factor); 93 | while ((binVolume - remainder) != binVolume) 94 | { 95 | CalculatedCuttingFactor = CalculateNewCutFactor(binVolume); 96 | remainder = CutSteel(binVolume, CalculatedCuttingFactor); 97 | } 98 | 99 | return binVolume - remainder; 100 | } 101 | 102 | /// 103 | /// Calculate any remainder after the modulus operation between volume and factor 104 | /// 105 | /// 106 | /// 107 | /// Remainder after cutting 108 | private int CutSteel(int volumeToCut, int factor) 109 | { 110 | // Use modulus to determine if the factor produces any scrap 111 | return volumeToCut % factor; 112 | } 113 | 114 | /// 115 | /// Calculate a new cutting factor 116 | /// r.Next(1, 7); returns a random number between 1 and 7 117 | /// 118 | /// Upper range value of random (bin volume + 1) 119 | /// 120 | /// A new cutting factor greater than 1 and equal to the bin volume 121 | /// 122 | private int CalculateNewCutFactor(int binVol) 123 | { 124 | return GetRandom(1, binVol + 1); 125 | } 126 | 127 | /// 128 | /// Get a random number 129 | /// 130 | /// Value not less than 2 131 | /// Upper range value of the random number to generate 132 | /// A random Integer 133 | static int GetRandom(int minValue, int maxValue) 134 | { 135 | Contract.Requires(minValue >= 2, 136 | "minValue cannot be less than 2"); 137 | Random r = new Random(); 138 | return r.Next(minValue, maxValue); 139 | } 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | /// 149 | /// Ensure that the passed volume is even 150 | /// 151 | /// The volume to verify 152 | /// boolean 153 | public bool IsEven(int volume) 154 | { 155 | return volume % 2 == 0; 156 | } 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | //Random r = new Random(); 166 | //return r.Next(2, binVol + 1); 167 | 168 | /// 169 | /// Ensure that a non-negative value is returned for available bin quantity 170 | /// 171 | /// Available bin quantity 172 | public int BinQtyAvailable() 173 | { 174 | Contract.Ensures(Contract.Result() >= 0); 175 | MaxBinQuantity = 75; 176 | CurrentBinQuantity = 50; 177 | int QtyAvailable = MaxBinQuantity - CurrentBinQuantity; 178 | return QtyAvailable; 179 | } 180 | 181 | /// 182 | /// Ensure that all bins are filled and that the steel volume does not exceed the maximum bin volume 183 | /// 184 | /// 185 | /// 186 | /// 187 | public void EnsureAllBinsFilled(out int binOverCount, int binVol, int steelVol) 188 | { 189 | Contract.Ensures(Contract.ValueAtReturn(out binOverCount) == 0, 190 | "The steel volume exceeds the bin volume"); 191 | 192 | binOverCount = steelVol % binVol; 193 | } 194 | 195 | } 196 | 197 | 198 | 199 | 200 | //public class Male : Human 201 | //{ 202 | // public override void Run(int distance) 203 | // { 204 | // Console.Write("The distance run is " + distance); 205 | // Console.ReadLine(); 206 | // } 207 | 208 | // public override void Sleep(int hours) 209 | // { 210 | // Console.Write("The hours slept were " + hours); 211 | // Console.ReadLine(); 212 | // } 213 | //} 214 | 215 | 216 | 217 | //public class Alien : Human, IShapeShiftable 218 | //{ 219 | // public override void Run(int distance) 220 | // { 221 | // throw new NotImplementedException(); 222 | // } 223 | 224 | // public override void Sleep(int hours) 225 | // { 226 | // throw new NotImplementedException(); 227 | // } 228 | 229 | // public void InanimateObject(int shapeDuration) 230 | // { 231 | // throw new NotImplementedException(); 232 | // } 233 | 234 | // public void Man(int shapeDuration) 235 | // { 236 | // throw new NotImplementedException(); 237 | // } 238 | 239 | // public void Woman(int shapeDuration) 240 | // { 241 | // throw new NotImplementedException(); 242 | // } 243 | //} 244 | 245 | 246 | 247 | 248 | public class DemoPurity 249 | { 250 | /// 251 | /// Property for cutting factor 252 | /// 253 | public int CutFactor { get; private set; } 254 | 255 | /// 256 | /// Public Constructor 257 | /// 258 | /// 259 | public DemoPurity(int cutFactor) 260 | { 261 | CutFactor = cutFactor; 262 | } 263 | 264 | /// 265 | /// Calculate the volume cut 266 | /// 267 | /// 268 | /// 269 | /// 270 | public int VolumeCut(int volumeSteel, int factorModifier) 271 | { 272 | Contract.Requires(CalculatedCutFactor(factorModifier) >= 0); 273 | 274 | return volumeSteel / (CutFactor * factorModifier); 275 | } 276 | 277 | /// 278 | /// This is not a pure method 279 | /// 280 | /// 281 | /// 282 | [Pure] 283 | public int CalculatedCutFactor(int factorModifier) 284 | { 285 | return CutFactor * factorModifier; 286 | } 287 | } 288 | 289 | 290 | 291 | 292 | public class AbbreviatorDemo 293 | { 294 | /// 295 | /// The factor for the cutting volume 296 | /// 297 | public int Factor { get; private set; } 298 | /// 299 | /// The maximum volume a bin can contain 300 | /// 301 | public int MaxVolume { get; private set; } 302 | 303 | /// 304 | /// Fill the bin with the volume of steel 305 | /// 306 | /// 307 | public void FillBin(int steelVolume) 308 | { 309 | ValidSteelAndMaxVolume(steelVolume); 310 | } 311 | 312 | /// 313 | /// Empty the bin of all steel contained 314 | /// 315 | /// 316 | /// 317 | public bool PurgeBin(int steelVolume) 318 | { 319 | ValidSteelAndMaxVolume(steelVolume); 320 | EnsurePositiveResult(); 321 | 322 | // Purge Bin and return successful result 323 | return true; 324 | } 325 | 326 | /// 327 | /// Perform a partial bin fill 328 | /// 329 | /// 330 | /// 331 | public bool FillBinPartially(int steelVolume) 332 | { 333 | ValidSteelAndMaxVolume(steelVolume); 334 | EnsurePositiveResult(); 335 | 336 | return true; 337 | } 338 | 339 | /// 340 | /// Abbreviator Method for steel and max volume 341 | /// 342 | /// 343 | [ContractAbbreviator] 344 | private void ValidSteelAndMaxVolume(int steelVolume) 345 | { 346 | Contract.Requires(steelVolume > 0); 347 | Contract.Ensures(steelVolume <= this.MaxVolume); 348 | } 349 | 350 | /// 351 | /// Abbreviator Method for successful result 352 | /// 353 | [ContractAbbreviator] 354 | private void EnsurePositiveResult() 355 | { 356 | Contract.Ensures(Contract.Result() == true); 357 | } 358 | } 359 | 360 | 361 | public class Visibility 362 | { 363 | //[ContractPublicPropertyName("GetFactor")] 364 | private int _internalFactor; 365 | 366 | public int GetFactor 367 | { 368 | get { return _internalFactor; } 369 | set { _internalFactor = value; } 370 | } 371 | 372 | public Visibility(int factor) 373 | { 374 | Contract.Requires(factor != 0); 375 | _internalFactor = factor; 376 | } 377 | 378 | //public void DetermineFactor() 379 | //{ 380 | // Contract.Requires(_internalFactor > 0); 381 | //} 382 | } 383 | 384 | 385 | /* 386 | public static class ERPIntegration 387 | { 388 | public static string ProductCode { get; private set;} 389 | public static int SerialNumber { get; private set; } 390 | public static int Quantity { get; private set; } 391 | 392 | public static Warehouse AddSerializedItem(string productCode, int serialNumber, int qty) 393 | { 394 | Contract.Requires 395 | (serialNumber >= 100000001, "Invalid Serial number"); 396 | Contract.Ensures(Contract.Result() != null); 397 | 398 | ProductCode = productCode; 399 | SerialNumber = serialNumber; 400 | Quantity = qty; 401 | 402 | return CreateItem(); 403 | } 404 | 405 | public static void GetSerializedItem(string serialNumber) 406 | { 407 | //Contract.Assert 408 | //Contract.Assume 409 | //Contract.ContractFailed 410 | //Contract.EndContractBlock 411 | //Contract.EnsuresOnThrow 412 | //Contract.Equals 413 | //Contract.Exists 414 | //Contract.ForAll 415 | //Contract.OldValue<> 416 | //Contract.Result<> 417 | //Contract.ValueAtReturn<> 418 | } 419 | 420 | 421 | private static Warehouse CreateItem() 422 | { 423 | // Add Stocked Item code goes here 424 | Warehouse IssuedToWarehouse = new Warehouse(ProductCode); 425 | switch (ProductCode.Substring(0,1)) 426 | { 427 | case "A": 428 | IssuedToWarehouse.Code = "FM"; 429 | IssuedToWarehouse.Name = "Fast movers"; 430 | IssuedToWarehouse.Bin = IssuedToWarehouse.ReturnWarehouseBin(); 431 | IssuedToWarehouse.BinReorderLevel = 10000; 432 | IssuedToWarehouse.LastStockTake = Convert.ToDateTime("2015-09-01"); 433 | 434 | break; 435 | case "B": 436 | IssuedToWarehouse.Code = "FG"; 437 | IssuedToWarehouse.Name = "Finished Goods"; 438 | IssuedToWarehouse.Bin = IssuedToWarehouse.ReturnWarehouseBin(); 439 | IssuedToWarehouse.BinReorderLevel = 500; 440 | IssuedToWarehouse.LastStockTake = Convert.ToDateTime("2015-09-04"); 441 | break; 442 | case "C": 443 | IssuedToWarehouse.Code = "RM"; 444 | IssuedToWarehouse.Name = "Raw Materials"; 445 | IssuedToWarehouse.Bin = IssuedToWarehouse.ReturnWarehouseBin(); 446 | IssuedToWarehouse.BinReorderLevel = 7500; 447 | IssuedToWarehouse.LastStockTake = Convert.ToDateTime("2015-09-02"); 448 | break; 449 | default: 450 | IssuedToWarehouse.Code = "GS"; 451 | IssuedToWarehouse.Name = "General Stock"; 452 | IssuedToWarehouse.Bin = IssuedToWarehouse.ReturnWarehouseBin(); 453 | IssuedToWarehouse.BinReorderLevel = 5000; 454 | IssuedToWarehouse.LastStockTake = Convert.ToDateTime("2015-09-09"); 455 | break; 456 | } 457 | return IssuedToWarehouse; 458 | } 459 | 460 | 461 | } 462 | 463 | 464 | public class SerialNumberException : Exception 465 | { 466 | public SerialNumberException() 467 | { 468 | } 469 | 470 | public SerialNumberException(string message) 471 | : base(message) 472 | { 473 | } 474 | 475 | public SerialNumberException(string message, Exception inner) 476 | : base(message, inner) 477 | { 478 | } 479 | } 480 | 481 | public class Warehouse 482 | { 483 | [ContractInvariantMethod] 484 | private void Invariants() 485 | { 486 | Contract.Invariant(this.ProductionYear >= 0); 487 | Contract.Invariant(this.ProductionMonth >= 0); 488 | Contract.Invariant(this.ProductionMonth <= 12); 489 | Contract.Invariant(this.ProductionDay >= 0); 490 | Contract.Invariant(this.ProductionDay <= 30); 491 | } 492 | 493 | public Warehouse(string stockCode) 494 | { 495 | StockCode = stockCode; 496 | } 497 | 498 | public string ReturnWarehouseBin() 499 | { 500 | Contract.Requires(0 <= (this.StockCode.Length - 1)); 501 | 502 | string returnBin = ""; 503 | try 504 | { 505 | if (!StockCode.Substring(0, 1).ToLower().Equals("X")) 506 | { 507 | returnBin = ReadWarehouseBin(); 508 | } 509 | return returnBin; 510 | } 511 | catch (Exception ex) 512 | { 513 | throw ex; 514 | } 515 | } 516 | 517 | public string StockCode { get; private set; } 518 | public string Code { get; set; } 519 | public string Name { get; set; } 520 | public string Bin { get; set; } 521 | public int BinReorderLevel { get; set; } 522 | public DateTime LastStockTake { get; set; } 523 | 524 | public int ProductionDay { get; set; } 525 | public int ProductionMonth { get; set; } 526 | public int ProductionYear { get; set; } 527 | 528 | private string ReadWarehouseBin() 529 | { 530 | string bin = "GS"; 531 | 532 | if (StockCode.Substring(0, 1).ToLower().Equals("a")) 533 | bin = "A"; 534 | if (StockCode.Substring(0, 1).ToLower().Equals("b")) 535 | bin = "B"; 536 | if (StockCode.Substring(0, 1).ToLower().Equals("c")) 537 | bin = "AD"; 538 | 539 | return bin; 540 | } 541 | } 542 | 543 | */ 544 | 545 | 546 | } 547 | 548 | 549 | 550 | 551 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/Human.cs: -------------------------------------------------------------------------------- 1 | //using System; 2 | //using System.Diagnostics.Contracts; 3 | 4 | ///// 5 | ///// Human Abstract Class 6 | ///// 7 | //[ContractClass(typeof(HumanContract))] 8 | //public abstract class Human : ITeachable 9 | //{ 10 | // public void MapReading(int hoursToLearn) 11 | // { 12 | // Console.Write("Hours taken to learn Map Reading = " + hoursToLearn); 13 | // Console.ReadLine(); 14 | // } 15 | 16 | // public abstract void Run(int distance); 17 | 18 | // public void ShelterConstruction(int hoursToLearn) 19 | // { 20 | // Console.Write("Hours taken to learn Shelter Construction = " + hoursToLearn); 21 | // } 22 | 23 | // public abstract void Sleep(int hours); 24 | 25 | // public void TrapBuilding(int hoursToLearn) 26 | // { 27 | // Console.Write("Hours taken to learn Trap Building = " + hoursToLearn); 28 | // } 29 | //} 30 | 31 | ///// 32 | ///// Human Contract Class 33 | ///// 34 | //[ContractClassFor(typeof(Human))] 35 | //public abstract class HumanContract : Human 36 | //{ 37 | // public override void Sleep(int hours) 38 | // { 39 | // Contract.Requires(hours >= 8, 40 | // "You need more than 8 hours of sleep each night."); 41 | // } 42 | //} 43 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/IShapeShiftable.cs: -------------------------------------------------------------------------------- 1 | //using System.Diagnostics.Contracts; 2 | 3 | //[ContractClass(typeof(IShapeShiftableContract))] 4 | //public interface IShapeShiftable 5 | //{ 6 | // void Man(int shapeDuration); 7 | // void Woman(int shapeDuration); 8 | // void InanimateObject(int shapeDuration); 9 | //} 10 | 11 | //[ContractClassFor(typeof(IShapeShiftable))] 12 | //abstract class IShapeShiftableContract : IShapeShiftable 13 | //{ 14 | // void IShapeShiftable.InanimateObject(int shapeDuration) 15 | // { 16 | // Contract.Requires(shapeDuration <= 12); 17 | // } 18 | 19 | // void IShapeShiftable.Man(int shapeDuration) 20 | // { 21 | // Contract.Requires(shapeDuration <= 4); 22 | // } 23 | 24 | // void IShapeShiftable.Woman(int shapeDuration) 25 | // { 26 | // Contract.Requires(shapeDuration <= 4); 27 | // } 28 | //} 29 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/ITeachable.cs: -------------------------------------------------------------------------------- 1 | //using System; 2 | //using System.Diagnostics.Contracts; 3 | 4 | //public interface ITeachable 5 | //{ 6 | // void TrapBuilding(int hoursToLearn); 7 | // void MapReading(int hoursToLearn); 8 | // void ShelterConstruction(int hoursToLearn); 9 | //} 10 | 11 | 12 | //abstract class ITeachableContract : ITeachable 13 | //{ 14 | // public void MapReading(int hoursToLearn) 15 | // { 16 | // Contract.Requires(hoursToLearn <= 1); 17 | // } 18 | 19 | // public void ShelterConstruction(int hoursToLearn) 20 | // { 21 | // Contract.Requires(hoursToLearn <= 6); 22 | // } 23 | 24 | // public void TrapBuilding(int hoursToLearn) 25 | // { 26 | // Contract.Requires(hoursToLearn <= 2); 27 | // } 28 | //} -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | //using CodeContractsDemoProject; 7 | 8 | //Warehouse IssueWarehouse = ERPIntegration.AddSerializedItem("AC32WL", 1000000, 2500); 9 | //Console.WriteLine("The following product..."); 10 | //Console.WriteLine("Product code: BC32WL"); 11 | //Console.WriteLine("Serial: 100000005"); 12 | //Console.WriteLine("Quantity: 1251"); 13 | //Console.WriteLine("...has been issued to..."); 14 | //Console.WriteLine("Warehouse: " + IssueWarehouse.Name); 15 | //Console.WriteLine("Warehouse code: " + IssueWarehouse.Code); 16 | //Console.WriteLine("Issued to bin: " + IssueWarehouse.Bin); 17 | //Console.WriteLine("Reorder level: " + IssueWarehouse.BinReorderLevel); 18 | //Console.WriteLine("Last stock take: " + IssueWarehouse.LastStockTake); 19 | //Console.ReadLine(); 20 | 21 | namespace CodeContractsDemo 22 | { 23 | class Program 24 | { 25 | static void Main(string[] args) 26 | { 27 | try 28 | { 29 | //int iFactor = 7; 30 | //int steelVolume = 10; 31 | //int binVolume = 2; 32 | //int binWastedSpace = 0; // This must always equal zero 33 | //ERPWarehouseIntegration oWhi = new ERPWarehouseIntegration(); 34 | //oWhi.BinQtyAvailable(); 35 | //oWhi.ProductionVolumePerBin(binVolume, iFactor); 36 | //oWhi.EnsureAllBinsFilled(out binWastedSpace, binVolume, steelVolume); 37 | 38 | //Console.Write("All bins filled"); 39 | //Console.ReadLine(); 40 | 41 | 42 | //Male oMan = new Male(); 43 | //oMan.Sleep(9); 44 | 45 | #region old code 46 | //int volumeSteel = 100; 47 | //int cutFactor = 2; 48 | //int factorModifier = 10; 49 | //DemoPurity oDemo = new DemoPurity(cutFactor); 50 | //volumeSteel = oDemo.VolumeCut(volumeSteel, factorModifier); 51 | 52 | //Console.Write("Steel volume cut = " + volumeSteel + " sheets."); 53 | //Console.ReadLine(); 54 | #endregion 55 | 56 | //int a = int.MinValue; 57 | //int result = int.MinValue % -1; 58 | int binVol = 20; 59 | int factor = 3; 60 | CodeContractsDemoProject.ERPWarehouseIntegration oWhi = 61 | new CodeContractsDemoProject.ERPWarehouseIntegration(); 62 | 63 | 64 | 65 | int result = oWhi.ProductionVolumePerBin(binVol, factor); 66 | 67 | 68 | 69 | //string input = "Hello World"; 70 | //input.Substring() 71 | 72 | 73 | 74 | if (oWhi.CalculatedCuttingFactor != factor && oWhi.CalculatedCuttingFactor != 0) 75 | { 76 | Console.Write($"The supplied cutting factor of {factor} resulted in " 77 | + "an imperfect cut. The system suggests using the following " 78 | + $"cutting factor: {oWhi.CalculatedCuttingFactor}"); 79 | } 80 | else 81 | Console.Write($"The cutting factor of {factor} resulted in 0 scrap"); 82 | 83 | Console.ReadLine(); 84 | 85 | 86 | } 87 | catch (Exception ex) 88 | { 89 | Console.Write(ex.Message); 90 | Console.ReadLine(); 91 | } 92 | } 93 | 94 | static string Substring(string input, int start, int end) 95 | { 96 | return input.Substring(0, end - start); 97 | } 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CodeContractsDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CodeContractsDemo")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7a9feede-4dd3-4251-a6ed-0c5104aec115")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | [assembly: InternalsVisibleTo("CodeContractsDemo.Tests")] 38 | [assembly: InternalsVisibleTo("CodeContractsDemo.Explorables")] 39 | [assembly: InternalsVisibleTo("CodeContractsDemo.Tests1")] 40 | 41 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/bin/Debug/CodeContracts/CodeContractsDemo.Contracts.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/bin/Debug/CodeContracts/CodeContractsDemo.Contracts.dll -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/bin/Debug/CodeContracts/CodeContractsDemo.Contracts.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/bin/Debug/CodeContracts/CodeContractsDemo.Contracts.pdb -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.XML: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeContractsDemo 5 | 6 | 7 | 8 | 9 | ERP Warehouse Integration Class to manage the cutting of steel volume and available bin quantities 10 | 11 | 12 | 13 | 14 | The maximum bin quantity for bins 15 | 16 | 17 | 18 | 19 | The current bin quantity available 20 | 21 | 22 | 23 | 24 | The new valid cutting factor calculated by ProductionVolumePerBin 25 | 26 | 27 | 28 | 29 | Calculate the production volume of steel per bin 30 | 31 | 32 | 33 | Bin Volume less Remainder 34 | 35 | 36 | 37 | Calculate any remainder after the modulus operation between volume and factor 38 | 39 | 40 | 41 | Remainder after cutting 42 | 43 | 44 | 45 | Calculate a new cutting factor 46 | r.Next(1, 7); returns a random number between 1 and 7 47 | 48 | Upper range value of random (bin volume + 1) 49 | 50 | A new cutting factor greater than 1 and equal to the bin volume 51 | 52 | 53 | 54 | 55 | Get a random number 56 | 57 | Value not less than 2 58 | Upper range value of the random number to generate 59 | A random Integer 60 | 61 | 62 | 63 | Ensure that the passed volume is even 64 | 65 | The volume to verify 66 | boolean 67 | 68 | 69 | 70 | Ensure that a non-negative value is returned for available bin quantity 71 | 72 | Available bin quantity 73 | 74 | 75 | 76 | Ensure that all bins are filled and that the steel volume does not exceed the maximum bin volume 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | Property for cutting factor 85 | 86 | 87 | 88 | 89 | Public Constructor 90 | 91 | 92 | 93 | 94 | 95 | Calculate the volume cut 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | This is not a pure method 104 | 105 | 106 | 107 | 108 | 109 | 110 | The factor for the cutting volume 111 | 112 | 113 | 114 | 115 | The maximum volume a bin can contain 116 | 117 | 118 | 119 | 120 | Fill the bin with the volume of steel 121 | 122 | 123 | 124 | 125 | 126 | Empty the bin of all steel contained 127 | 128 | 129 | 130 | 131 | 132 | 133 | Perform a partial bin fill 134 | 135 | 136 | 137 | 138 | 139 | 140 | Abbreviator Method for steel and max volume 141 | 142 | 143 | 144 | 145 | 146 | Abbreviator Method for successful result 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.XML.old: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeContractsDemo 5 | 6 | 7 | 8 | 9 | ERP Warehouse Integration Class to manage the cutting of steel volume and available bin quantities 10 | 11 | 12 | 13 | 14 | The maximum bin quantity for bins 15 | 16 | 17 | 18 | 19 | The current bin quantity available 20 | 21 | 22 | 23 | 24 | The new valid cutting factor calculated by ProductionVolumePerBin 25 | 26 | 27 | 28 | 29 | Calculate the production volume of steel per bin 30 | 31 | 32 | 33 | Bin Volume less Remainder 34 | 35 | 36 | 37 | Calculate any remainder after the modulus operation between volume and factor 38 | 39 | 40 | 41 | Remainder after cutting 42 | 43 | 44 | 45 | Calculate a new cutting factor 46 | r.Next(1, 7); returns a random number between 1 and 7 47 | 48 | Upper range value of random (bin volume + 1) 49 | Lower range value of random (> 1) 50 | 51 | A new cutting factor greater than 1 and equal to the bin volume 52 | 53 | 54 | 55 | 56 | Ensure that the passed volume is even 57 | 58 | The volume to verify 59 | boolean 60 | 61 | 62 | 63 | Ensure that a non-negative value is returned for available bin quantity 64 | 65 | Available bin quantity 66 | 67 | 68 | 69 | Ensure that all bins are filled and that the steel volume does not exceed the maximum bin volume 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | Property for cutting factor 78 | 79 | 80 | 81 | 82 | Public Constructor 83 | 84 | 85 | 86 | 87 | 88 | Calculate the volume cut 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | This is not a pure method 97 | 98 | 99 | 100 | 101 | 102 | 103 | The factor for the cutting volume 104 | 105 | 106 | 107 | 108 | The maximum volume a bin can contain 109 | 110 | 111 | 112 | 113 | Fill the bin with the volume of steel 114 | 115 | 116 | 117 | 118 | 119 | Empty the bin of all steel contained 120 | 121 | 122 | 123 | 124 | 125 | 126 | Perform a partial bin fill 127 | 128 | 129 | 130 | 131 | 132 | 133 | Abbreviator Method for steel and max volume 134 | 135 | 136 | 137 | 138 | 139 | Abbreviator Method for successful result 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.exe -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.pdb -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.vshost.exe -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.vshost.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/bin/Debug/CodeContractsDemo.vshost.exe.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\bin\Debug\CodeContracts\CodeContractsDemo.Contracts.dll 2 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\bin\Debug\CodeContracts\CodeContractsDemo.Contracts.pdb 3 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\bin\Debug\CodeContractsDemo.exe.config 4 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\bin\Debug\CodeContractsDemo.XML 5 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\bin\Debug\CodeContractsDemo.exe 6 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\bin\Debug\CodeContractsDemo.pdb 7 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\obj\Debug\Decl\CodeContractsDemo.exe 8 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\obj\Debug\Decl\CodeContractsDemo.pdb 9 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\obj\Debug\CodeContractsDemoccrefgen.rsp 10 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\obj\Debug\CodeContractsDemo.rewritten 11 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\obj\Debug\CodeContractsDemo.exe 12 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\obj\Debug\CodeContractsDemo.pdb 13 | C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\obj\Debug\CodeContractsDemo.csprojResolveAssemblyReference.cache 14 | C:\z\sourcecode\Code Contracts\CodeContractsDemo\bin\Debug\CodeContractsDemo.exe.config 15 | C:\z\sourcecode\Code Contracts\CodeContractsDemo\bin\Debug\CodeContractsDemo.XML 16 | C:\z\sourcecode\Code Contracts\CodeContractsDemo\obj\Debug\CodeContractsDemo.exe 17 | C:\z\sourcecode\Code Contracts\CodeContractsDemo\obj\Debug\CodeContractsDemo.pdb 18 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.exe -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.pdb -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.pdb.original: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.pdb.original -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.rewritten: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemo.rewritten -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemoccdocgen.rsp: -------------------------------------------------------------------------------- 1 | -assembly "bin\Debug\CodeContracts\CodeContractsDemo.Contracts.dll" -xmlFile "bin\Debug\CodeContractsDemo.XML" "-resolvedPaths:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\Microsoft.CSharp.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Core.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Data.DataSetExtensions.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Data.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Net.Http.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Xml.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Xml.Linq.dll" -libpaths "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\CodeContracts;C:\Program Files (x86)\Microsoft\Contracts\Contracts\.NETFramework\v4.5 " 2 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemoccrefgen.rsp: -------------------------------------------------------------------------------- 1 | "/resolvedPaths:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\Microsoft.CSharp.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Core.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Data.DataSetExtensions.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Data.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Net.Http.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Xml.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Xml.Linq.dll" "/libPaths:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\CodeContracts;C:\Program Files (x86)\Microsoft\Contracts\Contracts\.NETFramework\v4.5 " /pdb "/out:bin\Debug\CodeContracts\CodeContractsDemo.Contracts.dll" "obj\Debug\Decl\CodeContractsDemo.exe" 2 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/CodeContractsDemoccrewrite.rsp: -------------------------------------------------------------------------------- 1 | /level:4 /nologo /rewrite "/framework:v4.6" "/assemblyMode=standard" /throwonfailure "/resolvedPaths:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\Microsoft.CSharp.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Core.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Data.DataSetExtensions.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Data.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Net.Http.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Xml.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Xml.Linq.dll" "/libpaths:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\CodeContracts;C:\Program Files (x86)\Microsoft\Contracts\Contracts\.NETFramework\v4.5 " "CodeContractsDemo.exe" 2 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/Decl/CodeContractsDemo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/Decl/CodeContractsDemo.exe -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/Decl/CodeContractsDemo.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/Decl/CodeContractsDemo.pdb -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/Decl/CodeContractsDemocccheck.rsp: -------------------------------------------------------------------------------- 1 | -nobox -nologo -nopex -remote -suggest=!! -premode combined -suggest codefixes -framework:v4.5.2 -warninglevel low -assemblyMode=standard -maxwarnings 1200 -nonnull -bounds: -arrays -wp=true -bounds:type=subpolyhedra,reduction=simplex,diseq=false -arrays -adaptive -arithmetic -enum -check assumptions -suggest asserttocontracts -check conditionsvalidity -missingPublicRequiresAreErrors -suggest necessaryensures -suggest readonlyfields -infer requires -infer methodensures -infer autopropertiesensures -failOnWarnings "-resolvedPaths:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Microsoft.CSharp.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\mscorlib.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Core.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Data.DataSetExtensions.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Data.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Net.Http.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Xml.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Xml.Linq.dll" "-libPaths:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\CodeContracts;C:\Program Files (x86)\Microsoft\Contracts\Contracts\.NETFramework\v4.5 " "C:\z\[]sc 2015\Code Contracts\CodeContractsDemo\obj\Debug\Decl\CodeContractsDemo.exe" 2 | -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs -------------------------------------------------------------------------------- /Code Contracts/CodeContractsDemo/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/Code Contracts/CodeContractsDemo/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C# Code Contracts Succinctly 2 | This is the companion repo for [*C# Code Contracts Succinctly*](https://www.syncfusion.com/ebooks/csharpcontracts) by Dirk Strauss. Published by Syncfusion. 3 | 4 | [![cover](https://github.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/blob/master/cover.png)](https://www.syncfusion.com/ebooks/csharpcontracts) 5 | 6 | ## Looking for more _Succinctly_ titles? 7 | 8 | Check out the entire library of more than 130 _Succinctly_ e-books at [https://www.syncfusion.com/ebooks](https://www.syncfusion.com/ebooks). 9 | -------------------------------------------------------------------------------- /cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/CSharp-Code-Contracts-Succinctly/a0736cb908c5bea8bd445a80b7385629b1a4b486/cover.png --------------------------------------------------------------------------------