-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c412fdd
commit a58945d
Showing
5 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters