Created
December 19, 2018 04:31
-
-
Save SlyCodePanda/d9a056ed1ab639003264ead6d7726ad3 to your computer and use it in GitHub Desktop.
Learning to use pytest with a HackerRank challenge.
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
def main(): | |
n = int(input()) | |
student_marks = {} | |
for _ in range(n): | |
name, *line = input().split() | |
scores = list(map(float, line)) | |
student_marks[name] = scores | |
query_name = input() | |
result = sum(student_marks[name])/n | |
print(result/n) | |
print('%.2f' % 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
''' | |
Run this to test the findingPercentage.py file. | |
run : pytest findingPercentage_test01.py | |
''' | |
import findingPercentage | |
def test_app(capsys): | |
input_values = [2, 'Harsh 25 26.5 28', 'Anurag 26 28 30', 'Harsh'] | |
def mock_input(): | |
return input_values.pop(0) | |
findingPercentage.input = mock_input | |
findingPercentage.main() | |
out, err = capsys.readouterr() | |
assert out == '26.50' | |
assert err == '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment