-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds ira calculator with unit tests
- Loading branch information
1 parent
556df6c
commit 88b8f5c
Showing
2 changed files
with
89 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class IraCalculator: | ||
def __init__(self) -> None: | ||
self.mencaoMap = { | ||
'SS': 5, | ||
'MS': 4, | ||
'MM': 3, | ||
'MI': 2, | ||
'II': 1, | ||
'SR': 0, | ||
} | ||
|
||
def get_ira_value(self, mencoes): | ||
""" | ||
Obter o valor do IRA a partir de um conjunto de menções. | ||
:param mencoes: A lista de menções. Uma menção está no formato {'mencao': string, 'qtdCreditos': int, 'semestre': int}. | ||
""" | ||
valor_final = 0 | ||
for mencao in mencoes: | ||
|
||
if not (1 <= mencao['semestre'] <= 6): | ||
raise ValueError | ||
|
||
if mencao['mencao'] not in self.mencaoMap.keys(): | ||
raise ValueError | ||
|
||
numerador = self.mencaoMap[mencao['mencao']] * \ | ||
mencao['qtdCreditos'] * \ | ||
mencao['semestre'] | ||
|
||
denominador = mencao['qtdCreditos'] * mencao['semestre'] | ||
valor_final += numerador/denominador | ||
|
||
return valor_final | ||
|
||
|
||
|
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,52 @@ | ||
from django.test import TestCase | ||
from utils.ira_calculator import IraCalculator | ||
|
||
|
||
class IraTestCase(TestCase): | ||
def setUp(self): | ||
self.ira_calc = IraCalculator() | ||
|
||
def test_one_discipline_with_MM(self): | ||
args = [ | ||
{ | ||
'mencao': 'MM', | ||
'semestre': 1, | ||
'qtdCreditos': 2, | ||
} | ||
] | ||
|
||
self.assertEqual(self.ira_calc.get_ira_value(args), 3) | ||
|
||
def test_discipline_with_right_out_of_bounds_semester_value(self): | ||
args = [ | ||
{ | ||
'mencao': 'MM', | ||
'semestre': 7, | ||
'qtdCreditos': 2, | ||
}, | ||
] | ||
|
||
self.assertRaises(ValueError, self.ira_calc.get_ira_value, args) | ||
|
||
def test_discipline_with_left_out_of_bounds_semester_value(self): | ||
args = [ | ||
{ | ||
'mencao': 'MM', | ||
'semestre': 0, | ||
'qtdCreditos': 2, | ||
}, | ||
] | ||
|
||
self.assertRaises(ValueError, self.ira_calc.get_ira_value, args) | ||
|
||
|
||
def test_inexistent_grade(self): | ||
args = [ | ||
{ | ||
'mencao': 'NE', | ||
'semestre': 3, | ||
'qtdCreditos': 2, | ||
}, | ||
] | ||
self.assertRaises(ValueError, self.ira_calc.get_ira_value, args) | ||
|