Browse Source

Add test cases

master
unknown 1 year ago
parent
commit
dfd6f32662
8 changed files with 221 additions and 5 deletions
  1. +20
    -0
      Assignment5Test/Assignment5Test.csproj
  2. +172
    -0
      Assignment5Test/Problem2UnitTest.cs
  3. +7
    -1
      COMP-10068 Assignment 5.sln
  4. +18
    -0
      Problem2/Computer.cs
  5. +1
    -1
      Problem2/ComputerDirector.cs
  6. +1
    -1
      Problem2/HighEndComputerBuilder.cs
  7. +1
    -1
      Problem2/LowEndComputerBuilder.cs
  8. +1
    -1
      Problem2/MediumEndComputerBuilder.cs

+ 20
- 0
Assignment5Test/Assignment5Test.csproj View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Problem2\Problem2.csproj" />
</ItemGroup>
</Project>

+ 172
- 0
Assignment5Test/Problem2UnitTest.cs View File

@ -0,0 +1,172 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Problem2;
using System;
/** Statement of Authorship
*I, Michael Helbert, student number 000788384, certify that all code submitted is my own work; that I have not copied it from any other source.
*I also certify that I have not allowed my work to be copied by others.
*/
namespace Assignment5Test
{
[TestClass]
public class Problem2UnitTest
{
/// <summary>
/// Tests the low end computer builder
/// </summary>
[TestMethod]
public void TestLowEndBuilderConstruction()
{
//Initialize the builder
var lowEndBuilder = new LowEndComputerBuilder();
//Tell the director to construct the builder
//No exceptions should occure while building the computer since the components are hardcoded by the developer
ComputerDirector.Construct(lowEndBuilder);
//Check each component of the Computer object to ensure that no components are missing and were successfully initialized
Assert.IsNotNull(lowEndBuilder.Computer.Motherboard);
Assert.IsNotNull(lowEndBuilder.Computer.HardDrive);
Assert.IsNotNull(lowEndBuilder.Computer.Case);
}
/// <summary>
/// Tests the medium end computer builder
/// </summary>
[TestMethod]
public void TestMediumEndBuilderConstruction()
{
//Initialize the builder
var mediumEndBuilder = new MediumEndComputerBuilder();
//Tell the director to construct the builder
//No exceptions should occure while building the computer since the components are hardcoded by the developer
ComputerDirector.Construct(mediumEndBuilder);
//Check each component of the Computer object to ensure that no components are missing and were successfully initialized
Assert.IsNotNull(mediumEndBuilder.Computer.Motherboard);
Assert.IsNotNull(mediumEndBuilder.Computer.HardDrive);
Assert.IsNotNull(mediumEndBuilder.Computer.Case);
}
/// <summary>
/// Tests the high end computer builder
/// </summary>
[TestMethod]
public void TestHighEndBuilderConstruction()
{
//Initialize the builder
var highEndBuilder = new HighEndComputerBuilder();
//Tell the director to construct the builder
//No exceptions should occure while building the computer since the components are hardcoded by the developer
ComputerDirector.Construct(highEndBuilder);
//Check each component of the Computer object to ensure that no components are missing and were successfully initialized
Assert.IsNotNull(highEndBuilder.Computer.Motherboard);
Assert.IsNotNull(highEndBuilder.Computer.HardDrive);
Assert.IsNotNull(highEndBuilder.Computer.Case);
}
/// <summary>
/// Tests the manual construction of a computer
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestManualComputerCreation()
{
CPU cpu = new CPU(
speed: 2.8,
manufacturer: Manufacturer.Intel,
socketType: "LGA 1150",
cacheSize: 2048,
cores: 2
);
Memory[] memory = new Memory[2]
{
new Memory(
readSpeed: 1024,
writeSpeed: 1024,
type: MemoryType.DDR2,
size: 1024
),
new Memory(
readSpeed: 1024,
writeSpeed: 1024,
type: MemoryType.DDR2,
size: 1024
)
};
GraphicsCard graphicsCard = new GraphicsCard(
speed: 1024,
videoMemory: 1024,
cudaCores: 800,
fans: 1
);
Case @case = new Case(
length: 50.4,
width: 20.2,
height: 30.1,
fans: 1,
vents: 1
);
HardDrive hardDrive = new HardDrive(
capacity: 500,
HardDriveType.HDD,
readSpeed: 1024,
writeSpeed: 920
);
//Raise the ArgumentOutOfRangeException because the amount of memory cards exceeds the "memorySlots" argument.
Motherboard motherboardException = new Motherboard(
memorySlots: 1,
powerConsumption: 700,
pciSlots: 4,
formFactor: new FormFactor(
name: "ATX",
new DateTime(1999, 06, 04),
width: 20,
depth: 30,
usbSlots: 6
),
hardDriveLimit: 2,
cpu: cpu,
memory: memory,
graphicsCard: graphicsCard
);
//Proper motherboard which should not raise any exceptions
Motherboard motherboard = new Motherboard(
memorySlots: 2,
powerConsumption: 700,
pciSlots: 4,
formFactor: new FormFactor(
name: "ATX",
new DateTime(1999, 06, 04),
width: 20,
depth: 30,
usbSlots: 6
),
hardDriveLimit: 2,
cpu: cpu,
memory: memory,
graphicsCard: graphicsCard
);
Computer computer = new Computer(motherboard, hardDrive, @case);
//Check each component of the Computer object to ensure that no components are missing and were successfully initialized
Assert.IsNotNull(computer.Motherboard);
Assert.IsNotNull(computer.HardDrive);
Assert.IsNotNull(computer.Case);
//Check the computer's clock speed to what we set it above for assurance that other properties were correctly assigned
Assert.AreEqual(cpu.Speed, computer.Motherboard.CPU.Speed);
}
}
}

+ 7
- 1
COMP-10068 Assignment 5.sln View File

@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Problem3", "Problem3\Proble
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Problem4", "Problem4\Problem4.csproj", "{B8C9240E-2204-4138-88F6-2291BF9F8E07}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Problem1", "Problem1\Problem1.csproj", "{212B5B50-DB14-40AD-A04D-9AD9AF24E650}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Problem1", "Problem1\Problem1.csproj", "{212B5B50-DB14-40AD-A04D-9AD9AF24E650}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assignment5Test", "Assignment5Test\Assignment5Test.csproj", "{A4534E4C-085D-48EB-A612-EA8A253A6C43}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -33,6 +35,10 @@ Global
{212B5B50-DB14-40AD-A04D-9AD9AF24E650}.Debug|Any CPU.Build.0 = Debug|Any CPU
{212B5B50-DB14-40AD-A04D-9AD9AF24E650}.Release|Any CPU.ActiveCfg = Release|Any CPU
{212B5B50-DB14-40AD-A04D-9AD9AF24E650}.Release|Any CPU.Build.0 = Release|Any CPU
{A4534E4C-085D-48EB-A612-EA8A253A6C43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4534E4C-085D-48EB-A612-EA8A253A6C43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4534E4C-085D-48EB-A612-EA8A253A6C43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4534E4C-085D-48EB-A612-EA8A253A6C43}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE


+ 18
- 0
Problem2/Computer.cs View File

@ -17,5 +17,23 @@ namespace Problem2
public Motherboard Motherboard { get; set; }
public HardDrive HardDrive { get; set; }
public Case Case { get; set; }
/// <summary>
/// Initializes the Computer with a predefined motherboard, harddrive, and case
/// </summary>
/// <param name="motherboard">The motherboard</param>
/// <param name="hardDrive">The harddrive</param>
/// <param name="case">The casee</param>
public Computer(Motherboard motherboard, HardDrive hardDrive, Case @case)
{
Motherboard = motherboard;
HardDrive = hardDrive;
Case = @case;
}
/// <summary>
/// In case we need to build a computer but assign the components of it later.
/// </summary>
public Computer() : this(null, null, null) { }
}
}

+ 1
- 1
Problem2/ComputerDirector.cs View File

@ -22,7 +22,7 @@ namespace Problem2
{
builder.BuildMotherboard();
builder.BuildHardDrive();
builder.BuildMotherboard();
builder.BuildCase();
}
}
}

+ 1
- 1
Problem2/HighEndComputerBuilder.cs View File

@ -12,7 +12,7 @@ namespace Problem2
/// <summary>
/// Represents a class that builds a "high-end" computer.
/// </summary>
class HighEndComputerBuilder : IComputerBuilder
public class HighEndComputerBuilder : IComputerBuilder
{
public Computer Computer { get; private set; }


+ 1
- 1
Problem2/LowEndComputerBuilder.cs View File

@ -12,7 +12,7 @@ namespace Problem2
/// <summary>
/// Represents a class that builds a "low-end" computer.
/// </summary>
class LowEndComputerBuilder : IComputerBuilder
public class LowEndComputerBuilder : IComputerBuilder
{
public Computer Computer { get; private set; }


+ 1
- 1
Problem2/MediumEndComputerBuilder.cs View File

@ -12,7 +12,7 @@ namespace Problem2
/// <summary>
/// Represents a class that builds a "medium-end" computer.
/// </summary>
class MediumEndComputerBuilder : IComputerBuilder
public class MediumEndComputerBuilder : IComputerBuilder
{
public Computer Computer { get; private set; }


Loading…
Cancel
Save