single
Challenge: Test a Calculator Class
Deslize para mostrar o menu
In this challenge, you will apply your understanding of Python testing frameworks by implementing and testing a simple calculator class. Your calculator should support four basic operations: addition, subtraction, multiplication, and division. You will use the unittest framework to write comprehensive tests that verify the correctness of each operation.
Remember to design your tests so that each calculator method is covered, including checks for normal operation and for edge cases such as division by zero.
Deslize para começar a programar
Implement a Calculator class with methods for basic arithmetic operations and write unit tests for each method using the unittest framework.
To complete this task:
- Implement the
add,subtract,multiply, anddividemethods in theCalculatorclass so that each returns the correct result for the given operation. - Ensure the
dividemethod raises aZeroDivisionErrorwhen attempting to divide by zero. - Complete the provided test cases in the
TestCalculatorclass so that they verify the correctness of each method. - All tests should pass for a correct implementation.
Solução
Obrigado pelo seu feedback!
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo