Part 1 & 2
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/.vs
|
||||||
|
bin
|
||||||
|
obj
|
37
Bucket.sln
Normal file
37
Bucket.sln
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.9.34701.34
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Buckets", "Buckets\Buckets.csproj", "{0B0CE8F2-0665-42A4-AD91-7F2F6F67A5D0}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Buckets.Logic", "Buckets.Logic\Buckets.Logic.csproj", "{55E89D29-6A4E-4A7F-B1E3-08DA8C5AAC53}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Buckets.Test", "Buckets.Test\Buckets.Test.csproj", "{176D4C26-03A8-4C33-802D-D80294C0E909}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{0B0CE8F2-0665-42A4-AD91-7F2F6F67A5D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0B0CE8F2-0665-42A4-AD91-7F2F6F67A5D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0B0CE8F2-0665-42A4-AD91-7F2F6F67A5D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0B0CE8F2-0665-42A4-AD91-7F2F6F67A5D0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{55E89D29-6A4E-4A7F-B1E3-08DA8C5AAC53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{55E89D29-6A4E-4A7F-B1E3-08DA8C5AAC53}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{55E89D29-6A4E-4A7F-B1E3-08DA8C5AAC53}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{55E89D29-6A4E-4A7F-B1E3-08DA8C5AAC53}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{176D4C26-03A8-4C33-802D-D80294C0E909}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{176D4C26-03A8-4C33-802D-D80294C0E909}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{176D4C26-03A8-4C33-802D-D80294C0E909}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{176D4C26-03A8-4C33-802D-D80294C0E909}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {76573F70-1533-4DC6-8AFC-8C46B5EFCC12}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
23
Buckets.Logic/Bucket.cs
Normal file
23
Buckets.Logic/Bucket.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
namespace Buckets.Logic
|
||||||
|
{
|
||||||
|
public class Bucket : Container
|
||||||
|
{
|
||||||
|
private const int DEFAULT_CAPACITY = 12;
|
||||||
|
private const int MAX_CAPACITY = 2500;
|
||||||
|
private const int MIN_CAPACITY = 10;
|
||||||
|
|
||||||
|
public Bucket(int content) : base(DEFAULT_CAPACITY, content) {}
|
||||||
|
|
||||||
|
public Bucket(int capacity, int content) : base(capacity, content)
|
||||||
|
{
|
||||||
|
ArgumentOutOfRangeException.ThrowIfGreaterThan(capacity, MAX_CAPACITY, nameof(capacity));
|
||||||
|
ArgumentOutOfRangeException.ThrowIfLessThan(capacity, MIN_CAPACITY, nameof(capacity));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Fill(Bucket bucket)
|
||||||
|
{
|
||||||
|
Content += bucket.Content;
|
||||||
|
bucket.Empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
Buckets.Logic/Buckets.Logic.csproj
Normal file
9
Buckets.Logic/Buckets.Logic.csproj
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
32
Buckets.Logic/Container.cs
Normal file
32
Buckets.Logic/Container.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
namespace Buckets.Logic
|
||||||
|
{
|
||||||
|
public abstract class Container
|
||||||
|
{
|
||||||
|
private int content;
|
||||||
|
|
||||||
|
public int Capacity { get; }
|
||||||
|
public int Content {get => content; set { ArgumentOutOfRangeException.ThrowIfNegative(value, nameof(Content)); ArgumentOutOfRangeException.ThrowIfGreaterThan(value, Capacity, nameof(Content)); content = value; } }
|
||||||
|
|
||||||
|
public Container(int capacity, int content)
|
||||||
|
{
|
||||||
|
ArgumentOutOfRangeException.ThrowIfNegative(capacity, nameof(Capacity));
|
||||||
|
Capacity = capacity;
|
||||||
|
Content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Fill(int amount)
|
||||||
|
{
|
||||||
|
Content += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Empty(int amount)
|
||||||
|
{
|
||||||
|
Content -= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Empty()
|
||||||
|
{
|
||||||
|
Content = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
Buckets.Logic/OilBarrel.cs
Normal file
7
Buckets.Logic/OilBarrel.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace Buckets.Logic
|
||||||
|
{
|
||||||
|
public class OilBarrel(int content) : Container(CAPACITY, content)
|
||||||
|
{
|
||||||
|
public const int CAPACITY = 159;
|
||||||
|
}
|
||||||
|
}
|
15
Buckets.Logic/Rainbarrel.cs
Normal file
15
Buckets.Logic/Rainbarrel.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
namespace Buckets.Logic
|
||||||
|
{
|
||||||
|
public class Rainbarrel : Container
|
||||||
|
{
|
||||||
|
private readonly int[] ALLOWED_CAPACITIES = [80, 100, 120];
|
||||||
|
|
||||||
|
public Rainbarrel(int capacity, int content) : base(capacity, content)
|
||||||
|
{
|
||||||
|
if (!ALLOWED_CAPACITIES.Contains(capacity))
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Capacity must be one of the following values: {string.Join(", ", ALLOWED_CAPACITIES)}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
62
Buckets.Test/BucketTest.cs
Normal file
62
Buckets.Test/BucketTest.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using Buckets.Logic;
|
||||||
|
|
||||||
|
namespace Buckets.Test
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class BucketTest
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void Bucket_DefaultCapacity_ShouldEqual12()
|
||||||
|
{
|
||||||
|
Bucket bucket = new(0);
|
||||||
|
Assert.AreEqual(12, bucket.Capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Bucket_LowCapacity_ShouldThrow()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||||
|
{
|
||||||
|
Bucket bucket = new(5, 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Bucket_HighCapacity_ShouldThrow()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||||
|
{
|
||||||
|
Bucket bucket = new(2501, 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Fill_BucketOverCapacity_ShouldThrow()
|
||||||
|
{
|
||||||
|
Bucket bucket = new(10, 0);
|
||||||
|
Bucket bucket2 = new(20, 20);
|
||||||
|
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||||
|
{
|
||||||
|
bucket.Fill(bucket2);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Fill_SecondBucket_ShouldEqual0()
|
||||||
|
{
|
||||||
|
Bucket bucket = new(20, 0);
|
||||||
|
Bucket bucket2 = new(20, 10);
|
||||||
|
bucket.Fill(bucket2);
|
||||||
|
Assert.AreEqual(0, bucket2.Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Fill_Bucket_ShouldEqual20()
|
||||||
|
{
|
||||||
|
Bucket bucket = new(20, 10);
|
||||||
|
Bucket bucket2 = new(20, 10);
|
||||||
|
bucket.Fill(bucket2);
|
||||||
|
Assert.AreEqual(20, bucket.Content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
Buckets.Test/Buckets.Test.csproj
Normal file
27
Buckets.Test/Buckets.Test.csproj
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Buckets.Logic\Buckets.Logic.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
86
Buckets.Test/ContainerTest.cs
Normal file
86
Buckets.Test/ContainerTest.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
using Buckets.Logic;
|
||||||
|
|
||||||
|
namespace Buckets.Test
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class ContainerTest
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void Container_NegativeCapacity_ShouldThrow()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||||
|
{
|
||||||
|
Bucket container = new(-1, 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Container_NegativeContent_ShouldThrow()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||||
|
{
|
||||||
|
Bucket container = new(0, -1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Container_ContentLargerThanCapacity_ShouldThrow()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||||
|
{
|
||||||
|
Bucket container = new(0, 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Container_ValidParameters_ShouldEqual10()
|
||||||
|
{
|
||||||
|
Bucket container = new(20, 10);
|
||||||
|
Assert.AreEqual(10, container.Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Fill_ContentLargerThanCapacity_ShouldThrow()
|
||||||
|
{
|
||||||
|
Bucket container = new(20, 10);
|
||||||
|
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||||
|
{
|
||||||
|
container.Fill(20);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Fill_ValidParameters_ShouldEqual15()
|
||||||
|
{
|
||||||
|
Bucket container = new(20, 10);
|
||||||
|
container.Fill(5);
|
||||||
|
Assert.AreEqual(15, container.Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Empty_NegativeContent_ShouldThrow()
|
||||||
|
{
|
||||||
|
Bucket container = new(20, 10);
|
||||||
|
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
|
||||||
|
{
|
||||||
|
container.Empty(20);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Empty_ValidParameters_ShouldEqual5()
|
||||||
|
{
|
||||||
|
Bucket container = new(20, 10);
|
||||||
|
container.Empty(5);
|
||||||
|
Assert.AreEqual(5, container.Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void Empty_ValidParameters_ShouldEqual0()
|
||||||
|
{
|
||||||
|
Bucket container = new(20, 10);
|
||||||
|
container.Empty();
|
||||||
|
Assert.AreEqual(0, container.Content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
Buckets.Test/OilBarrelTest.cs
Normal file
15
Buckets.Test/OilBarrelTest.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using Buckets.Logic;
|
||||||
|
|
||||||
|
namespace Buckets.Test
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class OilBarrelTest
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void OilBarrel_ValidParams_ShouldEqualDefault()
|
||||||
|
{
|
||||||
|
OilBarrel oilbarrel = new(10);
|
||||||
|
Assert.AreEqual(OilBarrel.CAPACITY, oilbarrel.Capacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
Buckets.Test/RainBarrelTest.cs
Normal file
24
Buckets.Test/RainBarrelTest.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using Buckets.Logic;
|
||||||
|
|
||||||
|
namespace Buckets.Test
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class RainBarrelTest
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void RainBarrel_DisallowedCapacity_ShouldThrow()
|
||||||
|
{
|
||||||
|
Assert.ThrowsException<ArgumentException>(() =>
|
||||||
|
{
|
||||||
|
Rainbarrel rainbarrel = new(90, 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void RainBarrel_AllowedCapacity_ShouldEqual100()
|
||||||
|
{
|
||||||
|
Rainbarrel rainbarrel = new(100, 0);
|
||||||
|
Assert.AreEqual(100, rainbarrel.Capacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Buckets/Buckets.csproj
Normal file
14
Buckets/Buckets.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Buckets.Logic\Buckets.Logic.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
28
Buckets/Program.cs
Normal file
28
Buckets/Program.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using Buckets.Logic;
|
||||||
|
|
||||||
|
namespace Buckets
|
||||||
|
{
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
Bucket bucket = new(50, 0);
|
||||||
|
bucket.Fill(10);
|
||||||
|
bucket.Empty();
|
||||||
|
bucket.Fill(20);
|
||||||
|
bucket.Empty(10);
|
||||||
|
|
||||||
|
OilBarrel oilbarrel = new(0);
|
||||||
|
oilbarrel.Fill(10);
|
||||||
|
oilbarrel.Empty();
|
||||||
|
oilbarrel.Fill(20);
|
||||||
|
oilbarrel.Empty(10);
|
||||||
|
|
||||||
|
Rainbarrel rainbarrel = new(100, 0);
|
||||||
|
rainbarrel.Fill(10);
|
||||||
|
rainbarrel.Empty();
|
||||||
|
rainbarrel.Fill(20);
|
||||||
|
rainbarrel.Empty(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user