Skip to content

Commit

Permalink
New Homework Added
Browse files Browse the repository at this point in the history
New Homework Added
  • Loading branch information
nikolavn committed Aug 7, 2015
1 parent 5c9101b commit 9693aec
Show file tree
Hide file tree
Showing 67 changed files with 3,806 additions and 0 deletions.
25 changes: 25 additions & 0 deletions High-Quality-Code/11. Unit Testing/Homework/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Unit Testing Homework

## Task 1. Students and courses
* Write three classes: `Student`, `Course` and `School`.
* Students should have name and unique number (inside the entire `School`).
* Name can not be empty and the unique number is between 10000 and 99999.
* Each course contains a set of students.
* Students in a course should be less than 30 and can join and leave courses.
* Write VSTT tests
* Use 2 class library projects in Visual Studio: `School.csproj` and `School.Tests.csproj`
* Execute the tests using Visual Studio and check the code coverage. Ensure it is at least 90%.

## Task 2. Unit test the `Deck` class from the `SantaseGameEngine`
* [Deck.cs](https://github.com/NikolayIT/SantaseGameEngine/blob/master/Source/Santase.Logic/Cards/Deck.cs)
* Use NUnit as a testing framework
* Write at least one [Parameterized Test](http://nunit.org/index.php?p=parameterizedTests&r=2.6.1)

## Task 3*. Unit test the `PlayerActionValidater` class
* Get known with the [Santase game rules](https://www.google.bg/search?q=%D0%BF%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0+%D1%81%D0%B0%D0%BD%D1%82%D0%B0%D1%81%D0%B5)
* Download the [SantaseGameEngine](https://github.com/NikolayIT/SantaseGameEngine)
* Review the [PlayerActionValidater.cs](https://github.com/NikolayIT/SantaseGameEngine/blob/master/Source/Santase.Logic/PlayerActionValidater.cs)
* Write unit tests for the `IsValid` method
* Ensure code coverage of 100% for the `PlayerActionValidater.cs` class
* Fix any bugs you find during the unit testing
* You can use testing framework of your choice
34 changes: 34 additions & 0 deletions High-Quality-Code/11. Unit Testing/Homework/School/School.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "School", "School\School.csproj", "{54D603D9-DCD8-4ADB-85C3-06E123F4B822}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "School.Tests", "School.Tests\School.Tests.csproj", "{5BB0B30B-3AD1-4680-88E2-EF191C6C5E95}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchoolTests1", "SchoolTests1\SchoolTests1.csproj", "{0401D26E-C3BA-4E25-B307-23D90CBE8DB5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{54D603D9-DCD8-4ADB-85C3-06E123F4B822}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{54D603D9-DCD8-4ADB-85C3-06E123F4B822}.Debug|Any CPU.Build.0 = Debug|Any CPU
{54D603D9-DCD8-4ADB-85C3-06E123F4B822}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54D603D9-DCD8-4ADB-85C3-06E123F4B822}.Release|Any CPU.Build.0 = Release|Any CPU
{5BB0B30B-3AD1-4680-88E2-EF191C6C5E95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BB0B30B-3AD1-4680-88E2-EF191C6C5E95}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BB0B30B-3AD1-4680-88E2-EF191C6C5E95}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BB0B30B-3AD1-4680-88E2-EF191C6C5E95}.Release|Any CPU.Build.0 = Release|Any CPU
{0401D26E-C3BA-4E25-B307-23D90CBE8DB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0401D26E-C3BA-4E25-B307-23D90CBE8DB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0401D26E-C3BA-4E25-B307-23D90CBE8DB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0401D26E-C3BA-4E25-B307-23D90CBE8DB5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace School
{
public class Course
{
private const int MaximumStudentsInCourse = 30;

private List<Student> studentsList;
private string name;

public Course(string name)
{
this.Name = name;
this.studentsList = new List<Student>();
}

public string Name
{
get
{
return this.name;
}

set
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException("Course name cannot be null or empty");
}

this.name = value;
}
}

public void AddStudent(Student student)
{
if (object.Equals(student, null))
{
throw new ArgumentNullException("Student to add can not be null");
}

if (this.studentsList.Count >= MaximumStudentsInCourse)
{
throw new ArgumentOutOfRangeException("Students in course cannot be more than 30");
}

if (this.studentsList.Contains(student))
{
throw new ArgumentException("Student is already in the list");
}

this.studentsList.Add(student);
}

public void RemoveStudent(Student student)
{
if (object.Equals(student, null))
{
throw new ArgumentNullException("Student can not be null");
}

if (!this.studentsList.Contains(student))
{
throw new ArgumentException("Student is not in list");
}

this.studentsList.Remove(student);
}

public string ListStudents()
{
StringBuilder listOfStudents = new StringBuilder();

foreach (var student in this.studentsList)
{
listOfStudents.Append(student.ToString() + Environment.NewLine);
}

return listOfStudents.ToString();
}

public override string ToString()
{
return this.Name + Environment.NewLine + this.ListStudents();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("School")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("School")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4eb79c0c-f3b9-42f1-a597-10f02c4409a9")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{54D603D9-DCD8-4ADB-85C3-06E123F4B822}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>School</RootNamespace>
<AssemblyName>School</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>School.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>School.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Course.cs" />
<Compile Include="SchoolInstance.cs" />
<Compile Include="Student.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="School.ruleset" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.0-beta003\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for School" Description="Code analysis rules for School.csproj." ToolsVersion="14.0">
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1200" Action="None" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1601" Action="None" />
<Rule Id="SA1602" Action="None" />
<Rule Id="SA1603" Action="None" />
<Rule Id="SA1604" Action="None" />
<Rule Id="SA1605" Action="None" />
<Rule Id="SA1606" Action="None" />
<Rule Id="SA1607" Action="None" />
<Rule Id="SA1608" Action="None" />
<Rule Id="SA1609" Action="None" />
<Rule Id="SA1610" Action="None" />
<Rule Id="SA1611" Action="None" />
<Rule Id="SA1612" Action="None" />
<Rule Id="SA1613" Action="None" />
<Rule Id="SA1614" Action="None" />
<Rule Id="SA1615" Action="None" />
<Rule Id="SA1616" Action="None" />
<Rule Id="SA1617" Action="None" />
<Rule Id="SA1618" Action="None" />
<Rule Id="SA1619" Action="None" />
<Rule Id="SA1620" Action="None" />
<Rule Id="SA1621" Action="None" />
<Rule Id="SA1622" Action="None" />
<Rule Id="SA1626" Action="None" />
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1634" Action="None" />
<Rule Id="SA1635" Action="None" />
<Rule Id="SA1637" Action="None" />
<Rule Id="SA1638" Action="None" />
<Rule Id="SA1640" Action="None" />
<Rule Id="SA1642" Action="None" />
<Rule Id="SA1643" Action="None" />
<Rule Id="SA1648" Action="None" />
<Rule Id="SA1651" Action="None" />
<Rule Id="SA1652" Action="None" />
</Rules>
</RuleSet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace School
{
public class SchoolInstance
{
private string name;
private IList<Course> coursesList;

public SchoolInstance(string name)
{
this.Name = name;
this.coursesList = new List<Course>();
}

public string Name
{
get
{
return this.name;
}

set
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException("School name can not be null.");
}

this.name = value;
}
}

public void AddCourse(Course course)
{
if (object.Equals(course, null))
{
throw new ArgumentNullException("Course to add can not be null");
}

if (this.coursesList.Contains(course))
{
throw new ArgumentException("Course is already in the list");
}

this.coursesList.Add(course);
}

public void RemoveCourse(Course course)
{
if (object.Equals(course, null))
{
throw new ArgumentNullException("Course can not be null");
}

if (!this.coursesList.Contains(course))
{
throw new ArgumentException("Course is not in list");
}

this.coursesList.Remove(course);
}

public string ListCourses()
{
var coursesInSchool = new StringBuilder();

foreach (var course in this.coursesList)
{
coursesInSchool.Append(course.ToString());
}

return coursesInSchool.ToString();
}

public string ListStudents()
{
var studentsInSchool = new StringBuilder();

foreach (var course in this.coursesList)
{
studentsInSchool.Append(course.ListStudents());
}

return studentsInSchool.ToString();
}
}
}
Loading

0 comments on commit 9693aec

Please sign in to comment.