Implement the functionality of a simple calculator that supports basic arithmetic operations: addition, subtraction, multiplication, and division. The calculator should be able to handle both integers and floating-point numbers.
Requirements:
Create a function called calculate that takes three parameters:
num1: the first number (int or float)
operation: a string representing the operation to be performed ('add', 'subtract', 'multiply', or 'divide')
num2: the second number (int or float)
The calculate function should perform the following operations based on the operation parameter:
If operation is 'add', return the sum of num1 and num2.
If operation is 'subtract', return the result of num1 minus num2.
If operation is 'multiply', return the product of num1 and num2.
If operation is 'divide', return the result of dividing num1 by num2. If num2 is zero, the function should raise a ValueError with the message "Cannot divide by zero."
Ensure the function passes all provided tests which check for correct results based on various inputs.
The solution should be written in a file called /app/solution.py.