Skip to content

Commit

Permalink
Grading Students implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoMariano committed May 5, 2022
1 parent c412fdd commit a58945d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Challenges.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinMaxSum", "MinMaxSum\MinM
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BirthdayCakeCandles", "BirthdayCakeCandles\BirthdayCakeCandles.csproj", "{DB24AB65-267B-4D40-8EBC-2C729915737C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuotaPerMonth_RafaKowalski", "QuotaPerMonth.RafaKowalski\QuotaPerMonth_RafaKowalski.csproj", "{FDB93CDD-673E-4DFD-AB1B-135DA894C7CF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuotaPerMonth_RafaKowalski", "QuotaPerMonth.RafaKowalski\QuotaPerMonth_RafaKowalski.csproj", "{FDB93CDD-673E-4DFD-AB1B-135DA894C7CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GradingStudents", "GradingStudents\GradingStudents.csproj", "{6111D158-63E4-4479-BD7A-3CE9BC725EBC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -49,6 +51,10 @@ Global
{FDB93CDD-673E-4DFD-AB1B-135DA894C7CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDB93CDD-673E-4DFD-AB1B-135DA894C7CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDB93CDD-673E-4DFD-AB1B-135DA894C7CF}.Release|Any CPU.Build.0 = Release|Any CPU
{6111D158-63E4-4479-BD7A-3CE9BC725EBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6111D158-63E4-4479-BD7A-3CE9BC725EBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6111D158-63E4-4479-BD7A-3CE9BC725EBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6111D158-63E4-4479-BD7A-3CE9BC725EBC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -60,6 +66,7 @@ Global
{60684F63-A775-48FC-9261-A0F695E2EB92} = {485DB4CC-A847-42A2-8835-FF6E86FCFDDB}
{DB24AB65-267B-4D40-8EBC-2C729915737C} = {485DB4CC-A847-42A2-8835-FF6E86FCFDDB}
{FDB93CDD-673E-4DFD-AB1B-135DA894C7CF} = {485DB4CC-A847-42A2-8835-FF6E86FCFDDB}
{6111D158-63E4-4479-BD7A-3CE9BC725EBC} = {485DB4CC-A847-42A2-8835-FF6E86FCFDDB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B02C552-EEE2-46BB-8945-65300D51D508}
Expand Down
7 changes: 7 additions & 0 deletions GradingStudents/GradingStudents.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

</Project>
40 changes: 40 additions & 0 deletions GradingStudents/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;

namespace GradingStudents
{
public class Solution
{
/*
* HackerLand University has the following grading policy:
* Every student receives a grade in the inclusive range from 0 to 100.
* Any grade less than 40 is a failing grade.
*
* Sam is a professor at the university and likes to round each student's grade according to these rules:
* If the difference between the grade and the next multiple of 5 is less than 3, round grade up to the next multiple of 5.
* If the value of grade is less than 38, no rounding occurs as the result will still be a failing grade.
*
* Examples
* grade = 84 round to 85 (85 - 84 is less than 3)
* grade = 29 do not round (result is less than 40)
* grade = 57 do not round (60 - 57 is 3 or higher)
* Given the initial value of grade for each of Sam's n students, write code to automate the rounding process.
*/

public static List<int> Calculate(List<int> grades)
{
for (int i = 0; i < grades.Count; i++)
{
var item = grades[i];
if (item >= 38)
{
var diff = 5 - (item % 5);

if (diff < 3)
grades[i] = item + diff;
}
}

return grades;
}
}
}
51 changes: 51 additions & 0 deletions Tests/GradingStudentsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using GradingStudents;
using NUnit.Framework;
using System.Collections.Generic;

[TestFixture]
public class GradingStudentsTests
{
private List<int> grade;

[Test]
public void CaseOne()
{
//Arrange
grade = new() { 73, 67, 38, 33 };
List<int> expectedResult = new() { 75, 67, 40, 33 };

//Action
List<int> result = Solution.Calculate(grade);

//Assert
Assert.AreEqual(expectedResult, result);
}

[Test]
public void CaseTwo()
{
//Arrange
grade = new() { 55, 62, 48, 78 };
List<int> expectedResult = new() { 55, 62, 50, 80 };

//Action
List<int> result = Solution.Calculate(grade);

//Assert
Assert.AreEqual(expectedResult, result);
}

[Test]
public void CaseThree()
{
//Arrange
grade = new() { 8, 43, 77, 99 };
List<int> expectedResult = new() { 8, 45, 77, 100 };

//Action
List<int> result = Solution.Calculate(grade);

//Assert
Assert.AreEqual(expectedResult, result);
}
}
1 change: 1 addition & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<ProjectReference Include="..\BirthdayCakeCandles\BirthdayCakeCandles.csproj" />
<ProjectReference Include="..\GradingStudents\GradingStudents.csproj" />
<ProjectReference Include="..\MinMaxSum\MinMaxSum.csproj" />
<ProjectReference Include="..\MorseDecoder\MorseDecoder.csproj" />
<ProjectReference Include="..\QuotaPerMonth.RafaKowalski\QuotaPerMonth_RafaKowalski.csproj" />
Expand Down

0 comments on commit a58945d

Please sign in to comment.